FileDocCategorySizeDatePackage
DefaultTransactionService.javaAPI DocGlassfish v2 API21002Fri May 04 22:36:38 BST 2007com.sun.jts.CosTransactions

DefaultTransactionService

public class DefaultTransactionService extends Object implements com.sun.corba.ee.spi.costransactions.TransactionService, ProxyChecker
The DefaultTransactionService is our implemention of the com.sun.CosTransactions.TransactionService class.

The TransactionService abstract class describes the packaging of a Java Transaction Service implementation. Each implementation should be packaged as a subclass of the TransactionService class.

version
0.01
author
Simon Holdsworth, IBM Corporation
see

Fields Summary
private static CurrentImpl
currentInstance
private static TransactionFactoryImpl
factoryInstance
private static NamingContext
namingContext
private static ORB
orb
private static boolean
recoverable
private static boolean
poasCreated
private static boolean
active
static Logger
_logger
public static final String
JTS_SERVER_ID
Constructors Summary
public DefaultTransactionService()
Default constructor.

param
return
see

 /* FROZEN */

   
	         
      
        // We do not set up the Current instance until we know the ORB.
        // This method is not traced as trace is not configured until the init method
        // is called.

    
Methods Summary
static final voidcreatePOAs()
Creates the POA objects which are used for objects within the JTS.

param
return
exception
Exception The operation failed.
see


        POA rootPOA = (POA)orb.resolve_initial_references("RootPOA"/*#Frozen*/);

        // Create the POA used for CoordinatorResource objects.

        POA CRpoa = null;
        if( recoverable ) {

            // Create the POA with PERSISTENT and USE_SERVANT_MANAGER policies.

            Policy[] tpolicy = new Policy[2];
            tpolicy[0] = rootPOA.create_lifespan_policy(LifespanPolicyValue.PERSISTENT);
            tpolicy[1] = rootPOA.create_request_processing_policy(RequestProcessingPolicyValue.USE_SERVANT_MANAGER);
            CRpoa = rootPOA.create_POA("com.sun.jts.CosTransactions.CoordinatorResourcePOA"/*#Frozen*/, null, tpolicy);

            // Register the ServantActivator with the POA, then activate POA.

            CoordinatorResourceServantActivator crsa = new CoordinatorResourceServantActivator(orb);
            CRpoa.set_servant_manager(crsa);
        }

        // If the process is not recoverable, then we do not create a persistent POA.

        else
            CRpoa = rootPOA;

        Configuration.setPOA("CoordinatorResource"/*#Frozen*/,CRpoa);

        // Create the POA used for RecoveryCoordinator objects.

        POA RCpoa = null;
        if( recoverable ) {

            // Create the POA with PERSISTENT and USE_SERVANT_MANAGER policies.

            Policy[] tpolicy = new Policy[2];
            tpolicy[0] = rootPOA.create_lifespan_policy(LifespanPolicyValue.PERSISTENT);
            tpolicy[1] = rootPOA.create_request_processing_policy(RequestProcessingPolicyValue.USE_SERVANT_MANAGER);
            RCpoa = rootPOA.create_POA("com.sun.jts.CosTransactions.RecoveryCoordinatorPOA"/*#Frozen*/, null, tpolicy);

            // Register the ServantActivator with the POA, then activate POA.

            RecoveryCoordinatorServantActivator rcsa = new RecoveryCoordinatorServantActivator(orb);
            RCpoa.set_servant_manager(rcsa);
        }

        // If the process is not recoverable, then we do not create a persistent POA.

        else
            RCpoa = rootPOA;

        Configuration.setPOA("RecoveryCoordinator"/*#Frozen*/,RCpoa);

        // Create the POA used for Coordinator objects.

        POA Cpoa = rootPOA.create_POA("CoordinatorPOA"/*#Frozen*/, null, null);
        //  POA Cpoa = rootPOA;
        Configuration.setPOA("Coordinator"/*#Frozen*/,Cpoa);

        // Create the POA used for transient objects.

        Configuration.setPOA("transient"/*#Frozen*/,rootPOA);

        //  rootPOA.the_activator(new JTSAdapterActivator(orb));
        CRpoa.the_POAManager().activate();
        RCpoa.the_POAManager().activate();
        Cpoa.the_POAManager().activate();
        rootPOA.the_POAManager().activate();

        poasCreated = true;

    
public org.omg.CosTransactions.Currentget_current()
Obtain the implementation of the Current interface provided by the transaction service implementation.

param
return
An instance of the Current class
see

        org.omg.CosTransactions.Current result = null;

        result = (org.omg.CosTransactions.Current)currentInstance;

        return result;
    
public voididentify_ORB(ORB orb, TSIdentification ident, java.util.Properties properties)
Request the transaction service to identify itself with a communication manager.

Multiple communication managers may request a transaction service to identify itself.

param
orb The ORB to be used for communication.
param
ident The TSIdentification object with which the Sender and Receiver must be registered.
param
properties The Properties with which the ORB was initialised.
return
see

        if( this.orb == null ) {
            this.orb = orb;
            Configuration.setORB(orb);
            Configuration.setProperties(properties);
            Configuration.setProxyChecker(this);
        }

        // We have to wait until this point to trace entry into this method as trace
        // is only started by setting the properties in the Configuration class.

        // Get the persistent server id of the server.  If it does not represent a
        // transient server, then the server is recoverable.

        if( !poasCreated ) {
            //String serverId = properties.getProperty("com.sun.corba.ee.internal.POA.ORBServerId"/*#Frozen*/);
            String serverId = properties.getProperty(JTS_SERVER_ID);
            if (serverId == null) {
                serverId = 
                    properties.getProperty("com.sun.CORBA.POA.ORBServerId"/*#Frozen*/);
            }
            if (serverId != null) {
					_logger.log(Level.INFO,"jts.startup_msg",serverId);
            }
            String serverName = "UnknownHost"/*#Frozen*/;
            try {
                serverName = InetAddress.getLocalHost().getHostName();
            } catch (UnknownHostException ex) {
            }
            if( serverId != null ) {
                Configuration.setServerName(serverName + "," + 
		    Configuration.getPropertyValue(Configuration.INSTANCE_NAME)
		    +  ",P" + serverId/*#Frozen*/, true);
                recoverable = true;
            } else {
                long timestamp = System.currentTimeMillis();
                Configuration.setServerName(serverName + ",T" +
                                            String.valueOf(timestamp)/*#Frozen*/, false);
            }

            // Set up the POA objects for transient and persistent references.

            try {
                createPOAs();
            } catch( Exception exc ) {
				_logger.log(Level.WARNING,"jts.unexpected_error_when_creating_poa",exc);
                throw new INTERNAL(MinorCode.TSCreateFailed,CompletionStatus.COMPLETED_NO);
            }
        }

        // Set up the instance of the Current object now that we know the ORB.

        if( currentInstance == null )
           try {
                currentInstance = new CurrentImpl();
            } catch( Exception exc ) {
				_logger.log(Level.WARNING,"jts.unexpected_error_when_creating_current",exc);
                throw new INTERNAL(MinorCode.TSCreateFailed,CompletionStatus.COMPLETED_NO);
            }

        // Identify Sender and Receiver objects to the Comm Manager.

        SenderReceiver.identify(ident);

        // If the server is recoverable, create a NamingContext with which to
        // register the factory and admin objects.

        if( recoverable && namingContext == null )
            try {
                namingContext = NamingContextHelper.narrow(orb.resolve_initial_references("NameService"/*#Frozen*/));
            } catch( InvalidName inexc ) {
				// _logger.log(Level.WARNING,"jts.orb_not_running");
				if (_logger.isLoggable(Level.FINE)) {
					_logger.log(Level.FINE,"jts.orb_not_running");
				}
            } catch( Exception exc ) {
				// _logger.log(Level.WARNING,"jts.orb_not_running");
				if (_logger.isLoggable(Level.FINE)) {
					_logger.log(Level.FINE,"jts.orb_not_running");
				}
            }

        // Create a TransactionFactory object and register it with the naming service
        // if recoverable.

        if( factoryInstance == null )
            try {
                boolean localFactory = true;
                TransactionFactory factory = null;
                factoryInstance = new TransactionFactoryImpl();
                if (localFactory) {
                    factory = (TransactionFactory) factoryInstance;
                } else {
                    factory = factoryInstance.object();
                }

                // Since we are instantiating the TransactionFactory object
                // locally, we have a local transaction factory.

                Configuration.setFactory(factory, /*local factory*/ localFactory);

                if (Configuration.isLocalFactory() == false &&  namingContext != null) {
                    NameComponent nc = new NameComponent(TransactionFactoryHelper.id(),"");
                    NameComponent path[] = {nc};
                    namingContext.rebind(path,factory);
                }

                // Commented out by TN
                //if( !recoverable )
                //_logger.log(Level.WARNING,"jts.non_persistent_server");
            } catch( Exception exc ) {
				_logger.log(Level.WARNING,"jts.cannot_register_with_orb","TransactionFactory");
            }

            active = true; // transaction manager is alive and available
    
public static booleanisActive()

return
true, if transaction manager is available.

        return active;
    
public final booleanisProxy(org.omg.CORBA.Object obj)
Determines whether the given object is a proxy.

param
obj The potential proxy.
return
Indicates whether the object is a proxy.
see


        // TN  POA changes
        return !( StubAdapter.isStub(obj) && StubAdapter.isLocal(obj) );
    
public static voidshutdown(boolean immediate)
Request the transaction service to stop any further transactional activity.

param
immediate Indicates whether to ignore running transactions.
return
see

        // Remove the admin and factory objects from the naming service.

        if( namingContext != null )
            try {
                NameComponent nc = new NameComponent(TransactionFactoryHelper.id(),"");
                NameComponent path[] = {nc};
                namingContext.unbind(path);

                namingContext = null;
            } catch( Exception exc ) {}

        // Inform the local TransactionFactory and CurrentImpl classes that no more
        // transactional activity may occur.

        TransactionFactoryImpl.deactivate();
        CurrentImpl.deactivate();

        // Shut down the basic transaction services.

        currentInstance.shutdown(immediate);

        // Discard the factory and current instances.

        currentInstance = null;
        factoryInstance = null;
        //adminInstance   = null;
        active = false;