Package org.jboss.cache.marshall

Examples of org.jboss.cache.marshall.JBCMethodCall


    * @param call
    * @return
    * @throws Throwable
    */
   public Object invoke(MethodCall call) throws Throwable {
      JBCMethodCall m = (JBCMethodCall) call;
      Fqn          fqn=null;
      Method       meth=m.getMethod();
      Object[]     args=m.getArgs();
      Object       retval=null;

      // First call the parent class to load the node
      retval = super.invoke(m);
     
      // is this a node removal operation?
      boolean nodeRemoved = false;
     
      // Could be TRANSACTIONAL. If so, we register for TX completion (if we haven't done so yet)
      if(tx_mgr != null && tx_mgr.getTransaction() != null) {
         GlobalTransaction gtx = getInvocationContext().getGlobalTransaction();
         switch (m.getMethodId())
         {
            case MethodDeclarations.commitMethod_id:
               if (hasModifications(args)) {
                  loader.commit(gtx);
                  if (cache.getUseInterceptorMbeans()&& statsEnabled) {
                     Integer acts = (Integer)m_txActivations.get(gtx);
                     if (acts != null)
                        m_activations = m_activations + acts.intValue();
                     m_txActivations.remove(gtx);
                  }
               }
               break;
            case MethodDeclarations.rollbackMethod_id:
               if (hasModifications(args)) {
                  loader.rollback(gtx);
                  if (cache.getUseInterceptorMbeans()&& statsEnabled)
                     m_txActivations.remove(gtx);
               }
               break;
            case MethodDeclarations.optimisticPrepareMethod_id:
            case MethodDeclarations.prepareMethod_id:
               prepareCacheLoader(gtx);
               break;
         }
      }
     
      // if we're here then it's not transactional

      // CacheLoaderInterceptor normally doesn't load the node
      // since CacheStoreInterceptor.put() returns the old value
      switch (m.getMethodId())
      {
         case MethodDeclarations.putDataMethodLocal_id:
         case MethodDeclarations.putDataEraseMethodLocal_id:
         case MethodDeclarations.putKeyValMethodLocal_id:
            fqn=(Fqn)args[1];
View Full Code Here


      modifications=entry.getCacheLoaderModifications();
      if(modifications.size() == 0)
         return;
      List cache_loader_modifications=new ArrayList();
      for(Iterator it=modifications.iterator(); it.hasNext();) {
         JBCMethodCall methodCall=(JBCMethodCall)it.next();
         Method method=methodCall.getMethod();
         Object[] args;
         if(method == null)
            throw new Exception("method call has no method: " + methodCall);
         args=methodCall.getArgs();
         switch (methodCall.getMethodId())
         {
            case MethodDeclarations.removeNodeMethodLocal_id:
               // just remove it from loader, don't trigger activation processing
               Modification mod=new Modification(Modification.REMOVE_NODE, (Fqn)args[1]);
               cache_loader_modifications.add(mod);
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);
         if (log.isTraceEnabled())
            log.trace("load element " + fqn + " mustLoad=" + mustLoad(n, key));
         if (mustLoad(n, key))
         {
            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

        txTable=cache.getTransactionTable();
    }

    public Object invoke(MethodCall call) throws Throwable
    {
        JBCMethodCall m = (JBCMethodCall) call;
        InvocationContext ctx = getInvocationContext();
        Option optionOverride = ctx.getOptionOverrides();
        if (optionOverride != null && optionOverride.isCacheModeLocal() && ctx.getTransaction() == null)
        {
            // skip replication!!
            return super.invoke(m);
        }
       
        Transaction tx = ctx.getTransaction();
        Object retval = super.invoke(m);
        Method meth = m.getMethod();

        if (log.isTraceEnabled()) log.trace("(" + cache.getLocalAddress() + ") method call " + m );

        // now see if this is a CRUD method:
        if (MethodDeclarations.isCrudMethod(meth))
        {
            if (m.getMethodId() != MethodDeclarations.putFailFastKeyValueMethodLocal_id)
            {
               if (log.isDebugEnabled()) log.debug("Is a CRUD method");
               Fqn fqn = findFqn( m.getArgs() );
               if (fqn != null)
               {
                   // could be potentially TRANSACTIONAL.  Ignore if it is, until we see a prepare().
                   if (tx == null || !isValid(tx))
                   {
                       // the no-tx case:
                       //replicate an evict call.
                       invalidateAcrossCluster( fqn, null );
                   }
               }
            }
            else
            {
               log.debug("Encountered a putFailFast() - is a no op.");
            }
        }
        else
        {
            // not a CRUD method - lets see if it is a tx lifecycle method.
            if (tx != null && isValid(tx))
            {
                // lets see if we are in the prepare phase (as this is the only time we actually do anything)
               switch (m.getMethodId())
               {
                  case MethodDeclarations.prepareMethod_id:
                  case MethodDeclarations.optimisticPrepareMethod_id:
                     log.debug("Entering InvalidationInterceptor's prepare phase");
                     // fetch the modifications before the transaction is committed (and thus removed from the txTable)
View Full Code Here

        // increment invalidations counter if statistics maintained
        if (cache.getUseInterceptorMbeans()&& statsEnabled)
            m_invalidations++;
         
        // only propagate version details if we're using explicit versioning.
        JBCMethodCall call = workspace != null && !workspace.isVersioningImplicit() ?
            MethodCallFactory.create(MethodDeclarations.evictVersionedNodeMethodLocal, new Object[]{fqn, workspace.getNode(fqn).getVersion()}) :
            MethodCallFactory.create(MethodDeclarations.evictNodeMethodLocal, new Object[]{fqn});

        if (log.isDebugEnabled()) log.debug("Cache ["+cache.getLocalAddress()+"] replicating " + call);
        // voila, invalidated!
View Full Code Here

      modifications=entry.getCacheLoaderModifications();
      if(modifications.size() == 0)
         return;
      List cache_loader_modifications=new ArrayList();
      for(Iterator it=modifications.iterator(); it.hasNext();) {
         JBCMethodCall methodCall=(JBCMethodCall) it.next();
         Modification mod=convertMethodCallToModification(methodCall);
         cache_loader_modifications.add(mod);
         if (cache.getUseInterceptorMbeans()&& statsEnabled) {
            if ( (mod.getType() == Modification.PUT_DATA) ||
                 (mod.getType() == Modification.PUT_DATA_ERASE) ||
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)
        {
            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

        super.setCache(cache);
    }

    public Object invoke(MethodCall call) throws Throwable
    {
        JBCMethodCall m = (JBCMethodCall) call;
        InvocationContext ctx = getInvocationContext();
        Option optionOverride = ctx.getOptionOverrides();
       // bypass for buddy group org metod calls.
       if (isBuddyGroupOrganisationMethod(m)) return super.invoke(m);
      
        if (optionOverride != null && optionOverride.isCacheModeLocal() && ctx.getTransaction() == null)
        {
            // skip replication!!
            return super.invoke(m);
        }
       
        Object retval;

        //we need a transaction to be present in order to do this
        if (ctx.getTransaction() != null)
        {

            // get the current gtx
            GlobalTransaction gtx = ctx.getGlobalTransaction();
            if (gtx == null)
            {
                throw new CacheException("failed to get global transaction");
            }
            log.debug(" received method " + m);

            // on a  local prepare we first run the prepare -
            //if this works broadcast it

            switch (m.getMethodId())
            {
               case MethodDeclarations.optimisticPrepareMethod_id:
                  // pass up the chain.
                  retval = super.invoke(m);
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.