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

TransactionFactoryImpl

public class TransactionFactoryImpl extends TransactionFactoryPOA implements TransactionFactory
The TransactionFactoryImpl interface is our implementation of the standard TransactionFactory interface. It provides operations to create the objects required to process a transaction.
version
0.01
author
Simon Holdsworth, IBM Corporation
see

Fields Summary
private static POA
poa
private TransactionFactory
thisRef
static boolean
active
static Logger
_logger
Constructors Summary
TransactionFactoryImpl()
Constructor for the TransactionFactoryImpl. Passes through to the parent constructor.

param
return
see

                       
     

        // Initialise the TimeoutManager and RecoveryManager.

        TimeoutManager.initialise();
        RecoveryManager.initialise();
    
Methods Summary
public org.omg.CORBA.Request_create_request(org.omg.CORBA.Context ctx, java.lang.String operation, org.omg.CORBA.NVList arg_list, org.omg.CORBA.NamedValue result)

        throw new org.omg.CORBA.NO_IMPLEMENT("This is a locally constrained object.");
    
public org.omg.CORBA.Request_create_request(org.omg.CORBA.Context ctx, java.lang.String operation, org.omg.CORBA.NVList arg_list, org.omg.CORBA.NamedValue result, org.omg.CORBA.ExceptionList exceptions, org.omg.CORBA.ContextList contexts)

        throw new org.omg.CORBA.NO_IMPLEMENT("This is a locally constrained object.");
    
public org.omg.CORBA.Object_duplicate()

        throw new org.omg.CORBA.NO_IMPLEMENT("This is a locally constrained object.");
    
public org.omg.CORBA.DomainManager[]_get_domain_managers()

        throw new org.omg.CORBA.NO_IMPLEMENT("This is a locally constrained object.");
    
public org.omg.CORBA.Object_get_interface_def()

        throw new org.omg.CORBA.NO_IMPLEMENT("This is a locally constrained object.");
    
public org.omg.CORBA.Policy_get_policy(int policy_type)

        throw new org.omg.CORBA.NO_IMPLEMENT("This is a locally constrained object.");
    
public int_hash(int maximum)

        throw new org.omg.CORBA.NO_IMPLEMENT("This is a locally constrained object.");
    
public boolean_is_a(java.lang.String repository_id)

        throw new org.omg.CORBA.NO_IMPLEMENT("This is a locally constrained object.");
    
public boolean_is_equivalent(org.omg.CORBA.Object that)

        throw new org.omg.CORBA.NO_IMPLEMENT("This is a locally constrained object.");
    
public boolean_non_existent()

        throw new org.omg.CORBA.NO_IMPLEMENT("This is a locally constrained object.");
    
public void_release()

        throw new org.omg.CORBA.NO_IMPLEMENT("This is a locally constrained object.");
    
public org.omg.CORBA.Request_request(java.lang.String operation)

        throw new org.omg.CORBA.NO_IMPLEMENT("This is a locally constrained object.");
    
public org.omg.CORBA.Object_set_policy_override(org.omg.CORBA.Policy[] policies, org.omg.CORBA.SetOverrideType set_add)

        throw new org.omg.CORBA.NO_IMPLEMENT("This is a locally constrained object.");
    
public Controlcreate(int timeOut)
Creates the Coordinator, Control and Terminator objects for a new top-level transaction.

param
timeOut The timeout value for the transaction.
return
The Control object for the new transaction.
exception
SystemException An error occurred.
see


        Control result = null;
	
        ControlImpl cimpl = localCreate(timeOut);

        if (cimpl == null) {
            return result;
        }

        if (Configuration.isLocalFactory()) {
            result = (Control) cimpl;
        } else {
            result = cimpl.object();
        }

        return result;
    
static voiddeactivate()
Prevents any further transactional activity in the process.

param
return
see


        active = false;

        // Shut down the TimeoutManager and RecoveryManager.

        TimeoutManager.shutdown(false);
        RecoveryManager.shutdown(false);
        DelegatedRecoveryManager.shutdown(false);
    
public ControlImpllocalCreate(int timeOut)
Creates the Coordinator, Control and Terminator objects for a new top-level transaction.

param
timeOut The timeout value for the transaction.
return
The local Control object for the new transaction.
exception
SystemException An error occurred.
see


        // If the transaction service is not active, throw an exception.

        if (!active) {
            NO_PERMISSION exc =
                new NO_PERMISSION(0, CompletionStatus.COMPLETED_NO);
            throw exc;
        }

        // Ensure that resync has completed.

        RecoveryManager.waitForResync();

        // Create a new top-level Coordinator, and initialise it
        // with the given time-out value.  If the operation fails,
        // return a NULL Control
        // object, and whatever exception was raised.

        TopCoordinator coordinator = null;
        TerminatorImpl terminator = null;
        ControlImpl result = null;

        try {
            coordinator = new TopCoordinator(timeOut);

            // Create a Terminator object, and initialise it with
            // the Coordinator reference and a flag
            // to indicate that it does not represent a
            // subtransaction.  If the operation fails,
            // return a NULL Control object, and whatever exception was raised.

            terminator = new TerminatorImpl(coordinator,false);

            // Create a Control object, and initialise it with the Terminator,
            // Coordinator and global OMGtid. If the operation fails,
            // return a NULL Control object, and whatever exception was raised.

            // result = new ControlImpl(terminator, coordinator,
            //                         new GlobalTID(coordinator.getGlobalTID()),
            //                          new Long(coordinator.getLocalTID()));
            result = new ControlImpl(terminator, coordinator,
                                     coordinator.getGlobalTid(),
                                     new Long(coordinator.getLocalTID()));
		    if(_logger.isLoggable(Level.FINE))
		    {
				_logger.logp(Level.FINE,"TransactionFactoryImpl","localCreate()",
						"Control object :" + result + 
						" corresponding to this transaction has been created"+
						"GTID is : "+
						((TopCoordinator)coordinator).superInfo.globalTID.toString());
		    }
	
        } catch (Throwable exc) {

            // If an error occurred, free up the objects.

            if (coordinator != null) {
                coordinator.doFinalize();
            }

            if (result != null) {
                ((ControlImpl) result).doFinalize();
            }

            result = null;
        }

        return result;
    
synchronized TransactionFactoryobject()
Returns the CORBA Object which represents this object.

param
return
The CORBA object.
see

        if (thisRef == null) {
            if (poa == null) {
                poa = Configuration.getPOA("transient"/*#Frozen*/);
            }

            try {
                poa.activate_object(this);
                thisRef = TransactionFactoryHelper.
                            narrow(poa.servant_to_reference(this));
                //thisRef = (TransactionFactory)this;

                /*
                 * ADDED(Ram J) Whenever a TransactionFactory corba object is
                 * created, put it in the cosnaming service.
                 */

                NamingContext namingContext = null;
                try {
                    namingContext = NamingContextHelper.narrow(
                        Configuration.getORB().resolve_initial_references("NameService"/*#Frozen*/));
                } catch (Exception exc) {
					_logger.log(Level.WARNING,"jts.orb_not_running");
                }

                try {
                    NameComponent nc = new NameComponent(TransactionFactoryHelper.id(), "");
                    NameComponent path[] = { nc };
                    namingContext.rebind(path, thisRef);
                } catch (Exception exc) {
					_logger.log(Level.WARNING,"jts.cannot_register_with_orb",
							"TransactionFactory");
                }
            } catch (Exception exc) {
				_logger.log(Level.SEVERE,"jts.create_transactionfactory_object_error");
				 String msg = LogFormatter.getLocalizedMessage(_logger,
				 						"jts.create_transactionfactory_object_error");
				 throw  new org.omg.CORBA.INTERNAL(msg);
            }
        }

        return thisRef;
    
public Controlrecreate(PropagationContext context)
Creates the Coordinator, Control and Terminator objects for a transaction based on the context passed in.

param
context The context for the transaction.
return
The Control object for the new transaction.
exception
SystemException An error occurred.
see


        // If the transaction service is not active, throw an exception.

        if (!active) {
            NO_PERMISSION exc =
                new NO_PERMISSION(0,CompletionStatus.COMPLETED_NO);
            throw exc;
        }

        // If the transaction identifier in the context is NULL, just return.

        if (context.current == null || context.current.otid.formatID == -1) {
            return null;
        }

        // First check whether there is already a local subordinate
        // for the given transaction.

        GlobalTID globalTID = new GlobalTID(context.current.otid);
        CoordinatorImpl subordinate =
            RecoveryManager.getCoordinator(globalTID);
        Control result = null;

        // If there is no local subordinate, but the Coordinator
        // in the context represents a local object,
        // then the Coordinator must have been created by the client using
        // this TransactionFactory, and the transaction it represents
        // must have been rolled back - invoking a method on the Coordinator
        // at this point should throw OBJECT_NOT_EXIST.  This means that we
        // cannot import the transaction, and should throw
        // TRANSACTION_ROLLEDBACK.

        ProxyChecker checker = Configuration.getProxyChecker();
        if (subordinate == null &&
                !checker.isProxy(context.current.coord)) {

            TRANSACTION_ROLLEDBACK exc =
                new TRANSACTION_ROLLEDBACK(0, CompletionStatus.COMPLETED_NO);
            throw exc;
        }

        // If there is no subordinate, then we must import the transaction.
        // We first must make sure that resync is not in progress.

        if (subordinate == null) {
            RecoveryManager.waitForResync();
            subordinate = RecoveryManager.getCoordinator(globalTID);
        }

        // If there is no local subordinate, then for each OMGtid
        // in the context, make sure there is a local
        // Coordinator set up in this process - required for
        // AIX, where we need to ensure every  ancestor has a locally created
        // transaction.  When we have threading on AIX this will not
        // be absolutely necessary, but will still be desirable.

        try {

            if (subordinate == null) {

                if (context.parents.length > 0) {

                    CoordinatorImpl[] newAncestors =
                        new CoordinatorImpl[context.parents.length];

                    // If there are indeed ancestors, go through them
                    // starting at the top-level
                    // ancestor, which is the last in the sequence.

                    for (int i = context.parents.length - 1; i >= 0; i--) {

                        // If a subordinate does not exist, create one.

                        GlobalTID subGlobalTID =
                            new GlobalTID(context.parents[i].otid);
                        subordinate =
                            RecoveryManager.getCoordinator(subGlobalTID);

                        if (subordinate == null) {

                            if (i == context.parents.length - 1) {

                                // If it is the last ancestor, create a
                                // temporary top-level subordinate. Use a
                                // duplicate of the proxy to allow the context
                                // to be fully destroyed.

                                subordinate = new TopCoordinator(
                                    context.timeout,
                                    subGlobalTID,
                                    (Coordinator) context.parents[i].
                                        coord._duplicate(),
                                    true);

                            } else {

                                // If it is not the last ancestor, create a
                                // temporary child subordinate. Use a duplicate
                                // of the proxy to allow the context to be
                                // fully destroyed.

                                CoordinatorImpl[] subAncestors =
                                    new CoordinatorImpl[context.parents.length
                                                        - i - 1];
                                System.arraycopy(newAncestors, i + 1,
                                                 subAncestors, 0,
                                                 context.
                                                    parents.length - i - 1);

                                subordinate =
                                    new SubCoordinator(
                                        subGlobalTID,
                                        (Coordinator)context.parents[i].
                                            coord._duplicate(),
                                        true,
                                        subAncestors);

                                // Make sure that the parent knows about
                                // its new child.

                                newAncestors[i+1].addChild(subordinate);
                            }
                         }

                        // Replace the Coordinator reference in the sequence
                        // of ancestors with that of the local subordinate,
                        // first releasing the proxy in the context.

                        context.parents[i].coord._release();
                        newAncestors[i] = subordinate;
                    }

                    // Now the ancestors have been 'converted' create a
                    // subordinate of the given subtransaction.
                    // Use a duplicate of the proxy to allow
                    // the context to be fully destroyed.

                    subordinate =
                        new SubCoordinator(globalTID,
                                           (Coordinator) context.current.
                                                coord._duplicate(),
                                           true,
                                           newAncestors);

                    //$ This flag was set to false.  Surely this subordinate
                    // is temporary?

                    // Make sure the parent knows about its new child.

                    newAncestors[0].addChild(subordinate);
                } else {

                    // If there are no ancestors, but the subordinate
                    // does not already exist, create a top-level subordinate.
                    // Use a duplicate of the proxy to allow the context
                    // to be fully destroyed.

                    subordinate = new TopCoordinator(
                                    context.timeout,
                                    globalTID,
                                    (Coordinator) context.
                                        current.coord._duplicate(),
                                    true);
                }

                //$ This flag was set to false.
                // Surely this subordinate is temporary?

            } else {

                // If there already is a subordinate, then ensure
                // that it knows it is not a temporary Coordinator.
                subordinate.setPermanent();

            }

            // Create a new Control object for the transaction.
            // We do not create a local Terminator

            if (Configuration.isLocalFactory()) {
                result = (Control) new ControlImpl(null, subordinate, globalTID,
                                     new Long(subordinate.getLocalTID())
                                    );
            } else {
                result = new ControlImpl(null, subordinate, globalTID,
                                     new Long(subordinate.getLocalTID())
                                    ).object();
            }

        } catch (Throwable exc) {

            // If any exception was thrown during that lot, then we
            // have failed to create a subordinate.  Do something drastic.
			_logger.log(Level.SEVERE,"jts.unable_to_create_subordinate_coordinator");
			 String msg = LogFormatter.getLocalizedMessage(_logger,
				 					  "jts.unable_to_create_subordinate_coordinator");
			 throw  new org.omg.CORBA.INTERNAL(msg);
        }

        return result;
    
public Controlrecreate(GlobalTID tid, int timeout)
Creates the Coordinator, Control and Terminator objects for a transaction based on the Xid object passed in.

param
xid Xid object containing a transaction context.
return
The Control object for the new transaction.
exception
SystemException An error occurred.


        // If the transaction service is not active, throw an exception.
        if (!active) {
            NO_PERMISSION exc =
                new NO_PERMISSION(0, CompletionStatus.COMPLETED_NO);
            throw exc;
        }

        // First check whether there is already a local subordinate
        // for the given transaction.
        CoordinatorImpl subordinate = RecoveryManager.getCoordinator(tid);
        Control result = null;

        // If there is no subordinate, then we must import the transaction.
        // We first must make sure that resync is not in progress.
        if (subordinate == null) {
            RecoveryManager.waitForResync();
            subordinate = RecoveryManager.getCoordinator(tid);
        }

        // If there is no local subordinate, then for each OMGtid
        // in the context, make sure there is a local
        // Coordinator set up in this process - required for
        // AIX, where we need to ensure every  ancestor has a locally created
        // transaction.  When we have threading on AIX this will not
        // be absolutely necessary, but will still be desirable.

        try {
            if (subordinate == null) {
                // If there are no ancestors, but the subordinate
                // does not already exist, create a top-level subordinate.
                // Use a duplicate of the proxy to allow the context
                // to be fully destroyed.
                subordinate = new TopCoordinator(
                                timeout, tid, new TxInflowCoordinator(),
                                true);
            } else {
                Status status = subordinate.get_status();
                if ((status != Status.StatusMarkedRollback) &&
                        (status != Status.StatusActive)) {
                    throw new INVALID_TRANSACTION("tx completion in-progress");           
                }
                // If there already is a subordinate, then ensure
                // that it knows it is not a temporary Coordinator.
                subordinate.setPermanent();
            }

            // Create a new Control object for the transaction.
            // We do not create a local Terminator.
            if (Configuration.isLocalFactory()) {
                result = (Control) new ControlImpl(null, subordinate, tid,
                                     new Long(subordinate.getLocalTID())
                                    );
            } else {
                result = new ControlImpl(null, subordinate, tid,
                                     new Long(subordinate.getLocalTID())
                                    ).object();
            }
        } catch (Throwable exc) {
            // If any exception was thrown during that lot, then we
            // have failed to create a subordinate.
			 _logger.log(Level.WARNING,"jts.unable_to_create_subordinate_coordinator");
             String msg = LogFormatter.getLocalizedMessage(_logger,
                                        "jts.unable_to_create_subordinate_coordinator");
            // ErrorLog.error(Messages.SUBORDINATE_CREATE_FAILED, null, true);
            INTERNAL intExc = new INTERNAL(msg);
            //INTERNAL intExc = new INTERNAL("tx recreate failed");
            intExc.initCause(exc);
            throw intExc;
        }

        return result;
	
static final synchronized com.sun.jts.CosTransactions.TransactionFactoryImplservant(TransactionFactory factory)
Returns the TransactionFactoryImpl which serves the given object.

param
The CORBA Object.
return
The TransactionFactoryImpl object which serves it.
see

        TransactionFactoryImpl result = null;

        // we will not be able to obtain the
        // servant from our local POA for a proxy factory object.
        // so return null
        if (factory != null && Configuration.getProxyChecker().isProxy(factory)) {
            return result;
        }

        if (factory instanceof TransactionFactoryImpl ) {
            result = (TransactionFactoryImpl) factory;
        } else if (poa != null) {
            try {
                result = (TransactionFactoryImpl) poa.reference_to_servant(factory);
                if( result.thisRef == null )
                    result.thisRef = factory;
            } catch( Exception exc ) {
				_logger.log(Level.WARNING,"jts.cannot_locate_servant",
                        "TransactionFactory");
            }
        }

        return result;