int parent_level = parent.getFqn().size();
int target_level = parent_level + 1;
Fqn fqn;
int size;
Object name;
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());
}
name = fqn.get(size - 1);
Map attrs = nd.getAttributes();
// We handle this NodeData. Create a TreeNode and
// integrate its data
NodeSPI target = factory.createDataNode(name, fqn, parent, attrs, false);
parent.addChild(name, target);
// JBCACHE-913
Region region = cache.getRegion(fqn, false);
if (region != null && region.getEvictionPolicy() != null)
{
region.putNodeEvent(new EvictedEventNode(fqn, NodeEventType.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());
}