{
int parent_level = parent.getFqn().size();
int target_level = parent_level + 1;
Fqn fqn;
int size;
NodeData nd = nodeDataIterator.hasNext() ? nodeDataIterator.next() : null;
while (nd != null && !nd.isMarker())
{
fqn = nd.getFqn();
// If we need to integrate into the buddy backup subtree,
// change the Fqn to fit under it
if (offset > 0)
{
fqn = Fqn.fromRelativeFqn(parent.getFqn().getAncestor(offset), fqn);
}
size = fqn.size();
if (size <= parent_level)
{
return nd;
}
else if (size > target_level)
{
throw new IllegalStateException("NodeData " + fqn + " is not a direct child of " + parent.getFqn());
}
Map attrs = nd.getAttributes();
// We handle this NodeData. Create a TreeNode and
// integrate its data
NodeSPI target;
if (usePut)
{
cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
cache.getInvocationContext().getOptionOverrides().setSkipCacheStatusCheck(true);
cache.clearData(fqn);
cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
cache.getInvocationContext().getOptionOverrides().setSkipCacheStatusCheck(true);
cache.put(fqn, attrs);
target = cache.getNode(fqn);
}
else
{
target = factory.createNode(fqn, parent, attrs);
parent.addChild(fqn.getLastElement(), target);
// JBCACHE-913
Region region = cache.getRegion(fqn, false);
if (region != null && region.getEvictionRegionConfig() != null)
{
region.registerEvictionEvent(fqn, EvictionEvent.Type.ADD_NODE_EVENT, attrs == null ? 0 : attrs.size());
}
}
// Recursively call, which will walk down the tree
// and return the next NodeData that's a child of our parent
nd = integrateStateTransferChildren(target, offset, nodeDataIterator);
}
if (nd != null && nd.isExceptionMarker())
{
NodeDataExceptionMarker ndem = (NodeDataExceptionMarker) nd;
throw new CacheException("State provider node " + ndem.getCacheNodeIdentity()
+ " threw exception during loadState", ndem.getCause());
}