Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2007, Red Hat Middleware LLC, and individual contributors
   * as indicated by the @author tags.
   * See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   * This copyrighted material is made available to anyone wishing to use,
   * modify, copy, or redistribute it subject to the terms and conditions
   * of the GNU Lesser General Public License, v. 2.1.
  * This program is distributed in the hope that it will be useful, but WITHOUT A
  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
  * You should have received a copy of the GNU Lesser General Public License,
  * v.2.1 along with this distribution; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  * MA  02110-1301, USA.
  *
  * (C) 2007,
  * @author Red Hat Middleware LLC.
  */
 package org.jboss.jbossts.xts.recovery.participant.at;
 
 
 
This class is a plug-in module for the recovery manager. It is responsible for recovering XTS AT participants. (instances of org.jboss.jbossts.xts.recovery.participant.at.ATParticipantRecoveryRecord) $Id$
 
 
 public class ATParticipantRecoveryModule implements XTSRecoveryModule
 {
     public ATParticipantRecoveryModule()
     {
         if (..isDebugEnabled()) {
             ..debug("ATParticipantRecoveryModule created - default");
         }
 
         if ( == null)
         {
              = StoreManager.getRecoveryStore();
         }
 
          = ATParticipantRecoveryRecord.type();
     }

    
called by the service startup code before the recovery module is added to the recovery managers module list
 
     public void install()
     {
         // the manager is needed by both the participant or the coordinator recovery modules so whichever
         // one gets there first creates it. No synchronization is needed as modules are only ever
         // installed in a single thread
         XTSATRecoveryManager atRecoveryManager = XTSATRecoveryManager.getRecoveryManager();
         if (atRecoveryManager == null) {
             atRecoveryManager = new XTSATRecoveryManagerImple();
             XTSATRecoveryManager.setRecoveryManager(atRecoveryManager);
         }
         // Subordinate Coordinators register durable participants with their parent transaction so
         // we need to add an XTSATRecoveryModule which knows about the registered participants
 
         
         atRecoveryManager.registerRecoveryModule();
     }

    
a recovery module which knows hwo to recover the participants registered by Subordinate AT Coordinators
 
 
called by the service shutdown code after the recovery module is removed from the recovery managers module list
 
     public void uninstall()
     {
     }

    
This is called periodically by the RecoveryManager
    public void periodicWorkFirstPass()
    {
        // Transaction type
        boolean ATParticipants = false ;
        // uids per transaction type
        InputObjectState acc_uids = new InputObjectState() ;
        try
        {
            if (..isDebugEnabled()) {
                ..debug("ATParticipantRecoveryModule: first pass");
            }
            ATParticipants = .allObjUids(acc_uids );
        }
        catch ( ObjectStoreException ex )
        {
        }
        if ( ATParticipants )
        {
             = processParticipantsacc_uids ) ;
        }
    }
    public void periodicWorkSecondPass()
    {
        if (..isDebugEnabled()) {
            ..debug("ATParticipantRecoveryModule: Second pass");
        }
        processParticipantsStatus() ;
    }
    private void doRecoverParticipantUid recoverUid )
    {
        // Retrieve the participant from its original process.
        if (..isDebugEnabled()) {
            ..debug("participant type is " +  + " uid is " +
                    recoverUid.toString());
        }
        // we don't need to use a lock here because we only attempt the read
        // when the uid is inactive which means it cannto be pulled out form under our
        // feet at commit. uniqueness of uids also means we can't be foiled by a reused
        // uid.
        XTSATRecoveryManager recoveryManager = XTSATRecoveryManager.getRecoveryManager();
        if (!recoveryManager.isParticipantPresent(recoverUid)) {
            // ok, the participant can neither be active nor loaded awaiting recreation by
            // an application recovery module so we need to load it
            try {
                // retrieve the data for the participant
                InputObjectState inputState = .read_committed(recoverUid);
                if (inputState != null) {
                    try {
                        String participantRecordClazzName = inputState.unpackString();
                        try {
                            // create a participant engine instance and tell it to recover itself
                            Class participantRecordClazz = Class.forName(participantRecordClazzName);
                            ATParticipantRecoveryRecord participantRecord = (ATParticipantRecoveryRecord)participantRecordClazz.newInstance();
                            participantRecord.restoreState(inputState);
                            // ok, now insert into recovery map if needed
                            XTSATRecoveryManager.getRecoveryManager().addParticipantRecoveryRecord(recoverUidparticipantRecord);
                        } catch (ClassNotFoundException cnfe) {
                            // oh boy, not supposed to happen -- n.b. either the user deployed 1.0
                            // last time and 1.1 this time or vice versa or something is rotten in
                            // the state of Danmark
                            ..error_participant_at_ATParticipantRecoveryModule_4(participantRecordClazzNamerecoverUidcnfe);
                        } catch (InstantiationException ie) {
                            // this is also worrying, log an error
                            ..error_participant_at_ATParticipantRecoveryModule_5(participantRecordClazzNamerecoverUidie);
                        } catch (IllegalAccessException iae) {
                            // this is another configuration problem, log an error
                            ..error_participant_at_ATParticipantRecoveryModule_5(participantRecordClazzNamerecoverUidiae);
                        }
                    } catch (IOException ioe) {
                        // hmm, record corrupted? log this as a warning
                        ..error_participant_at_ATParticipantRecoveryModule_6(recoverUidioe);
                    }
                } else {
                    // hmm, it ought not to be able to disappear unless the recovery manager knows about it
                    // this is an error!
                    ..error_participant_at_ATParticipantRecoveryModule_7(recoverUid);
                }
            } catch (ObjectStoreException ose) {
                // if the object store is not working this is serious
                ..error_participant_at_ATParticipantRecoveryModule_8(recoverUidose);
            }
        }
    }
    private Vector processParticipantsInputObjectState uids )
    {
        Vector uidVector = new Vector() ;
        if (..isDebugEnabled()) {
            ..debug("processing " + 
                    + " WS-AT participants");
        }
        Uid NULL_UID = Uid.nullUid();
        Uid theUid = null;
        while (true)
        {
            try
            {
                theUid = UidHelper.unpackFromuids ) ;
            }
            catch ( Exception ex )
            {
                break;
            }
            if (theUid.equalsNULL_UID ))
            {
                break;
            }
            if (..isDebugEnabled()) {
                ..debug("found WS-AT participant " + theUid);
            }
            uidVector.addElementtheUid ) ;
        }
        return uidVector ;
    }
    private void processParticipantsStatus()
    {
        if ( != null) {
        // Process the Vector of transaction Uids
        Enumeration participantUidEnum = .elements() ;
        while ( participantUidEnum.hasMoreElements() )
        {
            Uid currentUid = (UidparticipantUidEnum.nextElement();
            try
            {
                if ( .currentStatecurrentUid) != . )
                {
                    doRecoverParticipantcurrentUid ) ;
                }
            }
            catch ( ObjectStoreException ex )
            {
                ..warn_participant_at_ATParticipantRecoveryModule_3(currentUidex);
            }
        }
        }
        // now get the AT recovery manager to try to activate recovered participants
        XTSATRecoveryManager.getRecoveryManager().recoverParticipants();
    }
    // 'type' within the Object Store for ATParticipant record.
    private String _participantType = ATParticipantRecoveryRecord.type() ;
    // Array of transactions found in the object store of the
    // ACCoordinator type.
    private Vector _participantUidVector = null ;
    // Reference to the Object Store.
    private static RecoveryStore _recoveryStore = null ;
    // This object provides information about whether or not a participant is currently active.
New to GrepCode? Check out our FAQ X