Package org.jboss.cache.marshall

Examples of org.jboss.cache.marshall.JBCMethodCall


    * be moved entirely into the ReplicationInterceptor.
    */
   public Object _replicate(MethodCall method_call) throws Throwable
   {
      if (log.isTraceEnabled()) log.trace(getLocalAddress() + " received call " + method_call);
      JBCMethodCall jbcCall = (JBCMethodCall) method_call;
      try
      {
         getInvocationContext().setOriginLocal(false);

         Object result = invokeMethod(method_call);

         // Patch from Owen Taylor - JBCACHE-766
         // We replicating, we don't need to return the return value of the put-key-value
         // methods and the return values will cause marshalling problems, so we
         // omit them.
         if (jbcCall.getMethodId() == MethodDeclarations.putKeyValMethodLocal_id ||
                 jbcCall.getMethodId() == MethodDeclarations.putFailFastKeyValueMethodLocal_id ||
                 jbcCall.getMethodId() == MethodDeclarations.removeKeyMethodLocal_id)
            return null;
         else
            return result;
      }
      catch (Exception ex)
      {
         // patch from Owen Taylor (otaylor@redhat.com) to fix JBCACHE-786
         // The point of putFailFast() is to allow the caller to catch and ignore timeouts;
         // but they don't get a chance to do that for the (always async) replicated version,
         // so we just ignore timeout exceptions for putFailFast here.

         if (jbcCall.getMethodId() == MethodDeclarations.putFailFastKeyValueMethodLocal_id && ex instanceof TimeoutException)
         {
            log.debug("ignoring timeout exception when replicating putFailFast");
            return null;
         }

View Full Code Here


    * @return a List containing 2 elements: (Boolean.TRUE or Boolean.FALSE) and a value (Object).  If buddy replication
    *         is used one further element is added - an Fqn of the backup subtree in which this node may be found.
    */
   public List _clusteredGet(MethodCall methodCall, Boolean searchBackupSubtrees)
   {
      JBCMethodCall call = (JBCMethodCall) methodCall;
      if (log.isTraceEnabled()) log.trace("Clustered Get called with params: " + call + ", " + searchBackupSubtrees);
      Method m = call.getMethod();
      Object[] args = call.getArgs();

      Object callResults = null;

      try
      {
View Full Code Here

   }


   public Object invoke(MethodCall call) throws Throwable
   {
      JBCMethodCall m = (JBCMethodCall) call;
      Fqn fqn = null;
      int lock_type = DataNode.LOCK_TYPE_NONE;
      long lock_timeout = lock_acquisition_timeout;
      Object[] args = m.getArgs();
      InvocationContext ctx = getInvocationContext();
      boolean storeLockedNode = false;

      if (log.isTraceEnabled()) log.trace("PessimisticLockInterceptor invoked for method " + m);
      if (ctx.getOptionOverrides() != null && ctx.getOptionOverrides().isSuppressLocking())
      {
         log.trace("Suppressing locking");
         switch (m.getMethodId())
         {
            case MethodDeclarations.putDataMethodLocal_id:
            case MethodDeclarations.putDataEraseMethodLocal_id:
            case MethodDeclarations.putKeyValMethodLocal_id:
            case MethodDeclarations.putFailFastKeyValueMethodLocal_id:
               log.trace("Creating nodes if necessary");
               createNodes((Fqn) args[1], ctx.getGlobalTransaction());
               break;
         }

         return super.invoke(m);
      }

      /** List<IdentityLock> locks. Locks acquired during the current method; will be released later by UnlockInterceptor.
       *  This list is only populated when there is no TX, otherwise the TransactionTable maintains the locks
       * (keyed by TX) */
      // List locks=null;

      boolean recursive = false;
      boolean createIfNotExists = false;
      boolean zeroLockTimeout = false; // only used if the call is an evict() call.  See JBCACHE-794
      boolean isRemoveData = false;

      // 1. Determine the type of lock (read, write, or none) depending on the method. If no lock is required, invoke
      //    the method, then return immediately
      //    Set the Fqn
      switch (m.getMethodId())
      {
         case MethodDeclarations.putDataMethodLocal_id:
         case MethodDeclarations.putDataEraseMethodLocal_id:
         case MethodDeclarations.putKeyValMethodLocal_id:
         case MethodDeclarations.putFailFastKeyValueMethodLocal_id:
            createIfNotExists = true;
            fqn = (Fqn) args[1];
            lock_type = DataNode.LOCK_TYPE_WRITE;
            if (m.getMethodId() == MethodDeclarations.putFailFastKeyValueMethodLocal_id)
               lock_timeout = ((Long) args[5]).longValue();
            break;
         case MethodDeclarations.removeNodeMethodLocal_id:
            fqn = (Fqn) args[1];
            lock_type = DataNode.LOCK_TYPE_WRITE;
            recursive = true; // remove node and *all* child nodes
            // BES 2007/12/12 -- Revert JBCACHE-1165 fix as it causes endless loop
            // in TransactionTest.testDoubleNodeRemoval, plus another failure
            // in that test
//            createIfNotExists = true;
            // JBCACHE-871 We need to store the node
            storeLockedNode = true;
            break;
         case MethodDeclarations.removeKeyMethodLocal_id:
         case MethodDeclarations.removeDataMethodLocal_id:
            isRemoveData = true;
         case MethodDeclarations.addChildMethodLocal_id:
            fqn = (Fqn) args[1];
            lock_type = DataNode.LOCK_TYPE_WRITE;
            break;
         case MethodDeclarations.evictNodeMethodLocal_id:
            zeroLockTimeout = true;
            fqn = (Fqn) args[0];
            lock_type = DataNode.LOCK_TYPE_WRITE;
            break;
         case MethodDeclarations.getKeyValueMethodLocal_id:
         case MethodDeclarations.getNodeMethodLocal_id:
         case MethodDeclarations.getKeysMethodLocal_id:
         case MethodDeclarations.getChildrenNamesMethodLocal_id:
         case MethodDeclarations.releaseAllLocksMethodLocal_id:
         case MethodDeclarations.printMethodLocal_id:
            fqn = (Fqn) args[0];
            lock_type = DataNode.LOCK_TYPE_READ;
            break;
         case MethodDeclarations.lockMethodLocal_id:
            fqn = (Fqn) args[0];
            lock_type = ((Integer) args[1]).intValue();
            recursive = ((Boolean) args[2]).booleanValue();
            break;
         case MethodDeclarations.commitMethod_id:
            // commit propagated up from the tx interceptor
            commit(ctx.getGlobalTransaction());
            break;
         case MethodDeclarations.rollbackMethod_id:
            // rollback propagated up from the tx interceptor
            rollback(ctx.getGlobalTransaction());
            break;
         default:
            if (isOnePhaseCommitPrepareMehod(m))
            {
               // commit propagated up from the tx interceptor
               commit(ctx.getGlobalTransaction());
            }
            break;
      }

      // Lock the node (must be either read or write if we get here)
      // If no TX: add each acquired lock to the list of locks for this method (locks)
      // If TX: [merge code from TransactionInterceptor]: register with TxManager, on commit/rollback,
      // release the locks for the given TX
      if (fqn != null)
      {
         if (createIfNotExists)
         {
            do
            {
               lock(fqn, ctx.getGlobalTransaction(), lock_type, recursive, zeroLockTimeout ? 0 : lock_timeout, createIfNotExists, storeLockedNode, isRemoveData);
            }
            while(!cache.exists(fqn)); // keep trying until we have the lock (fixes concurrent remove())
            // terminates successfully, or with (Timeout)Exception
         }
         else
            lock(fqn, ctx.getGlobalTransaction(), lock_type, recursive, zeroLockTimeout ? 0 : lock_timeout, createIfNotExists, storeLockedNode, isRemoveData);
      }
      else
      {
         if (log.isTraceEnabled())
            log.trace("bypassed locking as method " + m.getName() + "() doesn't require locking");
      }
      if (m.getMethodId() == MethodDeclarations.lockMethodLocal_id)
         return null;

      Object o = super.invoke(m);

      // FIXME this should be done in UnlockInterceptor, but I didn't want
      // to add the removedNodes map to TreeCache
      if (storeLockedNode && ctx.getGlobalTransaction() == null)
      {
         // do a REAL remove here.
         // this is for NON TRANSACTIONAL calls
         cache.realRemove(fqn, true);
      }
      else if (m.getMethodId() == MethodDeclarations.commitMethod_id || isOnePhaseCommitPrepareMehod(m) || m.getMethodId() == MethodDeclarations.rollbackMethod_id)
      {
         // and this is for transactional ones
         cleanup(ctx.getGlobalTransaction());
      }

View Full Code Here

        txTable = cache.getTransactionTable();
    }

    public Object invoke(MethodCall call) throws Throwable
    {
        JBCMethodCall m = (JBCMethodCall) call;
        if (log.isTraceEnabled())
        {
            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)
        {
           // JBCACHE-1246 If we haven't previously registered a synchronization
           // for the current tx, remove it from the tx table, since we are about to
           // suspend it and thus won't remove it later via the synchronization.
           // If we don't do this, we leak the tx and gtx in txTable.
           // BES -- I'm using the transactions map here as a proxy for whether
           // the tx has had a synchronization registered. Not really ideal...
           if (transactions.get(ctx.getTransaction()) == null)
           {
              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())
                      {
View Full Code Here

        if (modifications != null)
        {
            for (Iterator it = modifications.iterator(); it.hasNext();)
            {
                JBCMethodCall method_call = (JBCMethodCall) it.next();
                try
                {
                   if (injectDataVersions && !MethodDeclarations.isDataGravitationMethod(method_call.getMethodId()))
                   {
                      Object[] origArgs = method_call.getArgs();
                      // there may be instances (e.g., data gravitation calls) where a data version is not passed in or not even relevant.
                      // make sure we are aware of this.
                      injectDataVersion(origArgs[origArgs.length - 1]);
                      // modify the call to the non-dataversioned counterpart since we've popped out the data version
                      Object[] args = new Object[origArgs.length - 1];
                      System.arraycopy(origArgs, 0, args, 0, args.length);

                      retval = super.invoke(MethodCallFactory.create(MethodDeclarations.getUnversionedMethod(method_call.getMethodId()), args));
                   }
                   else
                   {
                      retval = super.invoke(method_call);
                   }
View Full Code Here

TOP

Related Classes of org.jboss.cache.marshall.JBCMethodCall

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.