/** * Returns true if this Fqn is a <i>direct</i> child of a given Fqn. * * @param parentFqn parentFqn to compare with * @return true if this is a direct child, false otherwise. */ public boolean isDirectChildOf(Fqn<? super E> parentFqn) { return elements.length == parentFqn.size() + 1 && isChildOf(parentFqn); }
protected boolean handleEvictAllInvalidation(NodeInvalidatedEvent event) { if (!event.isPre() && event.getFqn().isChildOf(internalFqn)) { invalidateState.set(InvalidateState.INVALID); return true; } return false; }
private Set<Node> retainInternalNodes(Node target) { Set<Node> result = new HashSet<Node>(); Fqn targetFqn = target.getFqn(); for (Fqn internalFqn : internalFqns) { if (internalFqn.isChildOf(targetFqn)) { Node internalNode = getInternalNode(target, internalFqn); if (internalNode != null) { result.add(internalNode); } } } return result; }
private void integrateRetainedNodes(Fqn target) { Set<Fqn> retainedNodes = retainInternalNodes(target); for (Fqn retained : retainedNodes) { if (retained.isChildOf(target)) { integrateRetainedNode(target, retained); } } }
protected boolean handleEvictAllModification(NodeModifiedEvent event) { if (!event.isPre() && (replication || event.isOriginLocal()) && event.getData().containsKey(ITEM)) { if (event.getFqn().isChildOf(internalFqn)) { invalidateState.set(InvalidateState.INVALID); return true; } } return false; }
/** * Recursively marks a node as removed. * * @param node Node to mark * @param ctx Invocation context */ protected void recursivelyMarkAsRemoved(NodeSPI node, InvocationContext ctx) { node.markAsDeleted(true); Fqn parentFqn = node.getFqn(); // recursion has to happen like this since child nodes are in the ctx. Map<Fqn, NodeSPI> nodes = ctx.getLookedUpNodes(); for (Map.Entry<Fqn, NodeSPI> entry : nodes.entrySet()) { if (entry.getKey().isChildOf(parentFqn)) entry.getValue().markAsDeleted(true); } }
private Set<Fqn> retainInternalNodes(Fqn target) { Set<Fqn> result = new HashSet<Fqn>(); for (Fqn internalFqn : internalFqns) { if (internalFqn.isChildOf(target)) { prepareContextOptions(); Node node = getInternalNode(cache.getNode(target), internalFqn); if (node != null) { result.add(node.getFqn()); } } } return result; }
/** * Creates a new Fqn whose ancestor has been replaced with the new ancestor passed in. * * @param oldAncestor old ancestor to replace * @param newAncestor nw ancestor to replace with * @return a new Fqn with ancestors replaced. */ public Fqn<E> replaceAncestor(Fqn<E> oldAncestor, Fqn<E> newAncestor) { if (!isChildOf(oldAncestor)) throw new IllegalArgumentException("Old ancestor must be an ancestor of the current Fqn!"); Fqn<E> subFqn = this.getSubFqn(oldAncestor.size(), size()); return Fqn.fromRelativeFqn(newAncestor, subFqn); } }
private void integrateRetainedNodes(NodeSPI target) { Set<Node> retainedNodes = retainInternalNodes(target); Fqn rootFqn = target.getFqn(); for (Node retained : retainedNodes) { if (retained.getFqn().isChildOf(rootFqn)) { integrateRetainedNode(target, retained); } } }
public void setContextClassLoaderAsCurrent(Fqn fqn) { if (fqn.isChildOf(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN)) { if (fqn.size() <= 2) { fqn = Fqn.ROOT; } else { fqn = fqn.getSubFqn(2, fqn.size()); } } Region region = getRegion(fqn, false); ClassLoader regionCL = (region == null) ? null : region.getClassLoader(); if (regionCL != null) { Thread.currentThread().setContextClassLoader(regionCL); } }
@Override Set<Object> getChildrenNames0(Fqn name) throws IOException { Fqn name2 = withDepth(name, name.size() + 1); TupleBrowser browser = tree.browse(name2); Tuple t = new Tuple(); Set<Object> set = new HashSet<Object>(); while (browser.getNext(t)) { Fqn fqn = (Fqn) t.getKey(); if (!fqn.isChildOf(name2)) { break; } set.add(fqn.getLastElement()); } if (set.isEmpty()) { return null; } return Collections.unmodifiableSet(set); }
/** * Monitors cache events and updates the local cache * * @param event */ @NodeModified public void nodeModified(NodeModifiedEvent event) { if (event.isPre()) return; Fqn fqn = event.getFqn(); Fqn regFqn = getRegionFqn(); if (fqn.size() == regFqn.size() + 1 && fqn.isChildOf(regFqn)) { Object key = fqn.get(regFqn.size()); localCache.put(key, event.getData().get(ITEM)); } }
if (!fqn.isChildOf(keys))
/** * Monitors cache events and updates the local cache * * @param event */ @NodeRemoved public void nodeRemoved(NodeRemovedEvent event) { if (event.isPre()) return; Fqn fqn = event.getFqn(); Fqn regFqn = getRegionFqn(); if (fqn.size() == regFqn.size() + 1 && fqn.isChildOf(regFqn)) { Object key = fqn.get(regFqn.size()); localCache.remove(key); } else if (fqn.equals(regFqn)) { localCache.clear(); } }
/** * Monitors cache events and updates the local cache * * @param event */ @NodeRemoved public void nodeRemoved(NodeRemovedEvent event) { if (event.isPre()) return; Fqn fqn = event.getFqn(); Fqn regFqn = getRegionFqn(); if (fqn.size() == regFqn.size() + 1 && fqn.isChildOf(regFqn)) { Object key = fqn.get(regFqn.size()); localCache.remove(key); } else if (fqn.equals(regFqn)) { localCache.clear(); } }
/** * Monitors cache events and updates the local cache * * @param event */ @NodeModified public void nodeModified(NodeModifiedEvent event) { if (!handleEvictAllModification(event) && !event.isPre()) { Fqn fqn = event.getFqn(); Fqn regFqn = getRegionFqn(); if (fqn.size() == regFqn.size() + 1 && fqn.isChildOf(regFqn)) { Object key = fqn.get(regFqn.size()); localCache.put(key, event.getData().get(ITEM)); } } }
if (!fqn.isChildOf(keys))
/** * Monitors cache events and updates the local cache * * @param event */ @NodeModified public void nodeModified(NodeModifiedEvent event) { if (event.isOriginLocal() || event.isPre()) return; Fqn fqn = event.getFqn(); Fqn regFqn = getRegionFqn(); if (fqn.size() == regFqn.size() + 1 && fqn.isChildOf(regFqn)) { Object key = fqn.get(regFqn.size()); Object[] vals = (Object[]) event.getData().get(ITEM); storeDataFromJBC(key, vals); // TODO consider this hack instead of the simple entry.update above: // if (!entry.update(vals[0], vals[1])) { // // Hack! Use the fact that the Object[] stored in JBC is // // mutable to correct our local JBC state in this callback // Object[] correct = entry.getJBCUpdateValues(); // vals[0] = correct[0]; // vals[1] = correct[1]; // } } }
/** * Monitors cache events and updates the local cache * * @param event */ @NodeModified public void nodeModified(NodeModifiedEvent event) { if (event.isOriginLocal() || event.isPre()) return; Fqn fqn = event.getFqn(); Fqn regFqn = getRegionFqn(); if (fqn.size() == regFqn.size() + 1 && fqn.isChildOf(regFqn)) { Object key = fqn.get(regFqn.size()); Object[] vals = (Object[]) event.getData().get(ITEM); storeDataFromJBC(key, vals); // TODO consider this hack instead of the simple entry.update above: // if (!entry.update(vals[0], vals[1])) { // // Hack! Use the fact that the Object[] stored in JBC is // // mutable to correct our local JBC state in this callback // Object[] correct = entry.getJBCUpdateValues(); // vals[0] = correct[0]; // vals[1] = correct[1]; // } } }
boolean moveToBuddy = subtree.isChildOf(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN) && subtree.size() > 1;