FileDocCategorySizeDatePackage
SuperiorInfo.javaAPI DocGlassfish v2 API15469Wed Jun 13 23:03:48 BST 2007com.sun.jts.CosTransactions

SuperiorInfo

public class SuperiorInfo extends Object
The SuperiorInfo interface provides operations that record the local transaction ID, global transaction ID for the superior (client) and the superior Coordinator. As an instance of this class may be accessed from multiple threads within a process, serialisation for thread-safety is necessary in the implementation. The information recorded in an instance of this class needs to be reconstructible in the case of a system failure.
version
0.01
author
Simon Holdsworth, IBM Corporation
see

Fields Summary
Long
localTID
The local identifier for the transaction.
GlobalTID
globalTID
The global identifier for the transaction.
Coordinator
superior
The reference of the superior Coordinator.
RecoveryCoordinator
recovery
The reference of the RecoveryCoordinator returned on the register_resource call to the superior Coordinator, if any. Note that this member may be directly read, but must be set using the setRecovery method in this class.
SubtransactionAwareResource
resource
The reference of the Resource registered on the register_resource call to the superior Coordinator, if any. Note that this member may be directly read, but must be set using the setResource method in this class.
private CoordinatorLog
logRecord
private Object
logSection
private int
resyncRetries
private static final String
LOG_SECTION_NAME
Constructors Summary
SuperiorInfo()
Default SuperiorInfo constructor.

param
return
see


               
      
SuperiorInfo(Long localTID, GlobalTID globalTID, Coordinator superior, CoordinatorLog log)
Defines the local transaction ID, global ID and superior Coordinator reference.

The CoordinatorLog is used as the basis for recovering the SuperiorInfo at restart. The SuperiorInfo section in the CoordinatorLog is created, with the global identifier added to the section.

param
localTID The local identifier for the transaction.
paran
globalTID The global identifier for the transaction.
param
superior The superior Coordinator reference (may be null).
param
log The CoordinatorLog object (may be null).
return
see


        this.localTID = localTID;
        this.globalTID = globalTID;
        this.superior = superior;
        recovery = null;
        resource = null;
        logRecord = log;
        resyncRetries = 0;

        // Set up CoordinatorLog section for this class

        if (log != null) {

            // Create a section in the CoordinatorLog for SuperiorInfo

            logSection = log.createSection(LOG_SECTION_NAME);

            // Add the Global Id to the SuperiorInfo section of the log

            log.addData(logSection,globalTID.toBytes());
        }
    
Methods Summary
voiddelegated_reconstruct(CoordinatorLog log, CoordinatorImpl coord, java.lang.String logPath)


        superior = null;

        // Recover our state from the CoordinatorLog object.
        // Get the section id in the CoordinatorLog for SuperiorInfo

        logSection = log.createSection(LOG_SECTION_NAME);
        byte[][] logData = log.getData(logSection);

        // Construct the global identifier.

        globalTID = new GlobalTID(logData[0]);

        // Get the local transaction identifier from the CoordinatorLog
        // attribute rather than from the log record itself.

        localTID = log.localTID;
        logRecord = log;
        resyncRetries = 0;

        // Add the Coordinator to the RecoveryManager map.  This is
        // to allow the recovery of the CoordinatorResource reference,
        // which results in a call to getCoordinator.

        DelegatedRecoveryManager.addCoordinator(globalTID, localTID, coord, 0, logPath);

        // Get all objects that were logged.  If this SuperiorInfo represents
        // a root TopCoordinator object, then there will be no objects logged.

        java.lang.Object[] logObjects = log.getObjects(logSection);

        try {
            if (logObjects.length > 1) {
                if (((org.omg.CORBA.Object) logObjects[0]).
                        _is_a(RecoveryCoordinatorHelper.id())) {
                    // TN - used to be com.sun.CORBA.iiop.CORBAObjectImpl
                    java.lang.Object rcimpl = logObjects[0];
                        
                    String[] ids = StubAdapter.getTypeIds(rcimpl);
                    /*
                    for (int i = 0; i < ids.length; i++)
                        if( trc != null )
                            trc.exit(998).data(i).data(ids[i]).write();
                    */

                    // TN - used to be com.sun.CORBA.iiop.CORBAObjectImpl
                    java.lang.Object crimpl = logObjects[1];
                        
                    ids = StubAdapter.getTypeIds(crimpl);
                    /*
                    for( int i = 0; i < ids.length; i++ )
                        if( trc != null )
                            trc.exit(998).data(i).data(ids[i]).write();
                    */
                    recovery = RecoveryCoordinatorHelper.
                                narrow((org.omg.CORBA.Object) logObjects[0]);

                    resource = SubtransactionAwareResourceHelper.
                                narrow((org.omg.CORBA.Object) logObjects[1]);
                } else {
                    recovery = RecoveryCoordinatorHelper.
                                narrow((org.omg.CORBA.Object) logObjects[1]);
                    resource = SubtransactionAwareResourceHelper.
                                narrow((org.omg.CORBA.Object) logObjects[0]);
                }
            } else {
                recovery = null;
                resource = null;
            }
        } catch (Throwable exc) {}
    
public voiddoFinalize()
Cleans up the objects state.

param
return
see


        // Destroy the global transaction identifier.

        //$ if( globalTID != null ) globalTID.finalize();

        // Release superior Coordinator references.

        if (superior != null &&
                !(superior instanceof org.omg.CORBA.LocalObject)) {
            superior._release();
        }

        //$#ifndef OTS_DEFERRED_REGISTRATION
        //$For deferred registration, the CurrentTransaction
        //$will release the proxy, so there is no need to do it here.
        //$For non-deferred registration, the RecoveryCoordinator
        //$must be destroyed by the subordinate as no-one else will.

        if (recovery != null && 
                !(recovery instanceof org.omg.CORBA.LocalObject)) {
            recovery._release();
        }

        //$#endif /* OTS_DEFERRED_REGISTRATION */

        localTID = null;
        globalTID = null;
        superior = null;
        recovery = null;
        resource = null;
    
voidreconstruct(CoordinatorLog log, CoordinatorImpl coord)
Directs the SuperiorInfo to recover its state after a failure, based on the given CoordinatorLog object.

The SuperiorInfo then adds the given Coordinator to the RecoveryManager mappings. If the SuperiorInfo has already been defined or reconstructed, the operation does nothing. If the state cannot be reconstructed, the Coordinator is not added.

The global identifier, local ID, RecoveryCoordinator and CoordinatorResource object references are restored.

param
log The CoordinatorLog object for the transaction.
param
coord The Coordinator object recreated after recovery.
return
see


        superior = null;

        // Recover our state from the CoordinatorLog object.
        // Get the section id in the CoordinatorLog for SuperiorInfo

        logSection = log.createSection(LOG_SECTION_NAME);
        byte[][] logData = log.getData(logSection);

        // Construct the global identifier.

        globalTID = new GlobalTID(logData[0]);

        // Get the local transaction identifier from the CoordinatorLog
        // attribute rather than from the log record itself.

        localTID = log.localTID;
        logRecord = log;
        resyncRetries = 0;

        // Add the Coordinator to the RecoveryManager map.  This is
        // to allow the recovery of the CoordinatorResource reference,
        // which results in a call to getCoordinator.

        RecoveryManager.addCoordinator(globalTID, localTID, coord, 0);

        // Get all objects that were logged.  If this SuperiorInfo represents
        // a root TopCoordinator object, then there will be no objects logged.

        java.lang.Object[] logObjects = log.getObjects(logSection);

        try {
            if (logObjects.length > 1) {
                if (((org.omg.CORBA.Object) logObjects[0]).
                        _is_a(RecoveryCoordinatorHelper.id())) {
                    // TN - used to be com.sun.CORBA.iiop.CORBAObjectImpl
                    java.lang.Object rcimpl = logObjects[0];
                        
                    String[] ids = StubAdapter.getTypeIds(rcimpl);
                    /*
                    for (int i = 0; i < ids.length; i++)
                        if( trc != null )
                            trc.exit(998).data(i).data(ids[i]).write();
                    */

                    // TN - used to be com.sun.CORBA.iiop.CORBAObjectImpl
                    java.lang.Object crimpl = logObjects[1];
                        
                    ids = StubAdapter.getTypeIds(crimpl);
                    /*
                    for( int i = 0; i < ids.length; i++ )
                        if( trc != null )
                            trc.exit(998).data(i).data(ids[i]).write();
                    */
                    recovery = RecoveryCoordinatorHelper.
                                narrow((org.omg.CORBA.Object) logObjects[0]);

                    resource = SubtransactionAwareResourceHelper.
                                narrow((org.omg.CORBA.Object) logObjects[1]);
                } else {
                    recovery = RecoveryCoordinatorHelper.
                                narrow((org.omg.CORBA.Object) logObjects[1]);
                    resource = SubtransactionAwareResourceHelper.
                                narrow((org.omg.CORBA.Object) logObjects[0]);
                }
            } else {
                recovery = null;
                resource = null;
            }
        } catch (Throwable exc) {}
    
intresyncRetries()
Returns the number of retries so far, and increments the count.

param
return
The number of retries so far.
see


        int result = resyncRetries++;

        return result;
    
voidsetRecovery(RecoveryCoordinator rec)
Records the RecoveryCoordinator for the transaction.

param
rec The RecoveryCoordinator from the superior.
return
see


        if (recovery == null) {
            recovery = rec;

            // Add the RecoveryCoordinator to the CoordinatorLog object

            if (logRecord != null) {
                logRecord.addObject(logSection, rec);
            }
        }
    
voidsetResource(SubtransactionAwareResource res)
Records the CoordinatorResource for the transaction.

param
res The CoordinatorResource registered with the superior.
return
see


        if (resource == null) {
            resource = res;

            // Add the CoordinatorResource to the CoordinatorLog object

            if (logRecord != null) {
                logRecord.addObject(logSection, res);
            }
        }