protected MarshalledValue createAndAddMarshalledValue(Object toWrap, Set<MarshalledValue> marshalledValues, InvocationContext ctx) throws NotSerializableException { MarshalledValue mv = new MarshalledValue(toWrap); marshalledValues.add(mv); if (!ctx.isOriginLocal()) mv.setEqualityPreferenceForInstance(false); return mv; } }
/** * if this is a shared cache loader and the call is of remote origin, pass up the chain */ @Override public boolean skipInterception(InvocationContext ctx, VisitableCommand command) { if ((!ctx.isOriginLocal() && loaderConfig.isShared()) || ctx.getOptionOverrides().isSuppressPersistence()) { if (trace) { log.trace("Passing up method call and bypassing this interceptor since the cache loader is shared and this call originated remotely."); } return true; } return false; }
private boolean isGravitationEnabled(InvocationContext ctx) { boolean enabled = ctx.isOriginLocal(); if (enabled && !buddyManager.isAutoDataGravitation()) { enabled = ctx.getOptionOverrides().getForceDataGravitation(); } return enabled; }
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); } }
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); } }
/** * Sets the state of the InvocationContext based on the template context passed in * * @param template template to copy from */ public void setState(InvocationContext template) { if (template == null) { throw new NullPointerException("Template InvocationContext passed in to InvocationContext.setState() passed in is null"); } this.setGlobalTransaction(template.getGlobalTransaction()); this.setLocalRollbackOnly(template.isLocalRollbackOnly()); this.setOptionOverrides(template.getOptionOverrides()); this.setOriginLocal(template.isOriginLocal()); this.setTransaction(template.getTransaction()); }
public void notifyTransactionRegistered(Transaction transaction, InvocationContext ctx) { if (!transactionRegisteredListeners.isEmpty() && !ctx.getOptionOverrides().isSuppressEventNotification()) { boolean isOriginLocal = ctx.isOriginLocal(); InvocationContext backup = resetInvocationContext(ctx); EventImpl e = new EventImpl(); e.setCache(cache); e.setOriginLocal(isOriginLocal); e.setTransaction(transaction); e.setType(TRANSACTION_REGISTERED); for (ListenerInvocation listener : transactionRegisteredListeners) listener.invoke(e); restoreInvocationContext(backup); } }
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); } }
public void notifyTransactionCompleted(Transaction transaction, boolean successful, InvocationContext ctx) { if (!transactionCompletedListeners.isEmpty() && !ctx.getOptionOverrides().isSuppressEventNotification()) { boolean isOriginLocal = ctx.isOriginLocal(); InvocationContext backup = resetInvocationContext(ctx); EventImpl e = new EventImpl(); e.setCache(cache); e.setOriginLocal(isOriginLocal); e.setTransaction(transaction); e.setSuccessful(successful); e.setType(TRANSACTION_COMPLETED); for (ListenerInvocation listener : transactionCompletedListeners) listener.invoke(e); restoreInvocationContext(backup); } }
public void notifyNodeCreated(Fqn fqn, boolean pre, InvocationContext ctx) { if (!nodeCreatedListeners.isEmpty() && !ctx.getOptionOverrides().isSuppressEventNotification()) { boolean originLocal = ctx.isOriginLocal(); Transaction tx = ctx.getTransaction(); InvocationContext backup = resetInvocationContext(ctx); EventImpl e = new EventImpl(); e.setCache(cache); e.setOriginLocal(originLocal); e.setPre(pre); e.setFqn(fqn); e.setTransaction(tx); e.setType(NODE_CREATED); for (ListenerInvocation listener : nodeCreatedListeners) listener.invoke(e); restoreInvocationContext(backup); } }
public void notifyNodeInvalidated(final Fqn fqn, final boolean pre, InvocationContext ctx) { if (!nodeInvalidatedListeners.isEmpty() && !ctx.getOptionOverrides().isSuppressEventNotification()) { final boolean originLocal = ctx.isOriginLocal(); Transaction tx = ctx.getTransaction(); InvocationContext backup = resetInvocationContext(ctx); EventImpl e = new EventImpl(); e.setCache(cache); e.setOriginLocal(originLocal); e.setPre(pre); e.setFqn(fqn); e.setTransaction(tx); e.setType(NODE_INVALIDATED); for (ListenerInvocation listener : nodeInvalidatedListeners) listener.invoke(e); restoreInvocationContext(backup); } }
/** * 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); } }
public void notifyNodeEvicted(final Fqn fqn, final boolean pre, InvocationContext ctx) { if (!nodeEvictedListeners.isEmpty() && !ctx.getOptionOverrides().isSuppressEventNotification()) { final boolean originLocal = ctx.isOriginLocal(); Transaction tx = ctx.getTransaction(); InvocationContext backup = resetInvocationContext(ctx); EventImpl e = new EventImpl(); e.setCache(cache); e.setOriginLocal(originLocal); e.setPre(pre); e.setFqn(fqn); e.setTransaction(tx); e.setType(NODE_EVICTED); for (ListenerInvocation listener : nodeEvictedListeners) listener.invoke(e); restoreInvocationContext(backup); } }
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); } }
public void notifyNodeMoved(Fqn originalFqn, Fqn newFqn, boolean pre, InvocationContext ctx) { if (!nodeMovedListeners.isEmpty() && !ctx.getOptionOverrides().isSuppressEventNotification()) { boolean originLocal = ctx.isOriginLocal(); Transaction tx = ctx.getTransaction(); InvocationContext backup = resetInvocationContext(ctx); EventImpl e = new EventImpl(); e.setCache(cache); e.setOriginLocal(originLocal); e.setPre(pre); e.setFqn(originalFqn); e.setTargetFqn(newFqn); e.setTransaction(tx); e.setType(NODE_MOVED); for (ListenerInvocation listener : nodeMovedListeners) listener.invoke(e); restoreInvocationContext(backup); } }
@Override public Object visitMoveCommand(InvocationContext ctx, MoveCommand command) throws Throwable { TransactionWorkspace workspace = getTransactionWorkspace(ctx); WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, command.getFqn(), workspace, true, true); if (ctx.isOriginLocal() && ctx.getOptionOverrides() != null && ctx.getOptionOverrides().getDataVersion() != null) { throw new CacheException("Setting a data version while performing a move() is not supported!!"); } if (workspaceNode != null) { setVersioning(ctx, workspace, workspaceNode); } moveNodeAndNotify(command.getTo(), workspaceNode, workspace, ctx); addToModificationList(command, ctx); return null; }
public void notifyNodeActivated(Fqn fqn, boolean pre, Map data, InvocationContext ctx) { if (!nodeActivatedListeners.isEmpty() && !ctx.getOptionOverrides().isSuppressEventNotification()) { boolean originLocal = ctx.isOriginLocal(); Map dataCopy = copy(data, useMarshalledValueMaps); Transaction tx = ctx.getTransaction(); InvocationContext backup = resetInvocationContext(ctx); EventImpl e = new EventImpl(); e.setCache(cache); e.setOriginLocal(originLocal); e.setPre(pre); e.setFqn(fqn); e.setTransaction(tx); e.setData(dataCopy); e.setType(NODE_ACTIVATED); for (ListenerInvocation listener : nodeActivatedListeners) listener.invoke(e); restoreInvocationContext(backup); } }
public void notifyNodeRemoved(Fqn fqn, boolean pre, Map data, InvocationContext ctx) { if (!nodeRemovedListeners.isEmpty() && !ctx.getOptionOverrides().isSuppressEventNotification()) { boolean originLocal = ctx.isOriginLocal(); Map dataCopy = copy(data, useMarshalledValueMaps); Transaction tx = ctx.getTransaction(); InvocationContext backup = resetInvocationContext(ctx); EventImpl e = new EventImpl(); e.setCache(cache); e.setOriginLocal(originLocal); e.setPre(pre); e.setFqn(fqn); e.setTransaction(tx); e.setData(dataCopy); e.setType(NODE_REMOVED); for (ListenerInvocation listener : nodeRemovedListeners) listener.invoke(e); restoreInvocationContext(backup); } }
public void notifyNodeLoaded(Fqn fqn, boolean pre, Map data, InvocationContext ctx) { if (!nodeLoadedListeners.isEmpty() && !ctx.getOptionOverrides().isSuppressEventNotification()) { boolean originLocal = ctx.isOriginLocal(); Map dataCopy = copy(data, useMarshalledValueMaps); Transaction tx = ctx.getTransaction(); InvocationContext backup = resetInvocationContext(ctx); EventImpl e = new EventImpl(); e.setCache(cache); e.setOriginLocal(originLocal); e.setPre(pre); e.setFqn(fqn); e.setTransaction(tx); e.setData(dataCopy); e.setType(NODE_LOADED); for (ListenerInvocation listener : nodeLoadedListeners) listener.invoke(e); restoreInvocationContext(backup); } }
public void notifyNodeModified(Fqn fqn, boolean pre, NodeModifiedEvent.ModificationType modificationType, Map data, InvocationContext ctx) { if (!nodeModifiedListeners.isEmpty() && !ctx.getOptionOverrides().isSuppressEventNotification()) { boolean originLocal = ctx.isOriginLocal(); Map dataCopy = copy(data, useMarshalledValueMaps); Transaction tx = ctx.getTransaction(); InvocationContext backup = resetInvocationContext(ctx); EventImpl e = new EventImpl(); e.setCache(cache); e.setOriginLocal(originLocal); e.setPre(pre); e.setFqn(fqn); e.setTransaction(tx); e.setModificationType(modificationType); e.setData(dataCopy); e.setType(NODE_MODIFIED); for (ListenerInvocation listener : nodeModifiedListeners) listener.invoke(e); restoreInvocationContext(backup); } }