Package org.jboss.cache

Examples of org.jboss.cache.GlobalTransaction


        SamplePojo pojo = new SamplePojo(21, "test");

        cache.put("/one/two", "key1", pojo);

        GlobalTransaction gtx = cache.getCurrentTransaction(tx);
        TransactionTable table = cache.getTransactionTable();
        OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
        assertNotNull(mgr.getTransaction());
        mgr.commit();

        //test local calls
        List calls = dummy.getAllCalled();
        assertEquals(MethodDeclarations.optimisticPrepareMethod, calls.get(0));
        assertEquals(MethodDeclarations.commitMethod, calls.get(1));

        assertNull(mgr.getTransaction());

        assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
        assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());


        GlobalTransaction remoteGtx = new GlobalTransaction();

        remoteGtx.setAddress(new Address()
        {
            public boolean isMulticastAddress()
            {

                return false;
            }

            public void readExternal(ObjectInput arg0)
            {
            }

            public void writeExternal(ObjectOutput arg0)
            {
            }

            public int compareTo(Object arg0)
            {

                return 0;
            }

            public int size()
            {

                return 0;
            }

            public void writeTo(DataOutputStream arg0)
            {
            }

            public void readFrom(DataInputStream arg0)
            {
            }
        });

//      hack the method call to make it have the remote gtx
        MethodCall meth = (MethodCall) entry.getModifications().get(0);

        meth.getArgs()[0] = remoteGtx;
        //call our remote method
        MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, new Object[]{remoteGtx, injectDataVersion(entry.getModifications()), null, remoteGtx.getAddress(), Boolean.FALSE});
        try
        {
            cache._replicate(prepareMethod);
        }
        catch (Throwable t)
View Full Code Here


        SamplePojo pojo = new SamplePojo(21, "test");

        cache.put("/one/two", "key1", pojo);

        GlobalTransaction gtx = cache.getCurrentTransaction(tx);
        TransactionTable table = cache.getTransactionTable();
        OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
        assertNotNull(mgr.getTransaction());
        mgr.commit();

        //test local calls
        List calls = dummy.getAllCalled();
        assertEquals(MethodDeclarations.optimisticPrepareMethod, calls.get(0));
        assertEquals(MethodDeclarations.commitMethod, calls.get(1));

        GlobalTransaction remoteGtx = new GlobalTransaction();

        remoteGtx.setAddress(new Address()
        {
            public boolean isMulticastAddress()
            {

                return false;
            }

            public void readExternal(ObjectInput arg0)
            {
            }

            public void writeExternal(ObjectOutput arg0)
            {
            }

            public int compareTo(Object arg0)
            {

                return 0;
            }

            public int size()
            {

                return 0;
            }

            public void writeTo(DataOutputStream arg0)
            {
            }

            public void readFrom(DataInputStream arg0)
            {
            }
        });

//      hack the method call to make it have the remote gtx
        MethodCall meth = (MethodCall) entry.getModifications().get(0);

        meth.getArgs()[0] = remoteGtx;
        //call our remote method
        MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, new Object[]{remoteGtx, injectDataVersion(entry.getModifications()), null, remoteGtx.getAddress(), Boolean.FALSE});
        try
        {
            cache._replicate(prepareMethod);
        }
        catch (Throwable t)
View Full Code Here

      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);
      }
View Full Code Here

    * transaction.
    * This is O(N) WRT to the number of modifications so far.
    */
   private boolean wasRemovedInTx(Fqn fqn)
   {
      GlobalTransaction t = getInvocationContext().getGlobalTransaction();
      if (t == null)
         return false;
      TransactionEntry entry = txTable.get(t);
      Iterator i = entry.getCacheLoaderModifications().iterator();
      while (i.hasNext())
View Full Code Here

            {
                throw new CacheException("failed extracting FQN from method " + m);
            }
            if (!cache.exists(fqn))
            {
                GlobalTransaction gtx = getInvocationContext().getGlobalTransaction();
                if (gtx != null)
                {
                    createNode(fqn, gtx, txTable);
                }
                else
View Full Code Here

        //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);

                  if (!gtx.isRemote() && getInvocationContext().isOriginLocal())
                  {
                      // replicate the prepare call.
                      retval = broadcastPrepare(m, gtx);
                      //if we have an exception then the remote methods failed
                      if (retval instanceof Throwable)
                      {
                          throw (Throwable) retval;
                      }
                  }
                  break;
               case MethodDeclarations.commitMethod_id:
                  //lets broadcast the commit first
                  Throwable temp = null;
                  if (!gtx.isRemote() && getInvocationContext().isOriginLocal() && broadcastTxs.containsKey(gtx))
                  {
                      //we dont do anything
                      try
                      {
                          broadcastCommit(gtx);
                      }
                      catch (Throwable t)
                      {
                          log.error(" a problem occurred with remote commit", t);
                          temp = t;
                      }
                  }

                  retval = super.invoke(m);
                  if (temp != null)
                  {
                      throw temp;
                  }
                  break;
               case MethodDeclarations.rollbackMethod_id:
                  //    lets broadcast the rollback first
                  Throwable temp2 = null;
                  if (!gtx.isRemote() && getInvocationContext().isOriginLocal() && broadcastTxs.containsKey(gtx))
                  {
                      //we dont do anything
                      try
                      {
                          broadcastRollback(gtx);
View Full Code Here

            return retval;
        }

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

            if (gtx == null)
            {
                throw new Exception("failed to get global transaction");
            }
View Full Code Here

        return MethodCallFactory.create(MethodDeclarations.lookupMethod(methodId), args);
    }

    private GlobalTransaction unmarshallGlobalTransaction(ObjectInputStream in, Map refMap) throws Exception
    {
        GlobalTransaction gtx = new GlobalTransaction();
        long id = in.readLong();
        Object address = unmarshallObject(in, refMap);
        gtx.setId(id);
        gtx.setAddress((Address) address);
        return gtx;
    }
View Full Code Here

      if (isBuddyGroupOrganisationMethod(m)) return super.invoke(m);


      Object result = null;

      GlobalTransaction gtx = ctx.getGlobalTransaction();

      TransactionWorkspace workspace = getTransactionWorkspace(gtx);

      if (MethodDeclarations.isCrudMethod(meth))
      {
View Full Code Here

    private MethodCall attachGlobalTransaction(Transaction tx, MethodCall m) throws Exception
    {
        if (log.isDebugEnabled()) log.debug(" local transaction exists - registering global tx if not present for " + Thread.currentThread());
        if (log.isTraceEnabled())
        {
            GlobalTransaction tempGtx = txTable.get(tx);
            log.trace("Associated gtx in txTable is " + tempGtx);
        }

        // register a sync handler for this tx - only if the gtx is not remotely initiated.
        GlobalTransaction gtx = registerTransaction(tx);
        if (gtx != null)
        {
            m = replaceGtx(m, gtx);
        }
        else
View Full Code Here

TOP

Related Classes of org.jboss.cache.GlobalTransaction

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.