Package org.jboss.cache

Examples of org.jboss.cache.InvocationContext


    * Similar to {@link #invoke(org.jboss.cache.InvocationContext , org.jboss.cache.commands.VisitableCommand)}, but
    * constructs a invocation context on the fly, using {@link InvocationContextContainer#get()}
    */
   public Object invokeRemote(VisitableCommand cacheCommand) throws Throwable
   {
      InvocationContext ctxt = invocationContextContainer.get();
      ctxt.setOriginLocal(false);
      return cacheCommand.acceptVisitor(ctxt, firstInChain);
   }
View Full Code Here


    * Similar to {@link #invoke(org.jboss.cache.InvocationContext , org.jboss.cache.commands.VisitableCommand)}, but
    * constructs a invocation context on the fly, using {@link InvocationContextContainer#get()} and setting the origin local flag to its default value.
    */
   public Object invoke(VisitableCommand cacheCommand) throws Throwable
   {
      InvocationContext ctxt = invocationContextContainer.get();
      return cacheCommand.acceptVisitor(ctxt, firstInChain);
   }
View Full Code Here

            log.trace("("+cache.getLocalAddress()+") call on method [" + m + "]");
        }
        // bypass for buddy group org metod calls.
        if (isBuddyGroupOrganisationMethod(m)) return super.invoke(m);

        InvocationContext ctx = getInvocationContext();

        final Transaction suspendedTransaction;
        boolean scrubTxsOnExit = false;
        final boolean resumeSuspended;
        Option optionOverride = ctx.getOptionOverrides();
       setTransactionInContext(ctx, txManager);

        if (optionOverride!= null && optionOverride.isFailSilently() && ctx.getTransaction() != null)
        {
           // make sure we remove the tx and global tx from the transaction table, since we don't care about this transaction
           // and will just suspend it.  - JBCACHE-1246
           GlobalTransaction gtx = txTable.remove(ctx.getTransaction());
           if (gtx != null) txTable.remove(gtx);

           suspendedTransaction = txManager.suspend();
           // set the tx in the invocation context to null now! - JBCACHE-785
           ctx.setTransaction(null);
           ctx.setGlobalTransaction(null);
            resumeSuspended = true;
        } else {
            suspendedTransaction = null;
            resumeSuspended = false;
        }

        Object result = null;

        try
        {
            // first of all deal with tx methods - these are only going to be
            // prepare/commit/rollback called by a remote cache, since calling
            // such methods on TreeCache directly would fail.

            if (isTransactionLifecycleMethod(m))
            {
                // this is a prepare, commit, or rollback.
                // start by setting transactional details into InvocationContext.
                ctx.setGlobalTransaction( findGlobalTransaction(m.getArgs()) );

                if (log.isDebugEnabled()) log.debug("Got gtx from method call " + ctx.getGlobalTransaction());
                ctx.getGlobalTransaction().setRemote( isRemoteGlobalTx(ctx.getGlobalTransaction()) );

                //replaceGtx(m, gtxFromMethodCall);
                if (ctx.getGlobalTransaction().isRemote()) remoteTransactions.put(ctx.getGlobalTransaction(),NULL);

                switch (m.getMethodId())
                {
                   case MethodDeclarations.optimisticPrepareMethod_id:
                   case MethodDeclarations.prepareMethod_id:
                      if (ctx.getGlobalTransaction().isRemote())
                      {
                          result = handleRemotePrepare(m, ctx.getGlobalTransaction());
                          scrubTxsOnExit = true;
                          if (cache.getUseInterceptorMbeans()&& statsEnabled)
                              m_prepares++;
                      }
                      else
                      {
                          if(log.isTraceEnabled()) log.trace("received my own message (discarding it)");
                          result = null;
                      }
                      break;
                   case MethodDeclarations.commitMethod_id:
                   case MethodDeclarations.rollbackMethod_id:
                      if (ctx.getGlobalTransaction().isRemote())
                      {
                          result = handleRemoteCommitRollback(m, ctx.getGlobalTransaction());
                          scrubTxsOnExit = true;
                      }
                      else
                      {
                          if (log.isTraceEnabled()) log.trace("received my own message (discarding it)");
                          result = null;
                      }
                      break;
                }
            }
            else
            {
                // non-transaction lifecycle method.
                result = handleNonTxMethod(m);
            }
        }
        catch (Exception e)
        {
            if (optionOverride == null || !optionOverride.isFailSilently()) throw e;
            log.trace("There was a problem handling this request, but " +
                  "failSilently was set, so suppressing exception", e);       
        }
        finally
        {
            if (resumeSuspended)
            {
                txManager.resume(suspendedTransaction);
            }
            else
            {
                if (ctx.getTransaction() != null && isValid(ctx.getTransaction()))
                {
                    copyInvocationScopeOptionsToTxScope(ctx);
                }
            }
View Full Code Here

     * @return
     * @throws Throwable
     */
    private Object handleNonTxMethod(MethodCall m) throws Throwable
    {
        InvocationContext ctx = getInvocationContext();
        Transaction tx = ctx.getTransaction();
        Object result;
        // if there is no current tx and we're using opt locking, we need to use an implicit tx.
        boolean implicitTransaction = cache.isNodeLockingOptimistic() && tx == null;
        if (implicitTransaction)
        {
            tx = createLocalTx();
            // we need to attach this tx to the InvocationContext.
            ctx.setTransaction( tx );
        }
        if (tx != null) m = attachGlobalTransaction(tx, m);

        try
        {
View Full Code Here

        return localTx;
    }

    private void setInvocationContext(Transaction tx, GlobalTransaction gtx)
    {
        InvocationContext ctx = getInvocationContext();
        ctx.setTransaction( tx );
        ctx.setGlobalTransaction( gtx );
    }
View Full Code Here

      if (cmd == null) throw new NullPointerException("Unable to execute a null command!  Message was " + req);
      if (trace) log.trace("Executing command: " + cmd + " [sender=" + req.getSrc() + "]");

      if (cmd instanceof VisitableCommand)
      {
         InvocationContext ctx = invocationContextContainer.get();
         ctx.setOriginLocal(false);
         if (!componentRegistry.invocationsAllowed(false))
         {
            return null;
         }
         return interceptorChain.invoke(ctx, (VisitableCommand) cmd);
View Full Code Here

   private void removeFromTreeCache(Fqn<?> fqn, boolean localOnly) throws Exception
   {
      if (localOnly)
      {
         InvocationContext ctx = cache.getInvocationContext();
         Option option = new Option();
         option.setCacheModeLocal(true);
         ctx.setOptionOverrides(option);
      }
      cache.removeNode(fqn);
   }
View Full Code Here

   private boolean executeRemove(GlobalTransaction gtx, Fqn toRemove) throws Throwable
   {
      Object result;
      RemoveNodeCommand removeBackupCommand = commandsFactory.buildRemoveNodeCommand(gtx, toRemove);

      InvocationContext ctx = invoker.getInvocationContext();
      ctx.getOptionOverrides().setCacheModeLocal(true);
      result = invoker.invoke(ctx, removeBackupCommand);
      return result != null && (Boolean) result;
   }
View Full Code Here

      Object callResults = null;
      try
      {
         if (trace) log.trace("Clustered get: invoking call with Fqn " + dataCommand.getFqn());
         InvocationContext ctx = interceptorChain.getInvocationContext();
         ctx.setOriginLocal(false);
         // very hacky to be calling this command directly.
         callResults = dataCommand.perform(ctx);
         boolean found = validResult(callResults);
         if (trace) log.trace("Got result " + callResults + ", found=" + found);
         if (found && callResults == null) callResults = createEmptyResults();
View Full Code Here

      return Version.printVersion();
   }

   public void move(Fqn<?> nodeToMove, Fqn<?> newParent) throws NodeNotExistsException
   {
      InvocationContext ctx = invocationContextContainer.get();
      cacheStatusCheck(ctx);
      MoveCommand command = commandsFactory.buildMoveCommand(nodeToMove, newParent);
      invoker.invoke(ctx, command);
   }
View Full Code Here

TOP

Related Classes of org.jboss.cache.InvocationContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.