/** * If this is the root, returns {@link Fqn#SEPARATOR}. * * @return a String representation of the last element that makes up this Fqn. */ public String getLastElementAsString() { if (isRoot()) { return SEPARATOR; } else { Object last = getLastElement(); if (last instanceof String) return (String) last; else return String.valueOf(getLastElement()); } }
public Set<Object> getChildrenNames() { if (optimisticChildNodeMap == null) { initialiseChildMap(); } Set<Object> names = new HashSet<Object>(optimisticChildNodeMap.keySet()); // invoke deltas if (childrenAdded != null) for (Fqn child : childrenAdded) names.add(child.getLastElement()); if (childrenRemoved != null) for (Fqn child : childrenRemoved) names.remove(child.getLastElement()); return names; }
public VersionedNode(Fqn fqn, NodeSPI<K, V> parent, Map<K, V> data, CacheSPI<K, V> cache) { super(fqn.getLastElement(), fqn, data, cache); if (parent == null && !fqn.isRoot()) throw new NullPointerException("parent"); if (version == null) version = DefaultDataVersion.ZERO; this.parent = parent; }
@Override public NodeSPI<K, V> getChildDirect(Fqn f) { if (f.size() > 1) { throw new UnsupportedOperationException("Workspace node does not support fetching indirect children"); } return getChildDirect(f.getLastElement()); }
public boolean removeChild(Fqn f) { if (f.size() > 1) throw new UnsupportedOperationException("Workspace nodes can only remove direct children!"); Object key = f.getLastElement(); return removeChild(key); }
public NodeSPI<K, V> createNode(Fqn fqn, NodeSPI<K, V> parent) { UnversionedNode<K, V> internal = createInternalNode(fqn.getLastElement(), fqn, parent, null); return initializeNodeInvocationDelegate(internal); }
public NodeSPI<K, V> createNode(Fqn fqn, NodeSPI<K, V> parent, Map<K, V> data) { UnversionedNode<K, V> internal = createInternalNode(fqn.getLastElement(), fqn, parent, data); return initializeNodeInvocationDelegate(internal); }
@SuppressWarnings("unchecked") @Override public InternalNode<K, V> copy() { PessimisticUnversionedNode<K, V> n = new PessimisticUnversionedNode<K, V>(fqn.getLastElement(), fqn, data, cache); copyInternals(n); n.children = children; n.lockStrategyFactory = lockStrategyFactory; n.commandsFactory = commandsFactory; n.nodeFactory = nodeFactory; return n; }
@Override public Object visitMoveCommand(InvocationContext ctx, MoveCommand command) throws Throwable { result.add(command.getFqn()); // now if this is a "move" operation, then we also have another Fqn - Object le = command.getFqn().getLastElement(); Fqn parent = command.getTo(); result.add(Fqn.fromRelativeElements(parent, le)); return null; } }
public boolean removeChild(Fqn f) { if (f.size() == 1) { return removeChild(f.getLastElement()); } else { NodeSPI<K, V> child = getChildDirect(f); return child != null && child.getParentDirect().removeChildDirect(f.getLastElement()); } }
public void rollback() { move(Fqn.fromRelativeElements(to, fqn.getLastElement()), fqn.getParent(), true, null); } }
private void adjustFqn(NodeSPI node, Fqn newBase) { Fqn newFqn = Fqn.fromRelativeElements(newBase, node.getFqn().getLastElement()); node.setFqn(newFqn); }
/** * Adds the Fqn of the node as well as all children and childrens children to the list. */ protected void greedyGetFqns(List<Fqn> list, NodeSPI<?, ?> n, Fqn newBase) { list.add(n.getFqn()); Fqn newFqn = Fqn.fromRelativeElements(newBase, n.getFqn().getLastElement()); list.add(newFqn); for (NodeSPI child : n.getChildrenDirect()) { greedyGetFqns(list, child, newFqn); } }
@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."); } }
@Override public NodeSPI<K, V> addChildDirect(Fqn f, boolean notify) { if (f.size() == 1) { GlobalTransaction gtx = cache.getInvocationContext().getGlobalTransaction(); return getOrCreateChild(f.getLastElement(), gtx, true, notify, null); } else { throw new UnsupportedOperationException("Cannot directly create children which aren't directly under the current node."); } }
public PessimisticUnversionedNode(Object name, Fqn fqn, Map<K, V> data, CacheSPI<K, V> cache) { super(fqn, cache, false); if (!fqn.isRoot() && !name.equals(fqn.getLastElement())) throw new IllegalArgumentException("Child " + name + " must be last part of " + fqn); if (data != null && !data.isEmpty()) setInternalState(data); else this.data = new FastCopyHashMap<K, V>(); setLockForChildInsertRemove(cache != null && cache.getConfiguration() != null && cache.getConfiguration().isLockParentForChildInsertRemove()); }
private void removeNodeLegacy(Fqn fqn) { NodeSPI targetNode = peek(fqn, false, true); if (targetNode == null) return; NodeSPI parentNode = targetNode.getParentDirect(); targetNode.setValid(false, false); if (parentNode != null) { parentNode.removeChildDirect(fqn.getLastElement()); parentNode.setChildrenLoaded(false); } }
@Override public void addChildDirect(NodeSPI<K, V> child) { Fqn childFqn = child.getFqn(); if (childFqn.isDirectChildOf(fqn)) { synchronized (this) { children().put(child.getFqn().getLastElement(), child); } } else throw new CacheException("Attempting to add a child [" + child.getFqn() + "] to [" + getFqn() + "]. Can only add direct children."); }
private void removeNode(Fqn fqn) { InternalNode targetNode = peekInternalNode(fqn, true); if (targetNode == null) return; InternalNode parentNode = peekInternalNode(fqn.getParent(), true); targetNode.setValid(false, false); if (parentNode != null) { parentNode.removeChild(fqn.getLastElement()); parentNode.setChildrenLoaded(false); } }
@Override protected Object handleMoveCommand(InvocationContext ctx, MoveCommand command) throws Throwable { Object returnValue = invokeNextInterceptor(ctx, command); if (inTransaction()) { return returnValue; } Fqn newNodeFqn = Fqn.fromRelativeElements(command.getTo(), command.getFqn().getLastElement()); recursiveMove(command.getFqn(), newNodeFqn); loader.remove(command.getFqn()); return returnValue; }