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

Registrant

public abstract class Registrant extends Object
This class encapsulates a coordination registrant.

The coordination protocol implementations will extend this class and add protocol specific functionality.

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

Fields Summary
private com.sun.xml.ws.tx.webservice.member.coord.RegisterType
registerRequest
private final Coordinator
parent
private final com.sun.xml.ws.api.tx.Protocol
protocol
private EndpointReference
coordinatorProtocolService
private static long
nextId
private final com.sun.xml.ws.tx.common.RegistrantIdentifier
id
private static com.sun.xml.ws.tx.common.TxLogger
logger
private Boolean
registrationCompleted
private Semaphore
registrationCompletedGate
protected static final Map
outstandingRegistrants
private boolean
remoteCPS
Constructors Summary
public Registrant(Coordinator parent, com.sun.xml.ws.tx.webservice.member.coord.RegisterType registerRequest)
Create a new registrant

param
registerRequest request
param
parent parent coordinator


                              
           
        this(parent, registerRequest.getProtocolIdentifier());
        this.registerRequest = registerRequest;
        // no need to add to outstanding registrants, the PPS is in registerRequest
    
protected Registrant(Coordinator parent, String protocolId)

        this(parent, Protocol.getProtocol(protocolId));
    
protected Registrant(Coordinator parent, com.sun.xml.ws.api.tx.Protocol protocol)
Create a Registratant with its coordinator parent for protocol.

param
parent parent coordinator
param
protocol activity protocol

        id = new RegistrantIdentifier(Long.toString(nextId++));

        this.parent = parent;
        this.protocol = protocol;
        if (parent.isSubordinate()) {
            outstandingRegistrants.put(getIdValue(), this);
            registrationCompleted = false;
            registrationCompletedGate = new Semaphore(0); // initially closed
        } else {
            if (registerRequest == null) {
                this.setParticpantProtocolService(getLocalParticipantProtocolService());
            }
        }
    
Methods Summary
public abstract voidforget()
Forget all resources associated with this Registrant

public CoordinatorgetCoordinator()
Get the parent coordinator for this Registrant

return
the parent coordinator

        return parent;
    
public synchronized javax.xml.ws.EndpointReferencegetCoordinatorProtocolService()

        return coordinatorProtocolService;
    
public com.sun.xml.ws.tx.common.IdentifiergetId()

        return id;
    
public java.lang.StringgetIdValue()

        return id.getValue();
    
public abstract javax.xml.ws.EndpointReferencegetLocalParticipantProtocolService()

public static com.sun.xml.ws.tx.coordinator.RegistrantgetOutstandingRegistrant(java.lang.String id)
Lookup outstanding registrant by id

param
id registrant id
return
the outstanding registrant or null if it doesn't exist


                            
    
          
        return outstandingRegistrants.get(id);
    
public javax.xml.ws.EndpointReferencegetParticipantProtocolService()

        return (registerRequest == null) ?
                getLocalParticipantProtocolService() :
                registerRequest.getParticipantProtocolService();
    
public com.sun.xml.ws.api.tx.ProtocolgetProtocol()
Get the protocol for this registrant

return
the protocol identifier

        return protocol;
    
private java.lang.StringgetProtocolIdentifier()

        switch (protocol) {
            case COMPLETION:
                return COMPLETION.getUri();
            case DURABLE:
                return DURABLE.getUri();
            case VOLATILE:
                return VOLATILE.getUri();
            default:
                return UNKNOWN.getUri();
        }
    
public com.sun.xml.ws.tx.webservice.member.coord.RegisterTypegetRegisterRequest()
Get the SOAP register request

return
the SOAP register message

        return registerRequest;
    
public booleanisRegistrationCompleted()

        return registrationCompleted;
    
public booleanisRemoteCPS()

        return remoteCPS;
    
public voidregister()

        RegistrationManager.getInstance().register(parent, this);
    
public static com.sun.xml.ws.tx.coordinator.RegistrantremoveOutstandingRegistrant(java.lang.String id)
Remove outstanding registrant by its id.

param
id registrant id
return
the outstanding registrant or null if it doesn't exist

        return outstandingRegistrants.remove(id);
    
public synchronized voidsetCoordinatorProtocolService(javax.xml.ws.EndpointReference cps)
Set the coordinator protocol service received by coor:registerResponse.

param
cps cps epr

        coordinatorProtocolService = cps;
        setRegistrationCompleted(true);
    
public voidsetParticpantProtocolService(javax.xml.ws.EndpointReference pps)

        if (registerRequest == null) {
            registerRequest = new RegisterType();
        }
        registerRequest.setProtocolIdentifier(this.getProtocolIdentifier());
        registerRequest.setParticipantProtocolService((MemberSubmissionEndpointReference) pps);
    
public synchronized voidsetRegistrationCompleted(boolean value)

        registrationCompleted = value;
        
        if (isRemoteCPS()) {
            if (logger.isLogging(Level.FINEST)) {
                logger.finest(
                        "setRegistrationCompleted(" + value + ")",
                        "semaphore has " + registrationCompletedGate.availablePermits() + " permits.");
            }
            if (value) {
                assert (registrationCompletedGate.availablePermits() <= 0);
                registrationCompletedGate.release();
                if (logger.isLogging(Level.FINEST)) {
                    logger.finest(
                            "setRegistrationCompleted(" + value + ")",
                            "released a permit, semaphore now has " + registrationCompletedGate.availablePermits() + " permits.");
                }
            }
        }
    
public voidsetRemoteCPS(boolean value)


         
        remoteCPS = value;
    
public booleanwaitForRegistrationResponse()
wait for a registerResponse to arrive - this method is only used with remote CPSs

return
true if <RegistrationResponse> was received, false if there was a timeout.

        try {
            if(logger.isLogging(Level.FINEST)) {
                logger.finest("waitForRegistrationResponse", "semaphore should have 0 permits. actual available permits: " + registrationCompletedGate.availablePermits());
                assert (registrationCompletedGate.availablePermits() <= 0);
                logger.finest("waitForRegistrationResponse", "Waiting for registration response.  Calling tryAcquire()...");
            }
            return !registrationCompletedGate.tryAcquire(1, 40, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            e.printStackTrace();
            return false;
        }