Package org.jboss.cache.marshall

Examples of org.jboss.cache.marshall.JBCMethodCall


        Object[] args = methodCall.getArgs();
        List modifications = (List) args[1];
        int num_mods = modifications != null ? modifications.size() : 0;

       // See JBCACHE-843 and docs/design/DataVersioning.txt
       JBCMethodCall toBroadcast = mapDataVersionedMethodCalls(methodCall, getTransactionWorkspace(gtx));

        // this method will return immediately if we're the only member (because
        // exclude_self=true)

        if (cache.getMembers() != null && cache.getMembers().size() > 1)
View Full Code Here


   {
      List newList = new ArrayList();
      Iterator origCalls = l.iterator();
      while (origCalls.hasNext())
      {
         JBCMethodCall origCall = (JBCMethodCall) origCalls.next();
         if (MethodDeclarations.isDataGravitationMethod(origCall.getMethodId()))
         {
            // no need to translate data gravitation calls.
            newList.add(origCall);
         }
         else
         {
            Object[] origArgs = origCall.getArgs();
            // get the data version associated with this orig call.

            // since these are all crud methods the Fqn is at arg subscript 1.
            Fqn fqn = (Fqn) origArgs[1];
            // now get a hold of the data version for this specific modification
            DataVersion versionToBroadcast = getVersionToBroadcast(w, fqn);

            // build up the new arguments list for the new call.  Identical to the original lis except that it has the
            // data version tacked on to the end.
            Object[] newArgs = new Object[origArgs.length + 1];
            for (int i=0; i<origArgs.length; i++) newArgs[i] = origArgs[i];
            newArgs[origArgs.length] = versionToBroadcast;

            // now create a new method call which contains this data version
            JBCMethodCall newCall = MethodCallFactory.create(MethodDeclarations.getVersionedMethod(origCall.getMethodId()), newArgs);

            // and add it to the new list.
            newList.add(newCall);
         }
      }
View Full Code Here

        if (cache.getMembers() != null && cache.getMembers().size() > 1)
        {
            try
            {
                broadcastTxs.remove(gtx);
                JBCMethodCall commit_method = MethodCallFactory.create(MethodDeclarations.commitMethod,
                                                          new Object[]{gtx});

                log.debug("running remote commit for " + gtx
                          + " and coord=" + cache.getLocalAddress());
View Full Code Here

        {
            // 1. Multicast rollback() to all other members (excluding myself)
            try
            {
                broadcastTxs.remove(gtx);
                JBCMethodCall rollback_method = MethodCallFactory.create(MethodDeclarations.rollbackMethod, new Object[]{gtx});

                log.debug("running remote rollback for " + gtx
                          + " and coord=" + cache.getLocalAddress());
                replicateCall( rollback_method, remoteCallSync );
View Full Code Here

        lockAcquisitionTimeout = cache.getLockAcquisitionTimeout();
    }

    public Object invoke(MethodCall call) throws Throwable
    {
        JBCMethodCall m = (JBCMethodCall) call;
        InvocationContext ctx = getInvocationContext();
        Object retval = null;
        Method meth = m.getMethod();

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

        // bail out if _lock() is being called on the tree cache... this should never be called with o/l enabled.
        if (m.getMethodId() == MethodDeclarations.lockMethodLocal_id)
        {
            log.warn("OptimisticLockingInterceptor intercepted a call to TreeCache._lock().  " +
                "This should NEVER be called if optimistic locking is used!!  "+
                "Not allowing this call to proceed further down the chain.");
            return retval;
        }

        if (ctx.getTransaction() != null)
        {
            GlobalTransaction gtx = ctx.getGlobalTransaction();

            if (gtx == null)
            {
                throw new Exception("failed to get global transaction");
            }
            //we are interested in the prepare/commit/rollback

            //methods we are interested in are prepare/commit
            //this is irrespective of whether we are local or remote
            switch (m.getMethodId())
            {
               case MethodDeclarations.optimisticPrepareMethod_id:
                  //try and acquire the locks - before passing on
                  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

   }


   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

   {
      List newList = new ArrayList();
      Iterator mi = modifications.iterator();
      while (mi.hasNext())
      {
         JBCMethodCall c = (JBCMethodCall) mi.next();
         Object[] oa = c.getArgs();
         Object[] na = new Object[oa.length + 1];
         System.out.println("*** " + oa.length);
         for (int i=0; i<oa.length; i++) na[i] = oa[i];
         na[oa.length] = new DefaultDataVersion();
         newList.add(MethodCallFactory.create(MethodDeclarations.getVersionedMethod(c.getMethodId()), na));
      }
      return newList;
   }
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();
        GlobalTransaction gtx = ctx.getGlobalTransaction();
        Object retval = null;
      
       // bypass for buddy group org metod calls.
       if (isBuddyGroupOrganisationMethod(m)) return super.invoke(m);


        if (tx == null)
            throw new CacheException("Not in a transaction");

        // Methods we are interested in are prepare/commit
        // They do not go further than this interceptor
        switch (m.getMethodId())
        {
           case MethodDeclarations.optimisticPrepareMethod_id:
              // should pass in a different prepare here
              validateNodes(gtx);
              break;
View Full Code Here

    * @see Region#getMethodCallQueue
    */
   public void _enqueueMethodCall(String subtree, MethodCall call)
           throws Throwable
   {
      JBCMethodCall jbcCall = (JBCMethodCall) call;
      Fqn fqn = Fqn.fromString(subtree);
      Region region = regionManager_.getRegion(fqn);
      // JBCACHE-1225 -- handle buddy region fqns
      if (region == null && BuddyManager.isBackupFqn(fqn))
      {
         // Strip out the buddy group portion
         fqn = fqn.getFqnChild(2, fqn.size());
         region = regionManager_.getRegion(fqn);
      }
      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.