FileDocCategorySizeDatePackage
Coordinator.javaAPI DocExample11179Tue May 29 16:57:18 BST 2007com.sun.xml.ws.tx.coordinator

Coordinator

public abstract class Coordinator extends Object
This class encapsulates a coordinated activity.

Whenever a client (participant) registers for the activity, a {@link Registrant} is constructed and managed by this class.

author
Ryan.Shoemaker@Sun.COM
version
$Revision: 1.8.2.1 $
since
1.0

Fields Summary
private final CoordinationContextInterface
context
private final com.sun.xml.ws.tx.webservice.member.coord.CreateCoordinationContextType
request
private final com.sun.xml.ws.tx.common.ActivityIdentifier
id
private static final Timer
expirationTimer
Timer to manage expiration of registrants
private ExpirationTask
expirationTask
private boolean
expired
private static com.sun.xml.ws.tx.common.TxLogger
logger
Constructors Summary
public Coordinator(CoordinationContextInterface context, com.sun.xml.ws.tx.webservice.member.coord.CreateCoordinationContextType request)
Construct a new Coordinator object from the specified context and soap request.

param
context The coordination context
param
request The soap request


                               
           
        this.context = context;
        this.request = request;

        this.id = new ActivityIdentifier(context.getIdentifier());

        if (logger.isLogging(Level.FINER)) {
            logger.finer("Coordinator constructor", "New Coordinator created for activity: " + context.getIdentifier());
        }

        if (context.getExpires() != 0L) {
            // start a expiration timer task if necessary
            if (logger.isLogging(Level.FINER)) {
                logger.finer("Coordinator constructor", "Starting expiration task for activity: "
                        + context.getIdentifier() + " will expire in " + context.getExpires() + "ms");
            }
            expirationTask = new ExpirationTask(this);
            expirationTimer.schedule(expirationTask, context.getExpires());
        }
    
public Coordinator(CoordinationContextInterface context)
Construct a new Coordinator object from the specified context.

This constructor will be the main entry point for activity within the AppServer.

param
context The coordination context

        this(context, null);
    
Methods Summary
public abstract voidaddRegistrant(Registrant registrant, javax.xml.ws.WebServiceContext wsContext)
Add the specified Registrant to the list of registrants for this coordinated activity.

param
registrant The {@link Registrant}
param
wsContext the web service context of the incoming message or null if it isn't available

public abstract booleanexpirationGuard()
Sub classes will implement this method to indicate whether or not they are subject to expiration.

return
true if the coordinator should NOT expire, false otherwise.

public voidexpire()
Release resources held by this coordinator.

This method will be automatically invoked once if the activity has a non-zero expiration.

During expiration, the coordinator will iterate over all of its registrants and tell them to expire. Depending on their state, registrants will either expire or not. A coordinator will not completely expire until all of its registrants have expired.

        expired = true;
        if (logger.isLogging(Level.FINEST)) {
            logger.finest("Coordinator.expire", "attempting to expire coordinator: " + id.getValue());
        }
        if (!expirationGuard()) {
            if (logger.isLogging(Level.FINEST)) {
                logger.finest("Coordinator.expire", "forgetting resources for: " + id.getValue());
            }
            // TODO: send fault S4.4 wscoor:NoActivity

            forget();
        } else {
            if (logger.isLogging(Level.FINEST)) {
                logger.finest("Coordinator.expire", "expiration was guarded, returning without expiration");
            }
        }
    
public voidforget()
Release all resources associated with this coordinator

        if (expirationTask != null){
            expirationTask.cancel();
            expirationTask = null;
        }
        CoordinationManager.getInstance().removeCoordinator(this.id.getValue());
    
public CoordinationContextInterfacegetContext()
Get the coordination context associated with this coordinated activity

return
The coordination context

        return context;
    
public abstract javax.xml.ws.EndpointReferencegetCoordinatorProtocolServiceForRegistrant(Registrant r)
Return the Coordinator Protocol Service EPR for registrant r.

param
r registrant
return
the CPS EPT for the specified registrant

public longgetExpires()
Get the expiration value

return
The expiration value

        return context.getExpires();
    
public com.sun.xml.ws.tx.common.IdentifiergetId()
Get the {@link ActivityIdentifier} object.

This object can be used when it is necessary to insert the id as a ReferenceParameter in a soap message

return
The activity id object

        return id;
    
public java.lang.StringgetIdValue()
Get the activity id value

return
The activity id value

        return id.getValue();
    
public abstract RegistrantgetRegistrant(java.lang.String id)
Get the registrant with the specified id or null if it does not exist.

param
id the registrant id
return
the Registrant object or null if the id does not exist

public abstract java.util.ListgetRegistrants()
Get the list of {@link Registrant}s for this coordinated activity.

The returned list is unmodifiable (read-only). Add new Registrants with the {@link #addRegistrant(Registrant,WebServiceContext)} api instead.

return
the list of Registrant objects

public com.sun.xml.ws.tx.webservice.member.coord.CreateCoordinationContextTypegetRequest()
Get the SOAP request associated with this coordinated activity, if it exists.

return
The original SOAP request (createCoordinationContext) or null if it doesn't exist.

        return request;
    
public booleanisExpired()

        return expired;
    
public booleanisSubordinate()
Return true iff this coordinator is delegating to a root coordinator

return
true iff this coordinator is delegating to a root coordinator

        return context.getRootRegistrationService() != null;
    
public booleanregisterWithRootRegistrationService(Registrant r)
Return true iff registrant should register with its root registration service.

Enables local participants to be cached with coordinator locally when this method returns true.

param
r restistrant
return
Return true iff registrant should register with its root registration service

        return false;
    
public abstract voidremoveRegistrant(java.lang.String id)
Remove the registrant with the specified id

param
id the registrant id

public voidsetExpired(boolean expired)

        this.expired = expired;
    
public voidsetExpires(long i)

        if (context != null) {
            context.setExpires(i);
        }