protected NodeSPI lookupForEviction(InvocationContext ctx, Fqn fqn) { return ctx.lookUpNode(fqn); }
/** * Checks whether a node represented by a given Fqn exists. * Deleted and invalid nodes are not considered. * * @return true if the node exists, false otherwise. */ public Object perform(InvocationContext ctx) { NodeSPI node = ctx.lookUpNode(fqn); return node != null && !node.isDeleted(); }
@Override protected boolean nodeDoesNotExist(InvocationContext ctx, Fqn fqn) { ReadCommittedNode node = (ReadCommittedNode) ctx.lookUpNode(fqn); return node == null || node.isNullNode(); }
/** * Retrieves a {@link org.jboss.cache.Node} referenced by the specified Fqn. * * @param ctx invocation context * @return a Node, or null if the Fqn refers to a node that does not exist. */ public Object perform(InvocationContext ctx) { NodeSPI node = ctx.lookUpNode(fqn); if (node != null && node.isDeleted()) { if (trace) log.trace("Node of type [" + node.getClass().getSimpleName() + "] found but marked as deleted in current scope. Returning null."); return null; } if (trace) log.trace("Found node, returning " + node); return node; }
@Override public Object perform(InvocationContext ctx) { // first get a hold of existing data. NodeSPI node = ctx.lookUpNode(fqn); Map existingData = node == null ? null : node.getDataDirect(); if (existingData != null && !existingData.isEmpty()) { oldData = new HashMap(existingData); // defensive copy } return super.perform(ctx); }
@Override public Object perform(InvocationContext ctx) { if (globalTransaction != null) { NodeSPI n = ctx.lookUpNode(fqn); originalData = n == null ? null : new HashMap(n.getDataDirect()); } return super.perform(ctx); }
@Override protected void storeStateForPutDataMap(Fqn f, InvocationContext ctx) throws Exception { loader.put(f, ctx.lookUpNode(f).getDataDirect()); }
/** * Retrieves Set of keys for all the data stored in a node referenced by the specified Fqn. * * @param ctx invocation context * @return a Set<K> of data keys contained in a node for a given Fqn, or null if the Fqn refers to a node that does not exist. */ public Object perform(InvocationContext ctx) { NodeSPI n = ctx.lookUpNode(fqn); if (n == null || n.isDeleted()) return null; return n.getKeysDirect(); }
/** * Retrieves the names of children for a specific Fqn. * * @param ctx invocation context * @return a Set<Object> of child names, for a given Fqn, or null if the Fqn refers to a node that does not exist. */ @SuppressWarnings("unchecked") @Override public Object perform(InvocationContext ctx) { NodeSPI<?, ?> n = fqn == null ? null : ctx.lookUpNode(fqn); if (n == null || n.isDeleted()) return null; Map<Object, ? extends Node<?, ?>> childrenMap = n.getChildrenMapDirect(); Collection<NodeSPI<?, ?>> children = (Collection<NodeSPI<?, ?>>) (childrenMap.isEmpty() ? Collections.emptySet() : childrenMap.values()); return getCorrectedChildNames(children); }
/** * Retrieves the names of children for a specific Fqn. * * @param ctx invocation context * @return a Set<Object> of child names, for a given Fqn, or null if the Fqn refers to a node that does not exist. */ @SuppressWarnings("unchecked") public Object perform(InvocationContext ctx) { ReadCommittedNode n = (ReadCommittedNode) (fqn == null ? null : ctx.lookUpNode(fqn)); if (n == null || n.isDeleted()) return null; Map<Object, InternalNode<?, ?>> childrenMap = n.getDelegationTarget().getChildrenMap(); Collection<InternalNode> children = (Collection<InternalNode>) (childrenMap.isEmpty() ? Collections.emptySet() : childrenMap.values()); return getCorrectedChildNames(children, ctx); }
/** * Utility method to peek a node and throw an exception if the version isn't what is expected. * * @param ctx context to use * @return node peeked, null if nonexistent * @throws org.jboss.cache.optimistic.DataVersioningException * if there is a version mismatch */ protected NodeSPI peekVersioned(InvocationContext ctx) { NodeSPI n = ctx.lookUpNode(fqn); if (n != null && isVersioned() && n.getVersion().newerThan(dataVersion)) { String errMsg = new StringBuilder("Node found, but version is not equal to or less than the expected [").append(dataVersion).append("]. Is [").append(n.getVersion()).append("] instead!").toString(); throw new DataVersioningException(errMsg); } return n; } }
@SuppressWarnings("unchecked") private NodeSPI wrapNodeForReading(InvocationContext ctx, Fqn f, boolean writeLockForced, boolean putInContext) throws InterruptedException { NodeSPI n; if (writeLockForced) { if (trace) log.trace("Forcing lock on reading node " + f); return wrapNodeForWriting(ctx, f, true, false, false, false, false); } else if ((n = ctx.lookUpNode(f)) == null) { if (trace) log.trace("Node " + f + " is not in context, fetching from container."); // simple implementation. Peek the node, wrap it, put wrapped node in the context. InternalNode[] nodes = dataContainer.peekInternalNodeAndDirectParent(f, false); ReadCommittedNode wrapped = nodeFactory.createWrappedNode(nodes[0], nodes[1]); // even though parents aren't needed for reading, we hold on to this ref in case the node is later written to. if (putInContext && wrapped != null) ctx.putLookedUpNode(f, wrapped); return wrapped; } else { if (trace) log.trace("Node " + f + " is already in context."); return n; } }
/** * Retrieves an unmodifiable map of data contained in a node referenced by the specified Fqn. * * @return an unmodifiable Map<K, V> of data contained in a node for a given Fqn, or null if the Fqn refers to a node that does not exist. */ public Object perform(InvocationContext ctx) { NodeSPI<?, ?> n = ctx.lookUpNode(fqn); if (n == null || n.isDeleted()) return null; return Immutables.immutableMapCopy(n.getDataDirect()); }
/** * Tests if locking the parent is necessary when locking a specific node. * * @param parent Fqn of parent node to check * @param ctx invocation context * @return true if parent lock is needed, false otherwise. */ private boolean isParentLockNeeded(Fqn parent, InvocationContext ctx) { ReadCommittedNode parentNodeTmp = (ReadCommittedNode) ctx.lookUpNode(parent); InternalNode in = parentNodeTmp == null ? dataContainer.peekInternalNode(parent, true) : parentNodeTmp.getDelegationTarget(); return isParentLockNeeded(in); } }
private InternalNode findNode(InvocationContext ctx, Fqn fqn) { ReadCommittedNode n = (ReadCommittedNode) ctx.lookUpNode(fqn); if (n == null || n.isNullNode()) { return dataContainer.peekInternalNode(fqn, true); } else { return n.getDelegationTarget(); } }
protected void storeStateForPutDataMap(Fqn f, InvocationContext ctx) throws Exception { loader.put(f, ctx.lookUpNode(f).getDelegationTarget().getData()); }
/** * Returns attributes for a node. */ private Map getNodeAttributes(InvocationContext ctx, Fqn fqn) throws NodeNotLoadedException { if (fqn == null) { throw new NodeNotLoadedException(); } NodeSPI n = ctx.lookUpNode(fqn); if (n != null) { return n.getDataDirect(); } else { throw new NodeNotLoadedException(); } }
@SuppressWarnings("unchecked") private void moveRecursively(NodeSPI oldNode, NodeSPI newNode, InvocationContext ctx) { if (trace) log.trace("Moving " + oldNode.getFqn() + " to " + newNode.getFqn()); // start deep. Map<Object, InternalNode> children = oldNode.getDelegationTarget().getChildrenMap(); if (!children.isEmpty()) { for (InternalNode child : children.values()) { Fqn childFqn = child.getFqn(); Fqn newChildFqn = childFqn.replaceAncestor(oldNode.getFqn(), newNode.getFqn()); moveRecursively(ctx.lookUpNode(childFqn), ctx.lookUpNode(newChildFqn), ctx); } } // now swap the data for the current node. newNode.getDelegationTarget().putAll(oldNode.getDelegationTarget().getData()); oldNode.markAsDeleted(true); }
@Override protected Object handleRemoveDataCommand(InvocationContext ctx, ClearDataCommand command) throws Throwable { if (!inTransaction()) { loader.removeData(command.getFqn()); // we need to mark this node as data loaded NodeSPI n = ctx.lookUpNode(command.getFqn()); if (n != null) { n.setDataLoaded(true); } } return invokeNextInterceptor(ctx, command); }
/** * Wraps a node and puts it in the context, optionally copying the node for updating if <tt>forUpdate</tt> is * <tt>true</tt>. If the node is already in the context, a new wrapped node is not created, but the existing one is * still checked for changes and potentially marked for update if <tt>forUpdate</tt> is <tt>true</tt>. * * @param ctx invocation context to add node to * @param fqn fqn of node to add * @param forUpdate if true, the wrapped node is marked for update before adding to the context. * @return the ReadCommittedNode wrapper, or null if the node does not exist. */ @SuppressWarnings("unchecked") private ReadCommittedNode wrapAndPutInContext(InvocationContext ctx, Fqn fqn, boolean forUpdate) { ReadCommittedNode node = (ReadCommittedNode) ctx.lookUpNode(fqn); if (node == null || node.isNullNode()) { InternalNode[] nodes = dataContainer.peekInternalNodeAndDirectParent(fqn, false); node = nodeFactory.createWrappedNodeForRemoval(fqn, nodes[0], nodes[1]); ctx.putLookedUpNode(fqn, node); } // node could be null if using read-committed if (forUpdate && node != null && !node.isChanged()) node.markForUpdate(dataContainer, writeSkewCheck); return node; }