public Fqn getFqn() { return node.getFqn(); }
public final Fqn getFqn() { return delegate.getFqn(); }
private Fqn getFqn(Object o) { if (o instanceof Node) return ((Node) o).getFqn(); if (o instanceof InternalNode) return ((InternalNode) o).getFqn(); throw new IllegalArgumentException(); }
private Fqn getFqn(Object o) { if (o instanceof Node) return ((Node) o).getFqn(); if (o instanceof InternalNode) return ((InternalNode) o).getFqn(); throw new IllegalArgumentException(); }
protected void generateNodeDataList(InternalNode<?, ?> node, List<NodeData> list) throws Exception { if (internalFqns.contains(node.getFqn())) { return; } Map attrs; NodeData nd; // first handle the current node attrs = node.getInternalState(false); if (attrs.size() == 0) { nd = new NodeData(node.getFqn()); } else { nd = new NodeData(node.getFqn(), attrs, true); } list.add(nd); // then visit the children for (InternalNode child : node.getChildren()) generateNodeDataList(child, list); } }
/** * Do a preorder traversal: visit the node first, then the node's children * * @param out * @throws Exception */ protected void marshallTransientState(InternalNode node, ObjectOutputStream out) throws Exception { List<NodeData> nodeData = new LinkedList<NodeData>(); generateNodeDataList(node, nodeData); cache.getMarshaller().objectToObjectStream(nodeData, out, node.getFqn()); }
/** * Only used with MVCC. */ private void removeLocksForDeadMembers(InternalNode<?, ?> node, List deadMembers) { Set<GlobalTransaction> deadOwners = new HashSet<GlobalTransaction>(); Object owner = lockManager.getWriteOwner(node.getFqn()); if (isLockOwnerDead(owner, deadMembers)) deadOwners.add((GlobalTransaction) owner); // MVCC won't have any read locks. for (GlobalTransaction deadOwner : deadOwners) { boolean localTx = deadOwner.getAddress().equals(getLocalAddress()); boolean broken = LockUtil.breakTransactionLock(node.getFqn(), lockManager, deadOwner, localTx, txTable, txManager); if (broken && trace) log.trace("Broke lock for node " + node.getFqn() + " held by " + deadOwner); } // Recursively unlock children for (InternalNode child : node.getChildren()) removeLocksForDeadMembers(child, deadMembers); }
private List<NodeData> buildNodeData(List<NodeData> list, InternalNode<?, ?> node, Map dataInNode, boolean mapSafe) { NodeData data = new NodeData(buddyFqnTransformer.getActualFqn(node.getFqn()), dataInNode, mapSafe); list.add(data); for (InternalNode childNode : node.getChildrenMap().values()) { buildNodeData(list, childNode, childNode.getData(), true); } return list; }
private void recursiveAddEvictionNodes(InternalNode<?, ?> node, List<Fqn> result) { for (InternalNode child : node.getChildren()) { recursiveAddEvictionNodes(child, result); } Fqn fqn = node.getFqn(); if (!fqn.isRoot() && !node.isResident()) { result.add(fqn); } }
@Override public void addChild(InternalNode<K, V> child, boolean safe) { Fqn<?> childFqn = child.getFqn(); if (safe || childFqn.isDirectChildOf(fqn)) { children().put(childFqn.getLastElement(), child); } else { throw new CacheException("Attempting to add a child [" + childFqn + "] to [" + fqn + "]. Can only add direct children."); } }
/** * Generates NodeAdded notifications for all nodes of the tree. This is * called whenever the tree is initially retrieved (state transfer) */ private void notifyAllNodesCreated(InvocationContext ctx, InternalNode curr) { if (curr == null) return; ctx.setOriginLocal(false); cache.getNotifier().notifyNodeCreated(curr.getFqn(), true, ctx); cache.getNotifier().notifyNodeCreated(curr.getFqn(), false, ctx); // AND notify that they have been modified!! if (!curr.getKeys().isEmpty()) { cache.getNotifier().notifyNodeModified(curr.getFqn(), true, NodeModifiedEvent.ModificationType.PUT_MAP, Collections.emptyMap(), ctx); cache.getNotifier().notifyNodeModified(curr.getFqn(), false, NodeModifiedEvent.ModificationType.PUT_MAP, curr.getData(), ctx); } ctx.setOriginLocal(true); Set<InternalNode> children = curr.getChildren(); for (InternalNode n : children) notifyAllNodesCreated(ctx, n); }
/** * Identical to {@link #lockForWritingRecursive(org.jboss.cache.Fqn, org.jboss.cache.InvocationContext, * java.util.List)} except that it uses an {@link org.jboss.cache.InternalNode} instead of an {@link Fqn} - saves a * lookup. * * @param node node to lock recursively * @param ctx invocation context * @param fqnList list of Fqns to add to * @throws InterruptedException if interrupted */ @SuppressWarnings("unchecked") private void lockForWritingRecursive(InternalNode node, InternalNode parent, InvocationContext ctx, List<Fqn> fqnList) throws InterruptedException { Fqn fqn = node.getFqn(); acquireLock(ctx, fqn); // lock node if (fqnList != null) fqnList.add(fqn); // now wrap and add to the context NodeSPI rcn = wrapNodeForWriting(ctx, node, parent); if (rcn != null) { rcn.markForUpdate(dataContainer, writeSkewCheck); Map<Object, InternalNode<?, ?>> children = node.getChildrenMap(); for (InternalNode child : children.values()) lockForWritingRecursive(child, node, ctx, fqnList); } }
Fqn childFqn = realChild.getFqn(); NodeSPI childNode = ctx.lookUpNode(childFqn);
@SuppressWarnings("unchecked") private void handleRecursiveEvict(InvocationContext ctx, EvictCommand command) throws InterruptedException { List<Fqn> fqnsToEvict; if (command.getFqn().isRoot()) { // if this is the root node, do not attempt to lock this for writing but instead just get all direct children of root. Map<Object, InternalNode> children = dataContainer.peekInternalNode(Fqn.ROOT, false).getChildrenMap(); if (!children.isEmpty()) { fqnsToEvict = new LinkedList<Fqn>(); // lock recursively. for (InternalNode child : children.values()) { fqnsToEvict.addAll(helper.wrapNodesRecursivelyForRemoval(ctx, child.getFqn())); } } else { fqnsToEvict = Collections.emptyList(); } } else { // lock current node recursively. fqnsToEvict = helper.wrapNodesRecursivelyForRemoval(ctx, command.getFqn()); } // set these in the evict command so that the command is aware of what needs to be evicted. command.setNodesToEvict(fqnsToEvict); }
private boolean childrenLoaded(InternalNode<?, ?> node) throws Exception { if (!node.isChildrenLoaded() && loader.getChildrenNames(node.getFqn()) != null) return false; for (InternalNode child : node.getChildren()) { if (!child.isDataLoaded()) { return false; } if (child.hasChildren()) { if (!childrenLoaded(child)) { return false; } } else if (!loaderNoChildren(child.getFqn())) { return false; } } return true; }
@SuppressWarnings("unchecked") private void handleNonrecursiveEvict(InvocationContext ctx, EvictCommand command) throws InterruptedException { if (command.getFqn().isRoot()) { // if this is the root node, do not attempt to lock this for writing but instead just get all direct children of root. Map<Object, InternalNode> children = dataContainer.peekInternalNode(Fqn.ROOT, false).getChildrenMap(); if (!children.isEmpty()) { for (InternalNode child : children.values()) { helper.wrapNodeForWriting(ctx, child.getFqn(), true, false, false, true, true); } } } else { // just wrap the node for writing. Do not create if absent. helper.wrapNodeForWriting(ctx, command.getFqn(), true, false, false, true, true); } }
integrateTransientState(target.getFqn(), in);
Fqn fqn = node.getFqn(); NodeSPI n = context.lookUpNode(fqn); if (n != null) // exists in context! Just acquire lock if needed, and wrap.
@SuppressWarnings("unchecked") private void moveRecursively(NodeSPI oldNode, NodeSPI newNode, InvocationContext ctx) { if (trace) log.trace("Moving " + oldNode.getFqn() + " to " + newNode.getFqn()); // start deep. Map<Object, InternalNode> children = oldNode.getDelegationTarget().getChildrenMap(); if (!children.isEmpty()) { for (InternalNode child : children.values()) { Fqn childFqn = child.getFqn(); Fqn newChildFqn = childFqn.replaceAncestor(oldNode.getFqn(), newNode.getFqn()); moveRecursively(ctx.lookUpNode(childFqn), ctx.lookUpNode(newChildFqn), ctx); } } // now swap the data for the current node. newNode.getDelegationTarget().putAll(oldNode.getDelegationTarget().getData()); oldNode.markAsDeleted(true); }
integrateRetainedNode(child.getFqn(), descFqn);