/** * 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 boolean lockAllAndRecord(NodeSPI node, LockType lockType, InvocationContext ctx) { List<NodeLock> locks = lockAllNodes(node, lockType, getLockOwner(ctx), ctx.getLockAcquisitionTimeout(lockAcquisitionTimeout), false); if (locks == null) return false; if (locks.size() > 0) { ctx.addAllLocks(locks); } return true; }
@Override protected void recordNodeLoaded(InvocationContext ctx, Fqn fqn) { ctx.addFqnLoaded(fqn); } }
/** * The call runs in a transaction and it was initiated on this node of the cluster. */ protected boolean isTransactionalAndLocal(InvocationContext ctx) { GlobalTransaction gtx = ctx.getGlobalTransaction(); boolean isInitiatedHere = gtx != null && !gtx.isRemote(); return isInitiatedHere && (ctx.getTransaction() != null); }
public boolean lockAndRecord(Fqn fqn, LockType lockType, InvocationContext ctx) throws InterruptedException { if (lockType == READ) return true; // we don't support read locks. if (trace) log.trace("Attempting to lock " + fqn); if (lockContainer.acquireLock(fqn, ctx.getLockAcquisitionTimeout(lockAcquisitionTimeout), MILLISECONDS)) { ctx.addLock(fqn); return true; } // couldn't acquire lock! return false; }
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); } }
@SuppressWarnings("deprecation") private Object handleAll(InvocationContext ctx, VisitableCommand command, GlobalTransaction gtx, boolean scrubContextOnCompletion) throws Throwable Option optionOverride = ctx.getOptionOverrides(); boolean suppressExceptions = false; Transaction suspendedTransaction = null; if (ctx.getTransaction() != null) ctx.getOptionOverrides().reset(); ctx.setFqnsLoaded(null); else if (ctx.getTransaction() != null && (TransactionTable.isValid(ctx.getTransaction()))) ctx.setCommand(null); ctx.setMethodCall(null); ctx.clearLookedUpNodes();
private Object handleDataVersionCommand(InvocationContext ctx, VersionedDataCommand command) throws Throwable { Option originalOption = ctx.getOptionOverrides(); if (command.isVersioned()) { Option option = new Option(); option.setDataVersion(command.getDataVersion()); ctx.setOptionOverrides(option); } Object retval; try { retval = invokeNextInterceptor(ctx, command); assertTxIsStillValid(ctx.getTransaction()); } catch (Throwable t) { log.error("method invocation failed", t); throw t; } finally { ctx.setOptionOverrides(originalOption); } return retval; } }
/** * It does not make sense replicating a transaction method(commit, rollback, prepare) if one of the following is true: * <pre> * - call was not initiated here, but on other member of the cluster * - there is no transaction. Why broadcast a commit or rollback if there is no transaction going on? * - the current transaction did not modify any data * </pre> */ protected boolean skipReplicationOfTransactionMethod(InvocationContext ctx) { GlobalTransaction gtx = ctx.getGlobalTransaction(); return ctx.getTransaction() == null || gtx == null || gtx.isRemote() || ctx.getOptionOverrides().isCacheModeLocal() || !ctx.getTransactionContext().hasModifications(); }
/** * only add the modification to the modification list if we are using pessimistic locking. * Optimistic locking calls *should* not make it this far down the interceptor chain, but just * in case a method has been invoked that the OptimisticNodeInterceptor knows nothing about, it will * filter down here. */ private Object handleAlterCacheMethod(InvocationContext ctx, WriteCommand command) throws Throwable { Object result = invokeCommand(ctx, command); if (notOptimisticLocking && ctx.isValidTransaction()) { GlobalTransaction gtx = ctx.getGlobalTransaction(); if (gtx == null) { if (log.isDebugEnabled()) { log.debug("didn't find GlobalTransaction for " + ctx.getTransaction() + "; won't add modification to transaction list"); } } else { ctx.getTransactionContext().addModification(command); } } return result; } }
/** * Assigns the given Option to the cache's {@link InvocationContext}. Does * nothing if <code>option</code> is <code>null</code>. * * @param cache * the cache. Cannot be <code>null</code>. * @param option * the option. May be <code>null</code>. * * @see {@link Cache#getInvocationContext()} * @see {@link InvocationContext#setOptionOverrides(Option)} */ public static void setInvocationOption(Cache cache, Option option) { if (option != null) { cache.getInvocationContext().setOptionOverrides(option); } }
Transaction ltx = ctx.getTransaction(); if (currentTransaction != null && ltx != null && currentTransaction.equals(ltx)) VisitableCommand originalCommand = ctx.getCommand(); ctx.setCommand(prepareCommand); try ctx.setCommand(originalCommand); ctx.setMethodCall(null);
public void beforeCompletion() { if (trace) log.trace("Running beforeCompletion on gtx " + gtx); if (transactionContext == null) { log.error("Transaction has a null transaction entry - beforeCompletion() will fail."); throw new IllegalStateException("cannot find transaction entry for " + gtx); } modifications = transactionContext.getModifications(); ctx = invocationContextContainer.get(); setTransactionalContext(tx, gtx, transactionContext, ctx); if (ctx.isOptionsUninitialised() && transactionContext.getOption() != null) { ctx.setOptionOverrides(transactionContext.getOption()); } assertCanContinue(); ctx.setOriginLocal(false); }
/** * If we are within one transaction we won't do any replication as replication would only be performed at commit time. * If the operation didn't originate locally we won't do any replication either. */ private Object handleCrudMethod(InvocationContext ctx, VisitableCommand command, boolean forceAsync) throws Throwable { boolean local = isLocalModeForced(ctx); if (local && ctx.getTransaction() == null) return invokeNextInterceptor(ctx, command); // FIRST pass this call up the chain. Only if it succeeds (no exceptions) locally do we attempt to replicate. Object returnValue = invokeNextInterceptor(ctx, command); if (ctx.getTransaction() == null && ctx.isOriginLocal()) { if (trace) { log.trace("invoking method " + command.getClass().getSimpleName() + ", members=" + rpcManager.getMembers() + ", mode=" + configuration.getCacheMode() + ", exclude_self=" + true + ", timeout=" + configuration.getSyncReplTimeout()); } replicateCall(ctx, command, !forceAsync && isSynchronous(ctx.getOptionOverrides()), ctx.getOptionOverrides()); } else { if (local) ctx.getTransactionContext().addLocalModification((WriteCommand) command); } return returnValue; }
protected Object attachGtxAndPassUpChain(InvocationContext ctx, VisitableCommand command) throws Throwable { Transaction tx = ctx.getTransaction(); if (tx != null) attachGlobalTransaction(ctx, tx, command); return invokeNextInterceptor(ctx, command); }
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; }
@Override public Object visitOptimisticPrepareCommand(InvocationContext ctx, OptimisticPrepareCommand command) throws Throwable { Object retval = invokeNextInterceptor(ctx, command); Transaction tx = ctx.getTransaction(); if (tx != null) { // here we just record the modifications but actually do the invalidate in commit. GlobalTransaction gtx = ctx.getGlobalTransaction(); TransactionContext transactionContext = ctx.getTransactionContext(); if (transactionContext == null) throw new IllegalStateException("cannot find transaction transactionContext for " + gtx); if (transactionContext.hasModifications()) { List<WriteCommand> mods = new ArrayList<WriteCommand>(transactionContext.getModifications()); if (transactionContext.hasLocalModifications()) mods.removeAll(transactionContext.getLocalModifications()); txMods.put(gtx, mods); } } return retval; }
setTransactionalContext(tx, gtx, transactionContext, ctx); if (ctx.isOptionsUninitialised() && transactionContext != null && transactionContext.getOption() != null) ctx.setOptionOverrides(transactionContext.getOption()); boolean isSuppressEventNotification = ctx.getOptionOverrides().isSuppressEventNotification(); ctx.setOptionOverrides(transactionContext.getOption()); ctx.getOptionOverrides().setSuppressEventNotification(isSuppressEventNotification);
ctx.setOriginLocal(!remoteLocal); // this is the LOCAL sync handler after all! originalOptions = ctx.getOptionOverrides(); transactionalOptions = transactionContext.getOption(); transactionalOptions.setSuppressEventNotification(originalOptions.isSuppressEventNotification()); ctx.setOptionOverrides(transactionalOptions); ctx.setOptionOverrides(originalOptions);
@Override protected Object handleMoveCommand(InvocationContext ctx, MoveCommand command) throws Throwable if (ctx.isLockingSuppressed()) return invokeNextInterceptor(ctx, command); if (ctx.getGlobalTransaction() != null) ctx.getTransactionContext().addRemovedNode(command.getFqn()); if (ctx.getTransaction() == null) // not transactional