Package javax.transaction

Examples of javax.transaction.Synchronization


      GlobalTransaction gtx = cache.getTransactionTable().get(cache.getTransactionManager().getTransaction());
      OrderedSynchronizationHandler osh = cache.getTransactionTable().get(gtx).getOrderedSynchronizationHandler();

//      OrderedSynchronizationHandler.getInstance(cache.getTransactionManager().getTransaction()).registerAtTail(
      osh.registerAtTail(
            new Synchronization()
            {

               public void beforeCompletion()
               {
                  // this will be called after the cache's prepare() phase.  Restart the cache server.
View Full Code Here


      if (enlisted != null)
      {
         int i = 0;
         while (i < enlisted.size())
         {
            Synchronization synch = (Synchronization) enlisted.get(i);
            invokeBefore(synch);
            ++i;
         }
      }
     
View Full Code Here

      if (enlisted != null)
      {
         int i = 0;
         while (i < enlisted.size())
         {
            Synchronization synch = (Synchronization) enlisted.get(i);
            invokeAfter(synch, status);
            ++i;
         }
      }
     
View Full Code Here

      Transaction tx = (Transaction)transactions.get(id);
      if (tx == null)
      {
         throw new IllegalStateException("Tx not found: " + id);
      }
      Synchronization sync = new Synchronization()
      {
         public void beforeCompletion()
         {
            log.info(tid() + " beforeCompletion() called");
         }
View Full Code Here

           
            // Synchronization.beforeCompletion
            Iterator syncIterator = synchronization.iterator();
            while (syncIterator.hasNext())
            {
                Synchronization sync = (Synchronization) syncIterator.next();
                sync.beforeCompletion();
            }
           
            List failures = null;
            boolean failed = false;
   
            Iterator branchKeys = branches.keySet().iterator();
   
            if (enlistedResources.size() == 1)
            {
   
                // If we have only one resource, we dont ask to prepare, and we go with one phase commit
                status = Status.STATUS_COMMITTING;
                while (branchKeys.hasNext())
                {
                    Object key = branchKeys.next();
                    XAResource resourceManager = (XAResource) branches.get(key);
                    try
                    {
                        if (!failed)
                        {
                            resourceManager.commit(xid, true);
                        }
                        else
                        {
                            resourceManager.rollback(xid);
                        }
                    }
                    catch (Throwable e)
                    {
                        if( failures == null )
                        {
                            //lazy instantiate this, because we only need on failures
                            failures = new ArrayList();
                        }
                        failures.add(e);
                        failed = true;
                        status = Status.STATUS_MARKED_ROLLBACK;
                        JPOXLogger.TRANSACTION.error(LOCALISER.msg("015038", "commit", resourceManager, getXAErrorCode(e), toString()));                   
                    }
                }
                if (!failed)
                {
                    status = Status.STATUS_COMMITTED;
                }
                else
                {
                    status = Status.STATUS_ROLLEDBACK;
                }
   
            }
            else if (enlistedResources.size() > 0)
            {
   
                // Prepare each enlisted resource
                status = Status.STATUS_PREPARING;
                while ((!failed) && (branchKeys.hasNext()))
                {
                    Object key = branchKeys.next();
                    XAResource resourceManager = (XAResource) branches.get(key);
                    try
                    {
                        // Preparing the resource manager using its branch xid
                        resourceManager.prepare((Xid) key);
                    }
                    catch (Throwable e)
                    {
                        if( failures == null )
                        {
                            //lazy instantiate this, because we only need on failures
                            failures = new ArrayList();
                        }
                        failures.add(e);
                        failed = true;
                        status = Status.STATUS_MARKED_ROLLBACK;
                        JPOXLogger.TRANSACTION.error(LOCALISER.msg("015038", "prepare", resourceManager, getXAErrorCode(e), toString()));
                    }
                }
   
                if (!failed)
                {
                    status = Status.STATUS_PREPARED;
                }
   
                // Starts 2nd commit phase
                // If fail, rollback
                if (failed)
                {
                    status = Status.STATUS_ROLLING_BACK;
                    failed = false;
                    // Rolling back all the prepared (and unprepared) branches
                    branchKeys = branches.keySet().iterator();
                    while (branchKeys.hasNext())
                    {
                        Object key = branchKeys.next();
                        XAResource resourceManager = (XAResource) branches.get(key);
                        try
                        {
                            resourceManager.rollback((Xid) key);
                        }
                        catch (Throwable e)
                        {
                            JPOXLogger.TRANSACTION.error(LOCALISER.msg("015038", "rollback", resourceManager, getXAErrorCode(e), toString()));                       
                            if( failures == null )
                            {
                                //lazy instantiate this, because we only need on failures
                                failures = new ArrayList();
                            }
                            failures.add(e);
                            failed = true;
                        }
                    }
                    status = Status.STATUS_ROLLEDBACK;
                }
                else
                {
                    status = Status.STATUS_COMMITTING;
                    // Commit each enlisted resource
                    branchKeys = branches.keySet().iterator();
                    while (branchKeys.hasNext())
                    {
                        Object key = branchKeys.next();
                        XAResource resourceManager = (XAResource) branches.get(key);
                        try
                        {
                            resourceManager.commit((Xid) key, false);
                        }
                        catch (Throwable e)
                        {
                            JPOXLogger.TRANSACTION.error(LOCALISER.msg("015038", "commit", resourceManager, getXAErrorCode(e), toString()));                    
                            if( failures == null )
                            {
                                //lazy instantiate this, because we only need on failures
                                failures = new ArrayList();
                            }
                            failures.add(e);
                            failed = true;
                        }
                    }
                    status = Status.STATUS_COMMITTED;
                }
            }
   
            // Synchronization.afterCompletion
            syncIterator = synchronization.iterator();
            while (syncIterator.hasNext())
            {
                Synchronization sync = (Synchronization) syncIterator.next();
                sync.afterCompletion(status);
            }
           
            if (status == Status.STATUS_ROLLEDBACK)
            {
                if( failed )
View Full Code Here

           
            // Synchronization.afterCompletion
            Iterator syncIterator = synchronization.iterator();
            while (syncIterator.hasNext())
            {
                Synchronization sync = (Synchronization) syncIterator.next();
                sync.afterCompletion(status);
            }
        }
        finally
        {
            completing = false;
View Full Code Here

     * @param listener the listener to add
     * @throws SQLException if a problem occurs adding the listener to the transaction
     */
    public void addTransactionContextListener(final TransactionContextListener listener) throws SQLException {
        try {
            getTransaction().registerSynchronization(new Synchronization() {
                public void beforeCompletion() {
                }

                public void afterCompletion(int status) {
                    listener.afterCompletion(TransactionContext.this, status == Status.STATUS_COMMITTED);
View Full Code Here

   * avoiding object loading during a flush. Not needed during transactions.
   */
  public void onFlush(FlushEvent event) {
    if ( used ) {
      Session session = event.getSession();
      Synchronization synchronization = flushSynch.get( session );
      if ( synchronization != null ) {
        //first cleanup
        flushSynch.remove( session );
        log.debug( "flush event causing index update out of transaction" );
        synchronization.beforeCompletion();
        synchronization.afterCompletion( Status.STATUS_COMMITTED );
      }
    }
  }
View Full Code Here

    }

    private void beforeCompletion() {
        int i = 0;
        while (true) {
            Synchronization synch;
            synchronized (this) {
                if (i == syncList.size()) {
                    return;
                }
                synch = (Synchronization) syncList.get(i++);
            }
            try {
                synch.beforeCompletion();
            } catch (Exception e) {
                log.warn("Unexpected exception from beforeCompletion; transaction will roll back", e);
                synchronized (this) {
                    status = Status.STATUS_MARKED_ROLLBACK;
                }
View Full Code Here

    }

    private void afterCompletion() {
        // this does not synchronize because nothing can modify our state at this time
        for (Iterator i = syncList.iterator(); i.hasNext();) {
            Synchronization synch = (Synchronization) i.next();
            try {
                synch.afterCompletion(status);
            } catch (Exception e) {
                log.warn("Unexpected exception from afterCompletion; continuing", e);
                continue;
            }
        }
View Full Code Here

TOP

Related Classes of javax.transaction.Synchronization

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.