use of com.arjuna.wst11.messaging.engines.ParticipantEngine in project narayana by jbosstm.
the class ContextFactoryImple method create.
/**
* Creates a coordination context.
*
* @param coordinationTypeURI
* the coordination type uri
* @param expires
* the expire date/time for the returned context, can be null
* @param currentContext
* the current context, can be null
*
* @return the created coordination context
*
* @throws com.arjuna.wsc.InvalidCreateParametersException
* if a parameter passed is invalid this activity identifier.
*/
public CoordinationContext create(final String coordinationTypeURI, final Long expires, final CoordinationContextType currentContext, final boolean isSecure) throws InvalidCreateParametersException {
if (coordinationTypeURI.equals(AtomicTransactionConstants.WSAT_PROTOCOL)) {
try {
if (currentContext == null) {
// make sure no transaction is currently associated
_coordManager.suspend();
final int timeout;
if (expires == null) {
timeout = 0;
} else {
final long timeoutVal = expires.longValue();
timeout = (timeoutVal > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) timeoutVal);
}
_coordManager.begin(ArjunaContextImple.serviceType, timeout);
final ArjunaContextImple arjunaContext = ArjunaContextImple.getContext();
final ServiceRegistry serviceRegistry = PrivilegedServiceRegistryFactory.getInstance().getServiceRegistry();
final String registrationCoordinatorURI = serviceRegistry.getServiceURI(CoordinationConstants.REGISTRATION_SERVICE_NAME, isSecure);
final CoordinationContext coordinationContext = new CoordinationContext();
coordinationContext.setCoordinationType(coordinationTypeURI);
CoordinationContextType.Identifier identifier = new CoordinationContextType.Identifier();
identifier.setValue("urn:" + arjunaContext.getTransactionIdentifier());
coordinationContext.setIdentifier(identifier);
final int transactionExpires = arjunaContext.getTransactionExpires();
if (transactionExpires > 0) {
Expires expiresInstance = new Expires();
expiresInstance.setValue(transactionExpires);
coordinationContext.setExpires(expiresInstance);
}
W3CEndpointReference registrationCoordinator = getRegistrationCoordinator(registrationCoordinatorURI, arjunaContext);
coordinationContext.setRegistrationService(registrationCoordinator);
/*
* Now add the registrar for this specific coordinator to the
* mapper.
*/
_coordManager.enlistSynchronization(new CleanupSynchronization(_coordManager.identifier().toString(), _theRegistrar));
/*
* TODO Uughh! This does a suspend for us! Left over from original
* WS-AS stuff.
*
* TODO
* REFACTOR, REFACTOR, REFACTOR.
*/
_theRegistrar.associate();
return coordinationContext;
} else {
// we need to create a subordinate transaction and register it as both a durable and volatile
// participant with the registration service defined in the current context
SubordinateATCoordinator subTx = (SubordinateATCoordinator) createSubordinate();
// hmm, need to create wrappers here as the subTx is in WSCF which only knows
// about WSAS and WS-C and the participant is in WS-T
String vtppid = subTx.getVolatile2PhaseId();
String dtppid = subTx.getDurable2PhaseId();
Volatile2PCParticipant vtpp = new SubordinateVolatile2PCStub(subTx);
Durable2PCParticipant dtpp = new SubordinateDurable2PCStub(subTx);
final String messageId = MessageId.getMessageId();
W3CEndpointReference participant;
W3CEndpointReference coordinator;
participant = getParticipant(vtppid, isSecure);
coordinator = RegistrationCoordinator.register(currentContext, messageId, participant, AtomicTransactionConstants.WSAT_SUB_PROTOCOL_VOLATILE_2PC);
ParticipantProcessor.getProcessor().activateParticipant(new ParticipantEngine(vtpp, vtppid, coordinator), vtppid);
participant = getParticipant(dtppid, isSecure);
coordinator = RegistrationCoordinator.register(currentContext, messageId, participant, AtomicTransactionConstants.WSAT_SUB_PROTOCOL_DURABLE_2PC);
ParticipantProcessor.getProcessor().activateParticipant(new ParticipantEngine(dtpp, dtppid, coordinator), dtppid);
// ok now create the context
final ServiceRegistry serviceRegistry = PrivilegedServiceRegistryFactory.getInstance().getServiceRegistry();
final String registrationCoordinatorURI = serviceRegistry.getServiceURI(CoordinationConstants.REGISTRATION_SERVICE_NAME, isSecure);
final CoordinationContext coordinationContext = new CoordinationContext();
coordinationContext.setCoordinationType(coordinationTypeURI);
CoordinationContextType.Identifier identifier = new CoordinationContextType.Identifier();
String txId = subTx.get_uid().stringForm();
identifier.setValue("urn:" + txId);
coordinationContext.setIdentifier(identifier);
Expires expiresInstance = currentContext.getExpires();
final long transactionExpires = (expiresInstance != null ? expiresInstance.getValue() : 0);
if (transactionExpires > 0) {
expiresInstance = new Expires();
expiresInstance.setValue(transactionExpires);
coordinationContext.setExpires(expiresInstance);
}
W3CEndpointReference registrationCoordinator = getRegistrationCoordinator(registrationCoordinatorURI, txId);
coordinationContext.setRegistrationService(registrationCoordinator);
// now associate the tx id with the sub transaction
_theRegistrar.associate(subTx);
return coordinationContext;
}
} catch (NoActivityException ex) {
ex.printStackTrace();
throw new InvalidCreateParametersException();
} catch (SystemException ex) {
ex.printStackTrace();
} catch (com.arjuna.mw.wsas.exceptions.WrongStateException ex) {
ex.printStackTrace();
throw new InvalidCreateParametersException();
} catch (Exception ex) {
// TODO handle properly
ex.printStackTrace();
}
} else {
wstxLogger.i18NLogger.warn_mwlabs_wst_at_Context11FactoryImple_1(AtomicTransactionConstants.WSAT_PROTOCOL, coordinationTypeURI);
throw new InvalidCreateParametersException(wstxLogger.i18NLogger.get_mwlabs_wst_at_Context11FactoryImple_3() + " < " + AtomicTransactionConstants.WSAT_PROTOCOL + ", " + coordinationTypeURI + " >");
}
return null;
}
use of com.arjuna.wst11.messaging.engines.ParticipantEngine in project narayana by jbosstm.
the class TransactionManagerImple method enlistForVolatileTwoPhase.
public void enlistForVolatileTwoPhase(Volatile2PCParticipant tpp, String id) throws WrongStateException, UnknownTransactionException, SystemException {
try {
final W3CEndpointReference participant = getParticipant(id, isCurrentContextSecure());
final W3CEndpointReference coordinator = registerParticipant(participant, AtomicTransactionConstants.WSAT_SUB_PROTOCOL_VOLATILE_2PC);
ParticipantProcessor.getProcessor().activateParticipant(new ParticipantEngine(tpp, id, coordinator), id);
} catch (com.arjuna.wsc.InvalidProtocolException ex) {
throw new SystemException(ex.toString());
} catch (com.arjuna.wsc.InvalidStateException ex) {
throw new WrongStateException();
} catch (com.arjuna.wsc.CannotRegisterException ex) {
// cause could actually be no activity or already registered
ex.printStackTrace();
throw new UnknownTransactionException();
}
}
use of com.arjuna.wst11.messaging.engines.ParticipantEngine in project narayana by jbosstm.
the class TransactionManagerImple method enlistForDurableTwoPhase.
public void enlistForDurableTwoPhase(Durable2PCParticipant tpp, String id) throws WrongStateException, UnknownTransactionException, SystemException {
try {
final W3CEndpointReference participant = getParticipant(id, isCurrentContextSecure());
final W3CEndpointReference coordinator = registerParticipant(participant, AtomicTransactionConstants.WSAT_SUB_PROTOCOL_DURABLE_2PC);
ParticipantProcessor.getProcessor().activateParticipant(new ParticipantEngine(tpp, id, coordinator), id);
} catch (com.arjuna.wsc.InvalidProtocolException ex) {
throw new SystemException(ex.toString());
} catch (com.arjuna.wsc.InvalidStateException ex) {
throw new WrongStateException();
} catch (com.arjuna.wsc.CannotRegisterException ex) {
// cause could actually be no activity or already registered
throw new UnknownTransactionException();
}
}
use of com.arjuna.wst11.messaging.engines.ParticipantEngine in project narayana by jbosstm.
the class ATInteropUtil method registerParticipant.
/**
* Register the participant in the specified coordination context.
* @param context The coordination context.
* @param participant The participant.
* @param id The participant id.
* @param protocol The sub protocol to register for.
* @return The participant engine.
* @throws Exception for errors.
*/
private static ParticipantEngine registerParticipant(final CoordinationContextType context, final Participant participant, final String id, final String protocol) throws Exception {
final W3CEndpointReference coordinator = RegistrationCoordinator.register(context, MessageId.getMessageId(), getParticipant(id), protocol);
final ParticipantEngine engine = new ParticipantEngine(participant, id, coordinator);
ParticipantProcessor.getProcessor().activateParticipant(engine, id);
return engine;
}
use of com.arjuna.wst11.messaging.engines.ParticipantEngine in project narayana by jbosstm.
the class ATParticipantProcessor method earlyReadonly.
/**
* Execute the EarlyReadonly
* @param map The current addressing context.
*
* @throws SoapFault11 for errors during processing
*/
public void earlyReadonly(final CoordinationContextType coordinationContext, final MAP map) throws SoapFault11 {
try {
final ParticipantEngine engine = ATInteropUtil.registerVolatile2PC(coordinationContext, new CommitVolatile2PCParticipant(), new Uid().toString());
ATInteropUtil.registerDurable2PC(coordinationContext, new CommitDurable2PCParticipant(), new Uid().toString());
engine.earlyReadonly();
} catch (final Throwable th) {
throw new SoapFault11(th);
}
}
Aggregations