use of com.arjuna.mwlabs.wscf.model.twophase.arjunacore.subordinate.SubordinateATCoordinator in project narayana by jbosstm.
the class BridgeWrapper method scan.
/**
* return a list of bridge wrappers for all recovered subordinate transactions with a given
* subordinate type
* @param subordinateType the subordinate type supplied in the original bridge wrapper create call
* which created the subordinate transaction.
* @return a possibly zero-length array of bridge wrappers for all recovered subordinate AT transactions
* with the given subordinate type or null if a subordinate coordinator recovery scan has not yet occurred
*/
public static BridgeWrapper[] scan(String subordinateType) {
// return null if not yet ready
XTSATRecoveryManager recoveryManager = XTSATRecoveryManager.getRecoveryManager();
if (!recoveryManager.isCoordinatorRecoveryStarted()) {
return null;
}
if (subordinateType == null || subordinateType.equals(SUBORDINATE_TX_TYPE_AT_AT)) {
return EMPTY_SCAN;
}
SubordinateATCoordinator[] coordinators = SubordinateATCoordinator.listRecoveredCoordinators();
int count = 0;
for (int i = 0; i < coordinators.length; i++) {
if (coordinators[i].getSubordinateType().equals(subordinateType)) {
count++;
}
}
if (count == 0) {
return EMPTY_SCAN;
}
BridgeWrapper[] result = new BridgeWrapper[count];
count = 0;
for (int i = 0; i < coordinators.length; i++) {
SubordinateATCoordinator coordinator = coordinators[i];
if (coordinator.getSubordinateType().equals(subordinateType)) {
BridgeWrapper bridgeWrapper = new BridgeWrapper();
bridgeWrapper.context = null;
bridgeWrapper.coordinator = coordinator;
bridgeWrapper.id = coordinator.get_uid().stringForm();
bridgeWrapper.subordinateType = coordinator.getSubordinateType();
result[count++] = bridgeWrapper;
}
}
return result;
}
use of com.arjuna.mwlabs.wscf.model.twophase.arjunacore.subordinate.SubordinateATCoordinator 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.mwlabs.wscf.model.twophase.arjunacore.subordinate.SubordinateATCoordinator in project narayana by jbosstm.
the class ContextFactoryImple method createBridgedTransaction.
/**
* create a bridged to subordinate WS-AT 1.1 transaction, associate it with the registrar and create and return
* a coordination context for it. n.b. this is a private, behind-the-scenes method for use by the JTA-AT
* transaction bridge code.
* @param subordinateType a unique string which groups subordinates for the benefit of their parent tx/app and
* allows them to be identified and retrieved as a group during recovery
* @param expires the timeout for the bridged to AT transaction
* @param isSecure true if the registration cooridnator URL should use a secure address, otherwise false.
* @return a coordination context for the bridged to transaction
*/
public BridgeTxData createBridgedTransaction(String subordinateType, final Long expires, final boolean isSecure) {
// we must have a type and it must not be the AT-AT subordinate type
if (subordinateType == null || SubordinateATCoordinator.SUBORDINATE_TX_TYPE_AT_AT.equals(subordinateType)) {
return null;
}
// 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 = null;
try {
subTx = (SubordinateATCoordinator) createSubordinate(subordinateType);
} catch (NoActivityException e) {
// will not happen
return null;
} catch (InvalidProtocolException e) {
// will not happen
return null;
} catch (SystemException e) {
// may happen
return null;
}
// 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(AtomicTransactionConstants.WSAT_PROTOCOL);
CoordinationContextType.Identifier identifier = new CoordinationContextType.Identifier();
String txId = subTx.get_uid().stringForm();
identifier.setValue("urn:" + txId);
coordinationContext.setIdentifier(identifier);
if (expires != null && expires.longValue() > 0) {
Expires expiresInstance = new Expires();
expiresInstance.setValue(expires);
coordinationContext.setExpires(expiresInstance);
}
W3CEndpointReference registrationCoordinator = getRegistrationCoordinator(registrationCoordinatorURI, txId);
coordinationContext.setRegistrationService(registrationCoordinator);
try {
_theRegistrar.associate(subTx);
} catch (Exception e) {
// will not happen
}
BridgeTxData bridgeTxData = new BridgeTxData();
bridgeTxData.context = coordinationContext;
bridgeTxData.coordinator = subTx;
bridgeTxData.identifier = txId;
return bridgeTxData;
}
use of com.arjuna.mwlabs.wscf.model.twophase.arjunacore.subordinate.SubordinateATCoordinator in project narayana by jbosstm.
the class CoordinatorControl method createSubordinate.
/**
* Create a subordinate transaction, i.e., one which can be driven
* through prepare, commit and rollback. Such a transaction is not
* interposed with any parent transaction because the parent may
* be physically remote from the child. Such interposition is the
* responsibility of the invoker.
*
* @return the subordinate transaction. The transaction is not
* associated with the thread and is not interposed. It is running.
*
* @throws SystemException throw if any error occurs.
*/
public final ATCoordinator createSubordinate(String subordinateType) throws SystemException {
try {
SubordinateATCoordinator coord = new SubordinateATCoordinator(subordinateType);
int status = coord.start(null);
if (status != ActionStatus.RUNNING) {
throw new BegunFailedException(wscfLogger.i18NLogger.get_model_twophase_arjunacore_CoordinatorControl_1() + ActionStatus.stringForm(status));
} else {
return coord;
}
} catch (SystemException ex) {
throw ex;
} catch (Exception ex) {
throw new UnexpectedException(ex.toString());
}
}
use of com.arjuna.mwlabs.wscf.model.twophase.arjunacore.subordinate.SubordinateATCoordinator in project narayana by jbosstm.
the class RegistrarImple method register.
/**
* Registers the interest of participant in a particular protocol.
*
* @param participantProtocolService
* the address of the participant protocol service
* @param protocolIdentifier
* the protocol identifier
*
* @return the PortReference of the coordinator protocol service
*
* @throws com.arjuna.wsc.AlreadyRegisteredException
* if the participant is already registered for this
* coordination protocol under this activity identifier
* @throws com.arjuna.wsc.InvalidProtocolException
* if the coordination protocol is not supported
* @throws com.arjuna.wsc.InvalidStateException
* if the state of the coordinator no longer allows registration
* for this coordination protocol
* @throws com.arjuna.wsc.NoActivityException
* if the activity does not exist.
*/
/*
* TODO
*
* See comment at head of class definition. We shouldn't have to rely on
* thread-to-activity association to register a participant. We currently do
* because the code is based on old WS-CAF models that are no longer
* applicable. This needs updating!
*/
public W3CEndpointReference register(final W3CEndpointReference participantProtocolService, final String protocolIdentifier, final InstanceIdentifier instanceIdentifier, final boolean isSecure) throws AlreadyRegisteredException, InvalidProtocolException, InvalidStateException, NoActivityException {
Object tx = _hierarchies.get(instanceIdentifier.getInstanceIdentifier());
if (tx instanceof SubordinateATCoordinator)
return registerWithSubordinate((SubordinateATCoordinator) tx, participantProtocolService, protocolIdentifier, isSecure);
ActivityHierarchy hier = (ActivityHierarchy) tx;
if (hier == null)
throw new NoActivityException();
try {
_coordManager.resume(hier);
} catch (com.arjuna.mw.wsas.exceptions.InvalidActivityException ex) {
throw new NoActivityException();
} catch (SystemException ex) {
throw new InvalidProtocolException();
}
if (AtomicTransactionConstants.WSAT_SUB_PROTOCOL_DURABLE_2PC.equals(protocolIdentifier)) {
// enlist participant that wraps the requester URI.
final String participantId = "D" + new Uid().stringForm();
try {
final Durable2PCStub participantStub = new Durable2PCStub(participantId, participantProtocolService);
_coordManager.enlistParticipant(new DurableTwoPhaseCommitParticipant(participantStub, participantId));
_coordManager.suspend();
return getCoordinator(participantId, isSecure);
} catch (Exception ex) {
throw new InvalidStateException();
}
} else if (AtomicTransactionConstants.WSAT_SUB_PROTOCOL_VOLATILE_2PC.equals(protocolIdentifier)) {
// enlist participant that wraps the requester URI.
final String participantId = "V" + new Uid().stringForm();
try {
final Volatile2PCStub participantStub = new Volatile2PCStub(participantId, participantProtocolService);
_coordManager.enlistSynchronization(new VolatileTwoPhaseCommitParticipant(participantStub));
_coordManager.suspend();
return getCoordinator(participantId, isSecure);
} catch (Exception ex) {
throw new InvalidStateException();
}
} else if (AtomicTransactionConstants.WSAT_SUB_PROTOCOL_COMPLETION.equals(protocolIdentifier)) {
try {
final CompletionCoordinatorParticipant participant = new CompletionCoordinatorImple(_coordManager, hier, true, participantProtocolService);
CompletionCoordinatorProcessor.getProcessor().activateParticipant(participant, instanceIdentifier.getInstanceIdentifier());
_coordManager.suspend();
return getCompletionCoordinator(instanceIdentifier, isSecure);
} catch (Exception ex) {
ex.printStackTrace();
throw new InvalidStateException(ex.toString());
}
} else if (AtomicTransactionConstants.WSAT_SUB_PROTOCOL_COMPLETION_RPC.equals(protocolIdentifier)) {
try {
final CompletionCoordinatorParticipant participant = new CompletionCoordinatorRPCImple(_coordManager, hier, true, participantProtocolService);
CompletionCoordinatorRPCProcessor.getProcessor().activateParticipant(participant, instanceIdentifier.getInstanceIdentifier());
_coordManager.suspend();
return getCompletionCoordinatorRPC(instanceIdentifier, isSecure);
} catch (Exception ex) {
ex.printStackTrace();
throw new InvalidStateException(ex.toString());
}
} else {
wstxLogger.i18NLogger.warn_mwlabs_wst_at_Registrar11Imple_1(AtomicTransactionConstants.WSAT_PROTOCOL, protocolIdentifier);
throw new InvalidProtocolException();
}
}
Aggregations