Package org.jboss.cache.marshall

Examples of org.jboss.cache.marshall.JBCMethodCall


   }

   private void processQueuedMethodCalls(List queue) throws Throwable
   {
      Map gtxMap = new HashMap();
      JBCMethodCall call = null;
      JBCMethodCall wrapped = null;
      for (Iterator iter = queue.iterator(); iter.hasNext();)
      {
         call = (JBCMethodCall) iter.next();
         boolean forgive = false;
         if (call.getMethodId() == MethodDeclarations.replicateMethod_id)
         {
            Object[] args = call.getArgs();
            wrapped = (JBCMethodCall) args[0];
            switch (wrapped.getMethodId())
            {
               case MethodDeclarations.prepareMethod_id:
                  args = wrapped.getArgs();
                  gtxMap.put(args[0], NULL);
                  break;
               case MethodDeclarations.commitMethod_id:
               case MethodDeclarations.rollbackMethod_id:
                  args = wrapped.getArgs();
                  // If we didn't see the prepare earlier, we'll forgive
                  // any error when we invoke the commit/rollback
                  // TODO maybe just skip the commit/rollback?
//                  forgive = (gtxMap.remove(args[0]) == null);
                  if (gtxMap.remove(args[0]) == null)
View Full Code Here


    * 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

      super.setCache(cache);
   }

   public Object invoke(MethodCall call) throws Throwable
   {
      JBCMethodCall m = (JBCMethodCall) call;
      InvocationContext ctx = getInvocationContext();
      Transaction tx = ctx.getTransaction();
      Method meth = m.getMethod();
      Object[] args = m.getArgs();

      // bypass for buddy group org metod calls.
      if (isBuddyGroupOrganisationMethod(m)) return super.invoke(m);


      Object result = null;

      GlobalTransaction gtx = ctx.getGlobalTransaction();

      TransactionWorkspace workspace = getTransactionWorkspace(gtx);

      if (MethodDeclarations.isCrudMethod(meth))
      {
         if (tx == null || !isValid(tx))
         {
            throw new CacheException("Must be in a valid transaction " + m);
         }

         WorkspaceNode workspaceNode = getOrCreateWorkspaceNode(getFqn(args), workspace, true);
         if (workspaceNode == null && m.getMethodId() == MethodDeclarations.dataGravitationCleanupMethod_id)
         {
            workspaceNode = getOrCreateWorkspaceNode(getBackupFqn(args), workspace, true);
         }


         if (workspaceNode != null)
         {
            // use explicit versioning
            if (ctx.getOptionOverrides() != null && ctx.getOptionOverrides().getDataVersion() != null)
            {
               workspace.setVersioningImplicit(false);
               DataVersion version = ctx.getOptionOverrides().getDataVersion();

               workspaceNode.setVersion(version);
               if (log.isTraceEnabled()) log.trace("Setting versioning for node " + workspaceNode.getFqn() + " to explicit");
               workspaceNode.setVersioningImplicit(false);
            }
            else
            {
               if (log.isTraceEnabled()) log.trace("Setting versioning for node " + workspaceNode.getFqn() + " to implicit");
               workspaceNode.setVersioningImplicit(true);
            }
         }
         else
         {
            // "fail-more-silently" patch thanks to Owen Taylor - JBCACHE-767
            if ((ctx.getOptionOverrides() == null || !ctx.getOptionOverrides().isFailSilently()) && MethodDeclarations.isOptimisticPutMethod(meth))
               throw new CacheException("Unable to set node version for " + getFqn(args) + ", node is null.");
            else
            {
               log.trace("Workspace node is null.  Perhaps it has been deleted?");
               return null;
            }
         }

         switch (m.getMethodId())
         {
            case MethodDeclarations.putDataMethodLocal_id:
               Boolean erase = (Boolean) args[3];
               putDataMap(args, erase.booleanValue(), workspace, workspaceNode);
               break;
            case MethodDeclarations.putDataEraseMethodLocal_id:
               putDataMap(args, true, workspace, workspaceNode);
               break;
            case MethodDeclarations.putKeyValMethodLocal_id:
               result = putDataKeyValue(args, workspace, workspaceNode);
               break;
            case MethodDeclarations.removeNodeMethodLocal_id:
               removeNode(workspace, workspaceNode);
               break;
            case MethodDeclarations.removeKeyMethodLocal_id:
               result = removeKey(args, workspace, workspaceNode);
               break;
            case MethodDeclarations.removeDataMethodLocal_id:
               removeData(workspace, workspaceNode);
               break;
            case MethodDeclarations.dataGravitationCleanupMethod_id:
               result = super.invoke(m);
            default:
               if (log.isInfoEnabled()) log.info("Cannot Handle Method " + m);
               break;
         }

         Option opt = ctx.getOptionOverrides();
         if (opt == null || !opt.isCacheModeLocal())
         {
            txTable.addModification(gtx, m);
            if (log.isDebugEnabled()) log.debug("Adding Method " + m + " to modification list");
         }
         if (cache.getCacheLoaderManager() != null) txTable.addCacheLoaderModification(gtx, m);
      }
      else
      {
         switch (m.getMethodId())
         {
            case MethodDeclarations.getKeyValueMethodLocal_id:
               result = getValueForKey(args, workspace);
               break;
            case MethodDeclarations.getKeysMethodLocal_id:
View Full Code Here

    * @return
    * @throws Throwable
    */
   public Object invoke(MethodCall call) throws Throwable
   {
      JBCMethodCall m = (JBCMethodCall) call;
      Fqn fqn = null; // if set, load the data
      Method meth = m.getMethod();
      Object[] args = m.getArgs();
      boolean acquireLock = false; // do we need to acquire a lock if we load this node from cloader?
      Map nodeData = null;
      boolean initNode = false; // keep uninitialized
      Object key = null;
      InvocationContext ctx = getInvocationContext();
      TransactionEntry entry = null;
      GlobalTransaction gtx = null;
      if ((gtx = ctx.getGlobalTransaction()) != null)
      {
         entry = txTable.get(gtx);
      }

      if (log.isTraceEnabled())
         log.trace("invoke " + m);
      switch (m.getMethodId())
      {
         case MethodDeclarations.putDataEraseMethodLocal_id:
         case MethodDeclarations.putDataMethodLocal_id:
            fqn = (Fqn) args[1];
            initNode = true;
            break;
         case MethodDeclarations.putKeyValMethodLocal_id:
            fqn = (Fqn) args[1];
            if (useCacheStore)
               initNode = true;
            else
               acquireLock = true;
            break;
         case MethodDeclarations.addChildMethodLocal_id:
            fqn = (Fqn) args[1];
            break;
         case MethodDeclarations.getKeyValueMethodLocal_id:
            fqn = (Fqn) args[0];
            key = args[1];
            acquireLock = true;
            break;
         case MethodDeclarations.getNodeMethodLocal_id:
         case MethodDeclarations.getKeysMethodLocal_id:
         case MethodDeclarations.getChildrenNamesMethodLocal_id:
         case MethodDeclarations.releaseAllLocksMethodLocal_id:
         case MethodDeclarations.printMethodLocal_id:
            fqn = (Fqn) args[0];
            acquireLock = true;
            break;
         case MethodDeclarations.rollbackMethod_id:
            // clean up nodesCreated map
            cleanupNodesCreated(entry);
            break;
         default:
            if (!useCacheStore)
            {
               if (m.getMethodId() == MethodDeclarations.removeKeyMethodLocal_id)
               {
                  fqn = (Fqn) args[1];
               }
               else if (m.getMethodId() == MethodDeclarations.removeDataMethodLocal_id)
               {
                  fqn = (Fqn) args[1];
                  initNode = true;
               }
            }
            break;
      }

      /* On the way in: load elements into cache from the CacheLoader if not yet in the cache. We need to synchronize
      this so only 1 thread attempts to load a given element */

      if (fqn != null)
      {

         DataNode n = cache.peek(fqn);
         boolean mustLoad = mustLoad(n, key);
         if (log.isTraceEnabled())
            log.trace("load element " + fqn + " mustLoad=" + mustLoad);
         if (mustLoad)
         {
            if (initNode)
            {
               n = createTempNode(fqn, entry);
            }
            // Only attempt to acquire this lock if we need to - i.e., if
            // the lock hasn't already been acquired by the Lock
            // interceptor.  CRUD methods (put, remove) would have acquired
            // this lock - even if the node is not in memory and needs to be
            // loaded.  Non-CRUD methods (put) would NOT have acquired this
            // lock so if we are to load the node from cache loader, we need
            // to acquire a write lock here.  as a 'catch-all', DO NOT
            // attempt to acquire a lock here *anyway*, even for CRUD
            // methods - this leads to a deadlock when you have threads
            // simultaneously trying to create a node.  See
            // org.jboss.cache.loader.deadlock.ConcurrentCreationDeadlockTest
            // - Manik Surtani (21 March 2006)
            if (acquireLock)
               lock(fqn, DataNode.LOCK_TYPE_WRITE, false); // not recursive

            if (!initNode && !wasRemovedInTx(fqn))
            {
               n = loadNode(fqn, n, entry);
            }
         }

         // The complete list of children aren't known without loading them
         if (m.getMethodId() == MethodDeclarations.getChildrenNamesMethodLocal_id)
         {
            loadChildren(fqn, n);
         }

      }
View Full Code Here

         return false;
      TransactionEntry entry = txTable.get(t);
      Iterator i = entry.getCacheLoaderModifications().iterator();
      while (i.hasNext())
      {
         JBCMethodCall m = (JBCMethodCall) i.next();
         if (m.getMethodId() == MethodDeclarations.removeNodeMethodLocal_id
                 && fqn.isChildOrEquals((Fqn) m.getArgs()[1]))
            return true;
      }
      return false;
   }
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)
      {
         long timeout = zeroLockTimeout ? 0 : lock_acquisition_timeout;
         // make sure we can bail out of this loop
         long cutoffTime = System.currentTimeMillis() + timeout;
         boolean firstTry = true;
         if (createIfNotExists)
         {
            do
            {
               if (!firstTry && System.currentTimeMillis() > cutoffTime)
               {
                  throw new TimeoutException("Unable to acquire lock on Fqn " + fqn + " after " + timeout + " millis");
               }
               lock(fqn, ctx.getGlobalTransaction(), lock_type, recursive, zeroLockTimeout ? 0 : lock_timeout, createIfNotExists, storeLockedNode, isRemoveData);
               firstTry = false;
            }
            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)
           {
              // 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())
                      {
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

    * @see Region#getMethodCallQueue
    */
   public void _enqueueMethodCall(String subtree, MethodCall call)
           throws Throwable
   {
      JBCMethodCall jbcCall = (JBCMethodCall) call;
      Region region = regionManager_.getRegion(subtree);
      if (region == null)
         throw new IllegalStateException("No region found for " + subtree);

      List queue = region.getMethodCallQueue();
      synchronized (queue)
      {
         // Confirm we're not active yet; if we are just invoke the method
         switch (region.getStatus())
         {
            case(Region.STATUS_ACTIVE):
               if (log.isTraceEnabled())
                  log.trace("_enqueueMethodCall(): Invoking " + call.getName() +
                          " on subtree " + subtree);
               call.invoke(this);
               break;

            case(Region.STATUS_QUEUEING):

               // Don't bother queueing a getState call

               if (jbcCall.getMethodId() == MethodDeclarations.replicateMethod_id)
               {
                  JBCMethodCall mc = (JBCMethodCall) call.getArgs()[0];
                  if (mc.getMethodId() == MethodDeclarations.getPartialStateMethod_id)
                     return;
               }
               if (log.isTraceEnabled())
                  log.trace("_enqueueMethodCall(): Enqueuing " + call.getName() +
                          " " + call.getArgs() + " on subtree " + subtree);
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.