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

TerminatorImpl

public class TerminatorImpl extends TerminatorPOA implements Terminator
The TerminatorImpl interface is our implementation of the standard Terminator interface. It provides operations to complete a transaction, either requesting commitment, or demanding rollback. The TerminatorImpl in this design should be a pseudo-object, as we do not want its reference to be passed to other processes, and we always want it to be created locally.
version
0.01
author
Simon Holdsworth, IBM Corporation
see

Fields Summary
private static POA
poa
private org.omg.CosTransactions.Terminator
thisRef
CoordinatorTerm
coordTerm
ControlImpl
control
static Logger
_logger
Constructors Summary
TerminatorImpl()
Default TerminatorImpl constructor.

param
return
see

               
     
TerminatorImpl(CoordinatorImpl coordinator, boolean subtran)
Creates and initialises a new TerminatorImpl, given the Coordinator object for the transaction, and a flag to indicate whether the TerminatorImpl represents a subtransaction.

param
coordinator The Coordinator for the transaction.
param
subtran A flag indicating whether the transaction is a child.
return
see


        // Initialise the instance variables.

         coordTerm = new CoordinatorTerm(coordinator, subtran);
    
Methods Summary
private voidPreCompletionCheck()
This implements the checked behaviour for threads calling the terminator object's completion methods directly.


        /* This method has been newly added (Ram J) */

        StatusHolder status = new StatusHolder();
        Long localTID = new Long(control.getLocalTID(status));

        // check if the transaction is active, else throw exception

        if (status.value != Status.StatusActive) {

            if( status.value == Status.StatusRolledBack) {
                TRANSACTION_ROLLEDBACK exc =
                    new TRANSACTION_ROLLEDBACK(0,
                                               CompletionStatus.COMPLETED_NO);
                throw exc;
            }

            INVALID_TRANSACTION exc =
                new INVALID_TRANSACTION(MinorCode.Completed,
                                        CompletionStatus.COMPLETED_NO);
            throw exc;
        }

        // check if there is no outstanding requests, else throw exception
        // CHECK(Ram J) should a check for active thread associations
        // be done here as well ??
        if (control.isOutgoing()) {

            INVALID_TRANSACTION exc =
                new INVALID_TRANSACTION(MinorCode.DeferredActivities,
                                        CompletionStatus.COMPLETED_NO);
            throw exc;
        }
    
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 synchronized voidcommit(boolean reportHeuristics)
Requests that the transaction controlled by the Terminator object be committed. The commit is passed on the the CoordinatorTerm object. If the heuristic report flag is set, any heuristic exception raised by the root Coordinator is returned to the caller, otherwise any heuristic exception is discarded. This operation is part of the OMG interface and must not return any exceptions other than those defined in the OMG interface.

param
reportHeuristics Indicates whether heuristic exceptions should be passed to the caller.
return
exception
HeuristicHazard Heuristic action may have been taken by a participant in the transaction.
exception
HeuristicMixed Heuristic action has been taken by a participant in the transaction so part of the transaction has been rolled back.
exception
SystemException The operation failed.
see


        // for checked transaction behaviour (Ram J)
        PreCompletionCheck();

        // Try to commit the transaction.  If the client does not want a
        // heuristic report, then the transaction can be completed promptly.

        // If the client does not want heuristic reporting, and an
        // exception was raised, and it is a Heuristic exception, forget it.
        // Any other exception that is raised is returned to the client.

        try {
            coordTerm.commit(!reportHeuristics);
        } catch (HeuristicMixed exc) {
            if (reportHeuristics) {
                control.destroy(); // added (Ram J) for memory Leak fix
                throw exc;
            }
        } catch (HeuristicHazard exc) {
            if (reportHeuristics) {
                control.destroy(); // added (Ram J) for memory Leak fix
                throw exc;
            }
        } catch (TRANSACTION_ROLLEDBACK exc) {
            control.destroy(); // added (Ram J) for memory Leak fix
            throw exc;
        } catch(LogicErrorException exc) {
            control.destroy(); // added (Ram J) for memory Leak fix
            INTERNAL ex2 = new INTERNAL(MinorCode.LogicError,
                                        CompletionStatus.COMPLETED_NO);
            throw ex2;
        } catch (INTERNAL exc) { // added (Ram J) percolate up system excs
            control.destroy();
            throw (INTERNAL) exc;
        }

        control.destroy(); // added (Ram J) for memory Leak fix
    
final synchronized voiddestroy()
Destroys the TerminatorImpl object.

param
return
see

        if (poa != null && thisRef != null) {
            try {
                poa.deactivate_object(poa.reference_to_id(thisRef));
                thisRef = null;
            } catch (Exception exc) {
				_logger.log(Level.WARNING,"jts.object_destroy_error","Terminator");
            }
        }

        //finalize();
    
final synchronized java.lang.Terminatorobject()
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 =
                    TerminatorHelper.narrow(poa.servant_to_reference(this));
                //thisRef = (Terminator) this;
            } catch(ServantAlreadyActive saexc) {
				_logger.log(Level.SEVERE,"jts.create_terminator_object_error",saexc);
				String msg = LogFormatter.getLocalizedMessage(_logger,
										 "jts.create_terminator_object_error");
				throw  new org.omg.CORBA.INTERNAL(msg);
            } catch(ServantNotActive snexc) {
				_logger.log(Level.SEVERE,"jts.create_terminator_object_error",snexc);
				String msg = LogFormatter.getLocalizedMessage(_logger,
										 "jts.create_terminator_object_error");
				throw  new org.omg.CORBA.INTERNAL(msg);
            } catch(Exception exc) {
				_logger.log(Level.SEVERE,"jts.create_terminator_object_error",exc);
				String msg = LogFormatter.getLocalizedMessage(_logger,
										 "jts.create_terminator_object_error");
				throw  new org.omg.CORBA.INTERNAL(msg);
            }
        }

        return thisRef;
    
public voidrollback()
Demands that the transaction represented by the Terminator object be rolled back. No heuristics are reported by this operation so if the root Coordinator raises a heuristic exception, it is cleared before the operation returns to the caller. This operation is part of the OMG interface and must not return any exceptions other than those defined in the OMG interface.

param
return
exception
SystemException The operation failed.
see


        // for checked transaction behaviour (Ram J)
        PreCompletionCheck();

        // Roll the transaction back.
        // If a Heuristic exception was raised, forget it.
        // Any other exception that is raised is returned to the client.

        try {
            coordTerm.rollback();
        } catch (HeuristicMixed exc) {
            control.destroy(); // added (Ram J) for memory Leak fix
        } catch (HeuristicHazard exc) {
            control.destroy(); // added (Ram J) for memory Leak fix
        } catch (TRANSACTION_ROLLEDBACK exc) {
            control.destroy(); // added (Ram J) for memory Leak fix
            throw exc;
        } catch (LogicErrorException exc) {
            control.destroy(); // added (Ram J) for memory Leak fix
            INTERNAL ex2 = new INTERNAL(MinorCode.LogicError,
                                        CompletionStatus.COMPLETED_NO);
            throw ex2;
        } catch (INTERNAL exc) { // added (Ram J) percolate up system excs
            control.destroy();
            throw (INTERNAL) exc;
        }

        control.destroy(); // added (Ram J) for memory Leak fix

    
voidsetControl(ControlImpl control)
sets the control object that points to this terminator.

param
control the control object this terminator belongs to.

        /* This method has been newly added (Ram J) */
        this.control = control;