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

CoordinationManager

public final class CoordinationManager extends Object
This singleton class is responsible for managing coordinated activities for the entire appserver.

Whenever a new coordinated activity is started, a new {@link Coordinator} object is constructed and managed by this class.

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

Fields Summary
private static final CoordinationManager
instance
private static final Map
coordinators
private static com.sun.xml.ws.tx.common.TxLogger
logger
Constructors Summary
private CoordinationManager()
private constructor for singleton


             
      
    
Methods Summary
private CoordinatorcreateCoordinator(CoordinationContextInterface context, com.sun.xml.ws.tx.webservice.member.coord.CreateCoordinationContextType contextRequest)
create a {@link Coordinator} from either the given context or the given request.

One of these parameters MUST be null, one of them MUST be non-null.

param
context coordination context
param
contextRequest createCoordinationContext soap msg
return
a Coordinator


        assert((context == null) ^ (contextRequest == null));  // xor

        if (logger.isLogging(Level.FINER)) {
            logger.entering("CoordinationManager.createCoordinator");
        }

        final String coordType;
        if (contextRequest == null) {
            coordType = context.getCoordinationType();
        } else {
            coordType = contextRequest.getCoordinationType();
        }

        if (WSAT_2004_PROTOCOL.equals(coordType)) {
            final Coordinator coord;
            if (contextRequest == null) {
                coord = context.getRootRegistrationService() == null ?
                        new ATCoordinator(context) : new ATSubCoordinator(context);
            } else {
                coord = contextRequest.getCurrentContext() == null ?
                        new ATCoordinator(ContextFactory.createContext(contextRequest), contextRequest) :
                        new ATSubCoordinator(ContextFactory.createContext(contextRequest), contextRequest);
            }
            if (logger.isLogging(Level.FINEST)) {
                logger.finest("CoordinationManager.createCoordinator id=", coord.getIdValue());
            }
            if (logger.isLogging(Level.FINER)) {
                logger.exiting("CoordinationManager.createCoordinator");
            }
            return coord;
        } else if (WSAT_OASIS_NSURI.equals(coordType)) {
            throw new UnsupportedOperationException(
                    LocalizationMessages.OASIS_UNSUPPORTED_3000()
            );
        } else {
            throw new UnsupportedOperationException(
                    LocalizationMessages.UNRECOGNIZED_COORDINATION_TYPE_3001(coordType)
            );
        }
    
private CoordinatorcreateSubordinateCoordinator(CoordinationContextInterface context, com.sun.xml.ws.tx.webservice.member.coord.CreateCoordinationContextType contextRequest)
Create a {@link Coordinator} that delegates to a root coordinator that is probably on a remote system not under our control.

One of these parameters MUST be null, one of them MUST be non-null.

param
context the original coordination context generated by the root coordinator
param
contextRequest the original createCordinationContext request message
return
a new subordinate coordinator that will delegate for our participants


        assert((context == null) ^ (contextRequest == null));  // xor

        if (logger.isLogging(Level.FINER)) {
            logger.entering("CoordinationManager.createSubordinateCoordinator");
        }

        if (context == null) {
            if (logger.isLogging(Level.FINER)) {
                logger.exiting("CoordinationManager.createSubordinateCoordinator");
            }
            // in this case, the context should already have the registration EPRs initialized
            // properly, so we don't have to swap - just create a new coordinator
            return createCoordinator(null, contextRequest);
        } else {
            // replace the registration service EPR with our own, but remember the EPR of the
            // root coordinator's registration EPR for delegation.
            context.setRootCoordinatorRegistrationService(context.getRegistrationService());

            // delegate
            final Coordinator coord = createCoordinator(context, null);
            context.setRegistrationService(RegistrationManager.newRegistrationEPR((ActivityIdentifier) coord.getId()));
            if (logger.isLogging(Level.FINER)) {
                logger.exiting("CoordinationManager.createSubordinateCoordinator");
            }
            return coord;
        }
    
public CoordinatorgetCoordinator(java.lang.String id)
Get the {@link Coordinator} object with the given coordination id

param
id the coordination context id
return
the Coordinator object or null if the id doesn't exist

        return coordinators.get(id);
    
public static com.sun.xml.ws.tx.coordinator.CoordinationManagergetInstance()
Return the singleton instance of CoordinationManager.

return
the CoordinationManager instance

        return instance;
    
public CoordinatorlookupOrCreateCoordinator(com.sun.xml.ws.tx.webservice.member.coord.CreateCoordinationContextType contextRequest)
Create a {@link Coordinator} object from the incoming request and add it to the list of managed activities. The actual type of the {@link Coordinator} object created will depend on the {@link com.sun.xml.ws.api.tx.Protocol} specified in the contextRequest parameter.

This method is invoked when we receive a createCoordinationContext soap request.

param
contextRequest the incoming wscoor:createCoordinationContext message
return
the coordinator

        Coordinator c;
        if (contextRequest.getCurrentContext() == null) {
            c = createCoordinator(null, contextRequest);
        } else {
            c = createSubordinateCoordinator(null, contextRequest);
        }
        putCoordinator(c);
        return c;
    
public CoordinatorlookupOrCreateCoordinator(CoordinationContextInterface context)
Lookup if coordinator exists for context, if not, create a {@link Coordinator} object from the given coordination context and add it to the list of managed activities. The actual type of the {@link Coordinator} object created will depend on the protocol identifier contained in the context.

This method is used for direct private invocation within the appserver.

param
context the coordination context
return
the coordinator

        Coordinator c = getCoordinator(context.getIdentifier());
        if (c == null) {
            // If registration service EPR is not created locally, make this a subordinate coordinator
            if (RegistrationManager.getRegistrationCoordinatorStatefulWebServiceManager().resolve(context.getRegistrationService()) == null) {
                c = createSubordinateCoordinator(context, null);
            } else {
                c = createCoordinator(context, null);
            }
        }
        putCoordinator(c);
        return c;
    
public voidputCoordinator(Coordinator coordinator)
Add the specified {@link Coordinator} object to the list of managed activities.

TODO: what about duplicate keys or entries?

param
coordinator coordinator

        coordinators.put(coordinator.getIdValue(), coordinator);
        if (logger.isLogging(Level.FINEST)) {
            logger.finest("putCoordinator", "add activity id:" + coordinator.getIdValue());
        }
    
public voidremoveCoordinator(java.lang.String id)
Remove the specified {@link Coordinator} object from the list of managed activities.

param
id activity id

        final Coordinator c = coordinators.remove(id);
        if(c!=null) {
            c.forget();
        }
        if (logger.isLogging(Level.FINEST)) {
            logger.finest("removeCoordinator", "remove activity id:" + id);
        }