Package org.jboss.cache.marshall

Examples of org.jboss.cache.marshall.MethodCall


      /*
      MethodCall call = workspace != null && !workspace.isVersioningImplicit() ?
              MethodCallFactory.create(MethodDeclarations.evictVersionedNodeMethodLocal, fqn, workspace.getNode(fqn).getVersion()) :
              MethodCallFactory.create(MethodDeclarations.evictNodeMethodLocal, fqn);
              */
      MethodCall call = MethodCallFactory.create(MethodDeclarations.invalidateMethodLocal_id, fqn, getNodeVersion(workspace, fqn));

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


         }

         long syncReplTimeout = o.getSyncReplTimeout();
         if (syncReplTimeout < 0) syncReplTimeout = configuration.getSyncReplTimeout();

         MethodCall toCall = wrapMethodCallInReplicateMethod ? toCall = MethodCallFactory.create(MethodDeclarations.replicateMethod_id, call) : call;

         List rsps = rpcManager.callRemoteMethods(callRecipients,
               toCall,
               sync, // is synchronised?
               true, // ignore self?
View Full Code Here

public class MarshalledValueInterceptor extends Interceptor
{
   @Override
   public Object invoke(InvocationContext context) throws Throwable
   {
      MethodCall call = context.getMethodCall();
      boolean isAPICall = false;
      int id = call.getMethodId();
      Set<MarshalledValue> marshalledValues = null;

      // needs to work for *all* API method calls.
      if (MethodDeclarations.isAPIMethodCall(id) && id != MethodDeclarations.getNodeMethodLocal_id && id != MethodDeclarations.removeNodeMethodLocal_id)
      {
         marshalledValues = new HashSet<MarshalledValue>();
         isAPICall = true;
         if (trace) log.trace("Is API method; wrapping any args that need to be wrapped");
         // check arguments for any user-defined objects that may need to be wrapped.
         Object[] args = call.getArgs();
         Object[] replacementArgs = new Object[args.length];
         int counter = -1;

         for (Object o : args)
         {
            counter++;
            if (o == null || MarshalledValueHelper.isTypeExcluded(o.getClass()) || isInternalCollection(counter, id))
            {
               replacementArgs[counter] = o;
            }
            else if (needToReplaceMap(counter, id))
            {
               if (trace) log.trace("Wrapping map contents of argument " + counter);
               replacementArgs[counter] = wrapMap((Map) o, marshalledValues, context);
            }
            else
            {
               if (trace) log.trace("Wrapping argument " + counter + " which contains type " + o.getClass());
               replacementArgs[counter] = createAndAddMarshalledValue(o, marshalledValues, context);
            }
         }
         call.setArgs(replacementArgs);
      }

      Object retVal = nextInterceptor(context);

      if (isAPICall)
      {
         if (trace) log.trace("Compacting MarshalledValues created");
         for (MarshalledValue mv : marshalledValues) mv.compact(false, false);

         if (retVal instanceof MarshalledValue)
         {
            if (trace) log.trace("Return value is a MarshalledValue.  Unwrapping.");
            retVal = ((MarshalledValue) retVal).get();
         }
         else if (retVal instanceof Map && call.getMethodId() == MethodDeclarations.getDataMapMethodLocal_id)
         {
            if (trace) log.trace("Return value is a Map and we're retrieving data.  Wrapping as a MarshalledValueMap.");
            Map retValMap = (Map) retVal;
            if (!retValMap.isEmpty()) retVal = new MarshalledValueMap(retValMap);
         }
View Full Code Here

   }

   @Override
   public Object invoke(InvocationContext ctx) throws Throwable
   {
      MethodCall m = ctx.getMethodCall();
      Object[] args = m.getArgs();

      Object result = null;

      if (MethodDeclarations.isCrudMethod(m.getMethodId()))
      {
         GlobalTransaction gtx = getGlobalTransaction(ctx);
         TransactionWorkspace workspace = getTransactionWorkspace(gtx);
         Fqn fqn = getFqn(args, m.getMethodId());
         WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, fqn, workspace, MethodDeclarations.removeNodeMethodLocal_id != m.getMethodId(), true);

         // in the case of a data gravitation cleanup, if the primary Fqn does not exist the backup one may.
         if (workspaceNode == null && m.getMethodId() == MethodDeclarations.dataGravitationCleanupMethod_id)
         {
            workspaceNode = fetchWorkspaceNode(ctx, getBackupFqn(args), workspace, true, true);
         }

         if (workspaceNode != null)
         {
            // use explicit versioning
            if (ctx.getOptionOverrides() != null && ctx.getOptionOverrides().getDataVersion() != null)
            {
               // if the method call is a move() then barf.  Note that remove calls will set data versions explicitly, regardless.
               if (ctx.isOriginLocal() && m.getMethodId() == MethodDeclarations.moveMethodLocal_id)
                  throw new CacheException("Setting a data version while performing a move() is not supported!!");

               workspace.setVersioningImplicit(false);
               DataVersion version = ctx.getOptionOverrides().getDataVersion();

               workspaceNode.setVersion(version);
               if (trace) log.trace("Setting versioning for node " + workspaceNode.getFqn() + " to explicit");

               workspaceNode.setVersioningImplicit(false);
            }
            else
            {
               if (trace) 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.isPutMethod(m.getMethodId()))
            {
               throw new CacheException("Unable to set node version for " + fqn + ", node is null.");
            }
         }

         switch (m.getMethodId())
         {
            case MethodDeclarations.moveMethodLocal_id:
               Fqn parentFqn = (Fqn) args[1];
               moveNodeAndNotify(parentFqn, workspaceNode, workspace, ctx);
               break;
            case MethodDeclarations.putDataMethodLocal_id:
               putDataMapAndNotify((Map<Object, Object>) args[2], false, workspace, workspaceNode, ctx);
               break;
            case MethodDeclarations.putDataEraseMethodLocal_id:
               putDataMapAndNotify((Map<Object, Object>) args[2], (Boolean) args[args.length - 1], workspace, workspaceNode, ctx);
               break;
            case MethodDeclarations.putKeyValMethodLocal_id:
            case MethodDeclarations.putForExternalReadMethodLocal_id:
               Object key = args[2];
               Object value = args[3];
               result = putDataKeyValueAndNotify(key, value, workspace, workspaceNode, ctx);
               break;
            case MethodDeclarations.removeNodeMethodLocal_id:
               result = removeNode(workspace, workspaceNode, true, ctx);
               break;
            case MethodDeclarations.removeKeyMethodLocal_id:
               Object removeKey = args[2];
               result = removeKeyAndNotify(removeKey, workspace, workspaceNode, ctx);
               break;
            case MethodDeclarations.removeDataMethodLocal_id:
               removeDataAndNotify(workspace, workspaceNode, ctx);
               break;
            case MethodDeclarations.dataGravitationCleanupMethod_id:
               result = nextInterceptor(ctx);
            default:
               if (log.isWarnEnabled()) log.warn("Cannot handle CRUD method " + m);
               break;
         }

         addToModificationList(gtx, m, ctx);
      }
      else
      {
         switch (m.getMethodId())
         {
            case MethodDeclarations.getKeyValueMethodLocal_id:
               result = getValueForKeyAndNotify(args, getTransactionWorkspace(getGlobalTransaction(ctx)), ctx);
               break;
            case MethodDeclarations.getKeysMethodLocal_id:
View Full Code Here

   protected void lock(Fqn fqn, NodeLock.LockType lock_type, boolean recursive) throws Throwable
   {

      if (configuration.isNodeLockingOptimistic()) return;

      MethodCall m = MethodCallFactory.create(MethodDeclarations.lockMethodLocal_id,
            fqn, lock_type, recursive);

      // hacky
      cache.getInterceptorChain().get(0).invoke(InvocationContext.fromMethodCall(m));
//      nextInterceptor(m);
View Full Code Here

               if (notify) cache.getNotifier().notifyNodeCreated(child_fqn, true, ctx);
               child = newChild;
               children.put(child_name, child);
               if (gtx != null)
               {
                  MethodCall undo_op = MethodCallFactory.create(MethodDeclarations.removeNodeMethodLocal_id,
                        gtx, child_fqn, false, false);
                  cacheImpl.addUndoOperation(gtx, undo_op);
                  // add the node name to the list maintained for the current tx
                  // (needed for abort/rollback of transaction)
                  // cache.addNode(gtx, child.getFqn());
View Full Code Here

      assertEquals(1, entry.getModifications().size());
      assertTrue(!cache.exists("/one/two"));
      assertEquals(null, dummy.getCalled());

      //now let us do a prepare
      MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod_id, gtx, entry.getModifications(), null, gtx.getAddress(), Boolean.FALSE);
      TestingUtil.getRemoteDelegate(cache)._replicate(prepareMethod);


      assertEquals(3, workspace.getNodes().size());
      assertNotNull(workspace.getNode(Fqn.fromString("/one/two")));
      assertEquals(pojo, workspace.getNode(Fqn.fromString("/one/two")).get("key1"));
      assertEquals(1, workspace.getNode(Fqn.fromString("/one/two")).getMergedData().size());
      assertTrue(entry.getLocks().isEmpty());
      assertEquals(1, entry.getModifications().size());
      assertTrue(!cache.exists("/one/two"));
      assertEquals(prepareMethod.getMethod(), dummy.getCalled());


      mgr.commit();
   }
View Full Code Here

      assertEquals(null, dummy.getCalled());

      //lets change one of the underlying version numbers
      workspace.getNode(Fqn.fromString("/one/two")).getNode().setVersion(new DefaultDataVersion(2));
      //now let us do a prepare
      MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod_id, gtx, entry.getModifications(), null, gtx.getAddress(), Boolean.FALSE);
      try
      {
         TestingUtil.getRemoteDelegate(cache)._replicate(prepareMethod);
         fail();
      }
View Full Code Here

      assertTrue(!cache.exists("/one/two"));
      assertEquals(null, dummy.getCalled());

      //lets change one of the underlying version numbers
      //now let us do a prepare
      MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod_id, gtx, entry.getModifications(), null, gtx.getAddress(), Boolean.FALSE);
      try
      {
         TestingUtil.getRemoteDelegate(cache)._replicate(prepareMethod);
         fail();
      }
      catch (Throwable t)
      {
         assertTrue(true);
      }

      MethodCall commitMethod = MethodCallFactory.create(MethodDeclarations.commitMethod_id, gtx);
      TestingUtil.getRemoteDelegate(cache)._replicate(commitMethod);


      assertEquals(3, workspace.getNodes().size());
      assertNotNull(workspace.getNode(Fqn.fromString("/one/two")));
      assertEquals(pojo, workspace.getNode(Fqn.fromString("/one/two")).get("key1"));
      assertEquals(1, workspace.getNode(Fqn.fromString("/one/two")).getMergedData().size());
      assertTrue(entry.getLocks().isEmpty());
      assertEquals(1, entry.getModifications().size());


      assertEquals(commitMethod.getMethod(), dummy.getCalled());
      NodeSPI<Object, Object> node = workspace.getNode(Fqn.ROOT).getNode();
      //assert we can navigate

      assertNotNull(node);
      node = (NodeSPI<Object, Object>) node.getChild("one");
View Full Code Here

      assertTrue(!cache.exists("/one/two"));
      assertEquals(null, dummy.getCalled());

      //lets change one of the underlying version numbers
      //now let us do a prepare
      MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod_id, gtx, entry.getModifications(), null, gtx.getAddress(), Boolean.FALSE);
      try
      {
         TestingUtil.getRemoteDelegate(cache)._replicate(prepareMethod);
         fail();
      }
      catch (Throwable t)
      {
         assertTrue(true);
      }


      MethodCall commitMethod = MethodCallFactory.create(MethodDeclarations.commitMethod_id, gtx);
      TestingUtil.getRemoteDelegate(cache)._replicate(commitMethod);


      assertEquals(3, workspace.getNodes().size());
      assertNotNull(workspace.getNode(Fqn.fromString("/one/two")));
      assertEquals(pojo, workspace.getNode(Fqn.fromString("/one/two")).get("key1"));
      assertEquals(1, workspace.getNode(Fqn.fromString("/one/two")).getMergedData().size());
      assertTrue(entry.getLocks().isEmpty());
      assertEquals(1, entry.getModifications().size());


      assertEquals(commitMethod.getMethod(), dummy.getCalled());
      NodeSPI<Object, Object> node = workspace.getNode(Fqn.fromString("/")).getNode();
      //assert we can navigate

      assertNotNull(node);
      node = (NodeSPI<Object, Object>) node.getChild("one");
View Full Code Here

TOP

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

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.