public Object getLockOwner(InvocationContext ctx) { return ctx.getGlobalTransaction() != null ? ctx.getGlobalTransaction() : Thread.currentThread(); } }
/** * @return a GlobalTransaction instance if the current call is participating in a transaction, or the current thread otherwise. */ protected final Object currentRequestor() { GlobalTransaction gtx; return (gtx = invocationContextContainer.get().getGlobalTransaction()) == null ? Thread.currentThread() : gtx; }
@Override public Object visitRollbackCommand(InvocationContext ctx, RollbackCommand command) throws Throwable { try { return invokeNextInterceptor(ctx, command); } finally { cleanupCommands.remove(ctx.getGlobalTransaction()); } }
private GlobalTransaction getGlobalTransaction(InvocationContext ctx) { // get the current globalTransaction GlobalTransaction gtx = ctx.getGlobalTransaction(); if (gtx == null) { throw new CacheException("failed to get global transaction"); } return gtx; }
@Override protected Object handleRollbackCommand(InvocationContext ctx, RollbackCommand command) throws Throwable { try { return super.handleRollbackCommand(ctx, command); } finally { if (optimistic) { GlobalTransaction gtx = ctx.getGlobalTransaction(); preparingTxs.remove(gtx); } } }
@Override public Object visitRollbackCommand(InvocationContext ctx, RollbackCommand command) throws Throwable { Object retval = invokeNextInterceptor(ctx, command); Transaction tx = ctx.getTransaction(); if (tx != null && optimistic) { GlobalTransaction gtx = ctx.getGlobalTransaction(); txMods.remove(gtx); log.debug("Caught a rollback. Clearing modification in txMods"); } return retval; }
private Object dataGravitationCleanupOnCommit(InvocationContext ctx, VisitableCommand command) throws Throwable { GlobalTransaction gtx = ctx.getGlobalTransaction(); try { doCommit(gtx); return invokeNextInterceptor(ctx, command); } finally { cleanupCommands.remove(gtx); } }
/** * 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); }
@Override protected Object handleCommitCommand(InvocationContext ctx, CommitCommand command) throws Throwable { Object returnValue = super.handleCommitCommand(ctx, command); // persist additional internal state, if any, and then clean up internal resources // specifically for optimistic locking to store versioning info AFTER a tx has committed. Hacky. // note - do NOT do this in a finally block. If the commit fails we shouldn't do this. if (optimistic) { // if the commit fails, preparingTxs will be cleaned up in a call to handleRollbackCommand() Set<Fqn> affectedFqns = preparingTxs.remove(ctx.getGlobalTransaction()); if (affectedFqns != null && !affectedFqns.isEmpty()) { storeInternalState(affectedFqns, ctx); } } return returnValue; }
@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); }
@Override public Object visitCommitCommand(InvocationContext ctx, CommitCommand command) throws Throwable { Object retval = invokeNextInterceptor(ctx, command); Transaction tx = ctx.getTransaction(); if (tx != null && optimistic) { GlobalTransaction gtx = ctx.getGlobalTransaction(); List<WriteCommand> modifications = txMods.remove(gtx); broadcastInvalidate(modifications, tx, ctx); if (trace) log.trace("Committing. Broadcasting invalidations."); } return retval; }
@SuppressWarnings("unchecked") private void transactionalCleanup(boolean commit, InvocationContext ctx) { if (ctx.getTransactionContext() != null) { List<Fqn> locks = ctx.getTransactionContext().getLocks(); if (!locks.isEmpty()) cleanupLocks(locks, ctx, ctx.getGlobalTransaction(), commit); } else { throw new IllegalStateException("Attempting to do a commit or rollback but there is no transactional context in scope. " + ctx); } } }
/** * @return the {@link org.jboss.cache.transaction.GlobalTransaction}, extracted from the current {@link org.jboss.cache.InvocationContext}. * @throws CacheException if the {@link org.jboss.cache.transaction.GlobalTransaction} or {@link javax.transaction.Transaction} associated with the * {@link org.jboss.cache.InvocationContext} is null. */ protected GlobalTransaction getGlobalTransaction(InvocationContext ctx) throws CacheException { Transaction tx = ctx.getTransaction(); if (tx == null) throw new CacheException("Transaction associated with the current invocation is null!"); GlobalTransaction gtx = ctx.getGlobalTransaction(); if (gtx == null) throw new CacheException("GlobalTransaction associated with the current invocation is null!"); return gtx; }
protected TransactionWorkspace getTransactionWorkspace(InvocationContext ctx) throws CacheException { OptimisticTransactionContext transactionContext = (OptimisticTransactionContext) ctx.getTransactionContext(); if (transactionContext == null) { throw new CacheException("Unable to map global transaction " + ctx.getGlobalTransaction() + " to transaction entry when trying to retrieve transaction workspace."); } // try and get the workspace from the transaction return transactionContext.getTransactionWorkSpace(); }
@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."); } }
@Override protected Object handlePrepareCommand(InvocationContext ctx, PrepareCommand command) throws Throwable { // 2-phase commit prepares are no-ops here. if (!command.isOnePhaseCommit()) return invokeNextInterceptor(ctx, command); // commit propagated up from the tx interceptor commit(ctx.getTransactionContext(), ctx.getGlobalTransaction()); Object retVal = invokeNextInterceptor(ctx, command); lockManager.unlock(ctx); 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(); }
/** * 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()); }
protected void copyInvocationScopeOptionsToTxScope(InvocationContext ctx) { // notify the transaction tCtx that this override is in place. TransactionContext tCtx = txTable.get(ctx.getGlobalTransaction()); if (tCtx != null) { Option txScopeOption = new Option(); txScopeOption.setCacheModeLocal(ctx.getOptionOverrides() != null && ctx.getOptionOverrides().isCacheModeLocal()); txScopeOption.setSkipCacheStatusCheck(ctx.getOptionOverrides() != null && ctx.getOptionOverrides().isSkipCacheStatusCheck()); tCtx.setOption(txScopeOption); } }