@Override public Map<Object, Node<K, V>> getChildrenMapDirect() { return children(); }
@Override public NodeSPI<K, V> getChildDirect(Object childName) { if (childName == null) return null; return (NodeSPI<K, V>) children().get(childName); }
@Override public void addChildDirect(Object nodeName, Node<K, V> nodeToAdd) { if (nodeName != null) { children().put(nodeName, nodeToAdd); } }
@Override public void setChildrenMapDirect(Map<Object, Node<K, V>> children) { if (children == null) this.children = null; else { this.children.clear(); this.children().putAll(children); } }
@Override public Set<NodeSPI<K, V>> getChildrenDirect() { // strip out deleted child nodes... if (children == null || children.size() == 0) return Collections.emptySet(); Set<NodeSPI<K, V>> exclDeleted = new HashSet<NodeSPI<K, V>>(); for (Node<K, V> n : children().values()) { NodeSPI<K, V> spi = (NodeSPI<K, V>) n; if (!spi.isDeleted()) exclDeleted.add(spi); } exclDeleted = Collections.unmodifiableSet(exclDeleted); return exclDeleted; }
@Override public void markAsRemoved(boolean marker, boolean recursive) { setFlag(NodeFlags.REMOVED, marker); if (recursive && children != null) { synchronized (this) { for (Node<?, ?> child : children().values()) { ((NodeSPI) child).markAsDeleted(marker, true); } } } }
@Override public void setValid(boolean valid, boolean recursive) { setFlag(VALID, valid); if (trace) log.trace("Marking node " + getFqn() + " as " + (valid ? "" : "in") + "valid"); if (recursive) { for (Node<K, V> child : children().values()) { ((NodeSPI<K, V>) child).setValid(valid, recursive); } } }
@Override public void setFqn(Fqn fqn) { if (trace) { log.trace(getFqn() + " set FQN " + fqn); } this.fqn = fqn; if (children == null) { return; } // invoke children for (Map.Entry<Object, ? extends Node<K, V>> me : children().entrySet()) { NodeSPI<K, V> n = (NodeSPI<K, V>) me.getValue(); Fqn cfqn = Fqn.fromRelativeElements(fqn, me.getKey()); n.setFqn(cfqn); } }
/** * Adds details of the node into a map as strings. */ @Override protected void printDetailsInMap(StringBuilder sb, int indent) { printIndent(sb, indent); indent += 2;// increse it sb.append(Fqn.SEPARATOR); if (!fqn.isRoot()) sb.append(fqn.getLastElement()); sb.append(" "); sb.append(data); for (Node n : children().values()) { sb.append("\n"); ((NodeSPI) n).printDetails(sb, indent); } }
@Override public void releaseObjectReferences(boolean recursive) { if (recursive && children != null) { for (Node<K, V> child : children().values()) { child.releaseObjectReferences(recursive); } } if (data != null) { for (K key : data.keySet()) { // get the key first, before attempting to serialize stuff since data.get() may deserialize the key if doing // a hashcode() or equals(). Object value = data.get(key); if (key instanceof MarshalledValue) { ((MarshalledValue) key).compact(true, true); } if (value instanceof MarshalledValue) { ((MarshalledValue) value).compact(true, true); } } } }
child = (NodeSPI<K, V>) children().get(childName); InvocationContext ctx = cache.getInvocationContext(); if (createIfNotExists && child == null) child = (NodeSPI<K, V>) children().get(childName); if (child == null) child = newChild; if (la != null) la.acquire(child); children().put(childName, child);
@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."); }