private void prepareContextOptions() { cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true); cache.getInvocationContext().getOptionOverrides().setSkipCacheStatusCheck(true); cache.getInvocationContext().getOptionOverrides().setSuppressPersistence(!needToPersistState); }
@Override public NodeSPI<K, V> addChildDirect(Object o, boolean notify) { GlobalTransaction gtx = cache.getInvocationContext().getGlobalTransaction(); return getOrCreateChild(o, gtx, true, notify, null); }
public NodeSPI<K, V> addChildAndAcquireLock(Object o, boolean notify, PessimisticNodeBasedLockManager.LockAcquirer la) { GlobalTransaction gtx = cache.getInvocationContext().getGlobalTransaction(); return getOrCreateChild(o, gtx, true, notify, la); }
cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true); cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(false);
@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."); } }
private Fqn getDefunctBackupRootFqn(Address dataOwner) { // the defunct Fqn should be: /_BUDDY_BACKUP_/dataOwnerAddess:DEAD/N // where N is a number. Fqn defunctRoot = buddyFqnTransformer.getDeadBackupRoot(dataOwner); cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true); cache.getInvocationContext().getOptionOverrides().setSkipCacheStatusCheck(true); Node<?, ?> root = cache.getRoot(); cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true); cache.getInvocationContext().getOptionOverrides().setSkipCacheStatusCheck(true); Node<?, ?> defunctRootNode = root.addChild(defunctRoot); SortedSet<Object> childrenNames = new TreeSet<Object>(defunctRootNode.getChildrenNames()); // will be naturally sorted. Integer childName = 1; if (!childrenNames.isEmpty()) { Integer lastChild = (Integer) childrenNames.last(); childName = lastChild + 1; } cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true); defunctRootNode.addChild(Fqn.fromElements(childName)); return Fqn.fromRelativeElements(defunctRoot, childName); }
public Node<K, V> addChild(Fqn f) { // TODO: Revisit. Is this really threadsafe? See comment in putIfAbsent() - same solution should be applied here too. assertValid(); Fqn nf = Fqn.fromRelativeFqn(getFqn(), f); Option o1 = spi.getInvocationContext().getOptionOverrides().copy(); Node<K, V> child = getChild(f); if (child == null) { if (trace) log.trace("Child is null; creating."); Option o2 = o1.copy(); spi.getInvocationContext().setOptionOverrides(o1); spi.put(nf, null); if (trace) log.trace("Created. Now getting again."); spi.getInvocationContext().setOptionOverrides(o2); child = getChild(f); if (trace) log.trace("Got child " + child); } return child; }
protected void integrateTransientState(ObjectInputStream in, NodeSPI target) throws Exception { boolean transientSet = false; try { if (log.isTraceEnabled()) { log.trace("integrating transient state for " + target); } integrateTransientState(target, in); transientSet = true; if (log.isTraceEnabled()) { log.trace("transient state successfully integrated"); } notifyAllNodesCreated(cache.getInvocationContext(), target); } catch (Exception e) { throw new CacheException(e); } finally { if (!transientSet) { target.clearDataDirect(); target.removeChildrenDirect(); } } }
public void setState(ObjectInputStream in, Fqn targetRoot) throws Exception { if (trace) log.trace("Setting state on Fqn root " + targetRoot); cache.getInvocationContext().getOptionOverrides().setSkipCacheStatusCheck(true); NodeSPI target = cache.getNode(targetRoot); if (target == null) { if(trace) log.trace("Target node not found, creating it"); // Create the integration root, but do not replicate cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true); //needed for BR state transfers cache.getInvocationContext().getOptionOverrides().setSkipCacheStatusCheck(true); cache.put(targetRoot, null); cache.getInvocationContext().getOptionOverrides().setSkipCacheStatusCheck(true); target = cache.getNode(targetRoot); } Object o = marshaller.objectFromObjectStream(in); Boolean hasState = (Boolean) o; if (trace) log.trace("Do we have state to integrate? " + hasState); if (hasState) { setState(in, target); } else { throw new CacheException("Cache instance at " + cache.getLocalAddress() + " cannot integrate state since state provider could not provide state due to " + marshaller.objectFromObjectStream(in)); } }
public Set getChildrenNames(Fqn fqn) throws Exception { if (!isCacheReady() || !cache.getInvocationContext().isOriginLocal()) return Collections.emptySet(); lock.acquireLock(fqn, true); try { GetChildrenNamesCommand command = commandsFactory.buildGetChildrenNamesCommand(fqn); Object resp = callRemote(command); return (Set) resp; } finally { lock.releaseLock(fqn); } }
private void migrateDefunctData(NodeSPI backupRoot, Address dataOwner) { Fqn defunctBackupRootFqn = getDefunctBackupRootFqn(dataOwner); if (log.isDebugEnabled()) log.debug("Migrating defunct data. Backup root is " + backupRoot + ". New backup root is " + defunctBackupRootFqn); if (trace) log.trace("Children of backup root are " + backupRoot.getChildren()); String ownerName = buddyFqnTransformer.getGroupNameFromAddress(dataOwner); Set<DefunctDataHistory> newHistorySet = new ConcurrentHashSet<DefunctDataHistory>(); Set<DefunctDataHistory> historySet = defunctDataHistory.putIfAbsent(ownerName, newHistorySet); if (historySet == null) { historySet = newHistorySet; } DefunctDataHistory history = new DefunctDataHistory(dataOwner, (Integer) defunctBackupRootFqn.getLastElement(), System.currentTimeMillis()); historySet.add(history); for (Object child : backupRoot.getChildren()) { Fqn childFqn = ((Node) child).getFqn(); cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true); cache.move(childFqn, defunctBackupRootFqn); } history.recordDataMoved(); cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true); backupRoot.getParentDirect().removeChild(backupRoot.getFqn().getLastElement()); }
notifyAllNodesCreated(cache.getInvocationContext(), target);
public boolean exists(Fqn name) throws Exception { // DON'T make a remote call if this is a remote call in the first place - leads to deadlocks - JBCACHE-1103 if (!isCacheReady() || !cache.getInvocationContext().isOriginLocal()) return false; lock.acquireLock(name, false); try { ExistsCommand command = commandsFactory.buildExistsNodeCommand(name); Object resp = callRemote(command); return resp != null && (Boolean) resp; } finally { lock.releaseLock(name); } }
InvocationContext ctx = cache.getInvocationContext(); if (createIfNotExists && child == null)
protected Map get0(Fqn name) throws Exception { // DON'T make a remote call if this is a remote call in the first place - leads to deadlocks - JBCACHE-1103 if (!isCacheReady() || !cache.getInvocationContext().isOriginLocal()) return null; // return Collections.emptyMap(); lock.acquireLock(name, true); try { GetDataMapCommand command = commandsFactory.buildGetDataMapCommand(name); Object resp = callRemote(command); return (Map) resp; } finally { lock.releaseLock(name); } }
if (usePut) cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true); cache.getInvocationContext().getOptionOverrides().setSkipCacheStatusCheck(true); target.clearData(); cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true); cache.getInvocationContext().getOptionOverrides().setSkipCacheStatusCheck(true); target.putAll(attributes);
private Node getInternalNode(Node parent, Fqn internalFqn) { Object name = internalFqn.get(parent.getFqn().size()); cache.getInvocationContext().getOptionOverrides().setSkipCacheStatusCheck(true); Node result = parent.getChild(name); if (result != null && internalFqn.size() < result.getFqn().size()) { // need to recursively walk down the tree result = getInternalNode(result, internalFqn); } return result; }
public Object put(Fqn name, Object key, Object value) throws Exception { // DON'T make a remote call if this is a remote call in the first place - leads to deadlocks - JBCACHE-1103 if (!isCacheReady() || !cache.getInvocationContext().isOriginLocal()) return null; lock.acquireLock(name, true); try { NodeSPI n = cache.peek(name, false); if (n == null) { GetKeyValueCommand command = commandsFactory.buildGetKeyValueCommand(name, key, true); return callRemote(command); } else { // dont bother with a remote call return n.getDirect(key); } } finally { lock.releaseLock(name); } }
/** * Fetches the remove value, does not remove. Replication handles * removal. */ public Object remove(Fqn name, Object key) throws Exception { // DON'T make a remote call if this is a remote call in the first place - leads to deadlocks - JBCACHE-1103 if (!isCacheReady() || !cache.getInvocationContext().isOriginLocal()) return false; lock.acquireLock(name, true); try { NodeSPI n = cache.peek(name, true); if (n == null) { GetKeyValueCommand command = commandsFactory.buildGetKeyValueCommand(name, key, true); return callRemote(command); } else { // dont bother with a remote call return n.getDirect(key); } } finally { lock.releaseLock(name); } }
GlobalTransaction gtx = cache.getInvocationContext().getGlobalTransaction();