@SuppressWarnings("unchecked") public InternalNode<K, V> copy() { UnversionedNode<K, V> n = new UnversionedNode<K, V>(fqn, cache, isFlagSet(LOCK_FOR_CHILD_INSERT_REMOVE)); n.data = copyDataMap(data); copyInternals(n); return n; }
@Override public void addChild(InternalNode<K, V> child) { addChild(child, false); }
public void setInternalState(Map state) { if (data == null) { data = copyDataMap(state); } else { // don't bother doing anything here putAll(state); } }
if (!isValid()) sb.append(" (invalid) "); if (isRemoved()) sb.append(" version=").append(this.getVersion()); sb.append(" children=").append(getChildrenNames()); Set names = getChildrenNames(); int i = 0; for (Object o : names)
@Override public ConcurrentMap<Object, InternalNode<K, V>> getChildrenMap() { return children(); }
@Override public InternalNode<K, V> createInternalNode(Fqn fqn) { UnversionedNode<K, V> un = new UnversionedNode<K, V>(fqn, cache, lockChildForInsertRemove); // always assume that new nodes don't have their data loaded, unless root. if (!fqn.isRoot()) un.setDataLoaded(false); return useRepeatableRead ? un : new NodeReference<K, V>(un); }
@Override public Set<InternalNode<K, V>> getChildren(boolean includeMarkedForRemoval) { if (includeMarkedForRemoval) { if (!children.isEmpty()) { return Immutables.immutableSetConvert(children().values()); } else { return Collections.emptySet(); } } else { return getChildren(); } }
public void setFqn(Fqn fqn) { if (trace) { log.trace(getFqn() + " set FQN " + fqn); } this.fqn = fqn; // invoke children for (Map.Entry<Object, InternalNode<K, V>> me : children().entrySet()) { InternalNode<K, V> n = me.getValue(); Fqn cfqn = Fqn.fromRelativeElements(fqn, me.getKey()); n.setFqn(cfqn); } }
public void putAll(Map<? extends K, ? extends V> data) { if (data != null) { if (this.data == null) this.data = copyDataMap(data); else if (this.data.size() == 1 && data.size() == 1 && this.data.keySet().iterator().next().equals(data.keySet().iterator().next())) { // replace key! Entry<? extends K, ? extends V> e = data.entrySet().iterator().next(); // These casts are a work-around for an eclipse compiler bug, please don't remove ;) this.data = Collections.singletonMap((K)e.getKey(), (V) e.getValue()); } else { // size. Do we need to update the existing data map to a FCHM? upgradeDataMap(); this.data.putAll(data); } } }
/** * Adds details of the node into a map as strings. */ 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 (InternalNode n : children().values()) { sb.append("\n"); n.printDetails(sb, indent); } }
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 V remove(K key) { if (data == null) return null; V value; if (data instanceof FastCopyHashMap) { value = data.remove(key); downgradeDataMapIfNeeded(); } else { // singleton maps cannot remove! value = data.get(key); data = null; } return value; }
@Override public InternalNode<K, V> getChild(Fqn f) { if (fqn.size() == 1) { return getChild(fqn.getLastElement()); } else { InternalNode<K, V> currentNode = this; for (int i = 0; i < fqn.size(); i++) { Object nextChildName = fqn.get(i); currentNode = currentNode.getChild(nextChildName); if (currentNode == null) return null; } return currentNode; } }
@Override public InternalNode<K, V> getChild(Object childName) { if (childName == null) return null; return children().get(childName); }
@Override public void addChild(Object nodeName, InternalNode<K, V> nodeToAdd) { if (nodeName != null) { children().put(nodeName, nodeToAdd); } }
@Override public Set<InternalNode<K, V>> getChildren() { // strip out deleted child nodes... if (children.isEmpty()) return Collections.emptySet(); Set<InternalNode<K, V>> exclDeleted = new HashSet<InternalNode<K, V>>(); for (InternalNode<K, V> n : children().values()) { if (!n.isRemoved()) exclDeleted.add(n); } exclDeleted = Collections.unmodifiableSet(exclDeleted); return exclDeleted; }
public void releaseObjectReferences(boolean recursive) { if (recursive) { for (InternalNode<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); } } } }
@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."); } }