/** * @return the last element in the Fqn. * @see #getLastElementAsString */ public Object getLastElement() { if (isRoot()) return null; return elements[elements.length - 1]; }
public boolean isDefaultRegion() { return regionFqn.isRoot(); }
private boolean recursiveEvictOnRoot(NodeSPI node) { return node == null && fqn.isRoot() && recursive && !nodesToEvict.isEmpty(); }
private String getFqnWildcardString(String fqnString, Fqn fqn) { return escapeSqlLikeParameter(fqnString + (fqn.isRoot() ? "" : Fqn.SEPARATOR)) + '%'; }
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; }
/** * 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()); } }
/** * Returns a parent by checking the TreeMap by name. */ public NodeSPI<K, V> getParent() { if (fqn.isRoot()) { return null; } return cache.peek(fqn.getParent(), true); }
/** * mark the node to be removed (and all children) as invalid so anyone holding a direct reference to it will * be aware that it is no longer valid. */ protected void invalidateNode(NodeSPI node) { node.setValid(false, true); // root nodes can never be invalid if (fqn.isRoot()) node.setValid(true, false); // non-recursive. }
private void writePersistentData(ObjectOutputStream out, Fqn fqn, CacheLoader cacheLoader) throws Exception { if (trace) log.trace("writing persistent state for " + fqn + ", using " + cache.getCacheLoaderManager().getCacheLoader().getClass()); if (fqn.isRoot()) { cacheLoader.loadEntireState(out); } else { cacheLoader.loadState(fqn, out); } if (trace) log.trace("persistent state succesfully written"); }
@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); }
public NodeSPI<K, V> getParent() { Fqn f = getFqn(); if (f.isRoot()) return this; return spi.getNode(f.getParent()); }
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); } }
private void recursiveAddEvictionNodes(NodeSPI<?, ?> node, List<Fqn> result) { for (NodeSPI<?, ?> child : node.getChildrenDirect()) { recursiveAddEvictionNodes(child, result); } Fqn fqn = node.getFqn(); if (!fqn.isRoot() && !node.isResident()) { result.add(fqn); } }
protected void marshallFqn(Fqn fqn, ObjectOutputStream out, Map<Object, Integer> refMap) throws Exception { boolean isRoot = fqn.isRoot(); out.writeBoolean(isRoot); if (!isRoot) { out.writeShort(fqn.size()); for (Object o : fqn.peekElements()) { marshallObject(o, out, refMap); } } }
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()); }
public void addEvictionRegionConfig(EvictionRegionConfig evictionRegionConfig) { testImmutability("evictionRegionConfigs"); if (evictionRegionConfig.getRegionFqn().isRoot() || evictionRegionConfig.getRegionFqn().equals(RegionManagerImpl.DEFAULT_REGION)) { mergeWithDefault(evictionRegionConfig); } else { evictionRegionConfigs.add(evictionRegionConfig); } }
protected void assertValid() { if (!getFqn().isRoot() && !node.isValid()) throw new NodeNotValidException("Node " + getFqn() + " is not valid. Perhaps it has been moved or removed."); }
private void validateNodeAndParents(NodeSPI node) { node.setValid(true, false); if (!node.getFqn().isRoot()) validateNodeAndParents(node.getParentDirect()); }
@Override @SuppressWarnings("unchecked") protected void updateNode(Fqn fqn, InvocationContext ctx, DataContainer dataContainer) { if (fqn.isRoot()) { dataContainer.setRoot(node); } else if (!isFlagSet(DELETED)) { InternalNode parent = lookupParent(fqn, ctx, dataContainer); parent.addChild(node, true); // we know this is safe since we calculated the parent from the child. No need to have the parent re-do checks when adding the child again. } } }
@Override public Object handleInvalidateCommand(InvocationContext ctx, InvalidateCommand command) throws Throwable { // this should be handled the same as a recursive evict command. ctx.getOptionOverrides().setLockAcquisitionTimeout(0); if (!command.getFqn().isRoot()) helper.wrapNodesRecursivelyForRemoval(ctx, command.getFqn()); return invokeNextInterceptor(ctx, command); }