use of com.arjuna.mw.wsas.exceptions.SystemException in project narayana by jbosstm.
the class VolatileTwoPhaseCommitParticipant method beforeCompletion.
/**
* The transaction that the instance is enrolled with is about to commit.
*
* @exception SystemException
* Thrown if any error occurs. This will cause the
* transaction to roll back.
*/
public void beforeCompletion() throws SystemException {
try {
if (_resource != null) {
// com.arjuna.mw.wst.vote.Vote vt = _resource.prepare();
com.arjuna.wst.Vote vt = _resource.prepare();
if (vt instanceof com.arjuna.wst.ReadOnly)
_readonly = true;
else {
if (vt instanceof com.arjuna.wst.Prepared) {
// do nothing
} else {
List<Class<?>> expected = Arrays.asList(com.arjuna.wst.ReadOnly.class, com.arjuna.wst.Prepared.class);
wstxLogger.i18NLogger.error_wst_at_participants_Volatile2PC_prepare_wrong_type(vt, _resource, expected);
throw new SystemException("participant on before completion preparation resulted in wrong vote result " + vt);
}
}
} else {
wstxLogger.i18NLogger.error_wst_at_participants_Volatile2PC_prepare_is_null();
throw new SystemException("participant to prepare is null");
}
} catch (SystemException ex) {
throw ex;
} catch (Exception ex) {
wstxLogger.i18NLogger.error_wst_at_participants_Volatile2PC_prepare(_resource, ex);
SystemException se = new SystemException(ex.toString());
se.addSuppressed(ex);
throw se;
}
}
use of com.arjuna.mw.wsas.exceptions.SystemException 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.mw.wsas.exceptions.SystemException 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.mw.wsas.exceptions.SystemException in project narayana by jbosstm.
the class ContextFactoryImple method createSubordinate.
public final Object createSubordinate(String subordinateType) throws NoActivityException, InvalidProtocolException, SystemException {
try {
CoordinatorServiceImple coordManager = (CoordinatorServiceImple) _coordManager;
CoordinatorControl theControl = coordManager.coordinatorControl();
ATCoordinator subordinateTransaction = theControl.createSubordinate(subordinateType);
/*
* Now add the registrar for this specific coordinator to the
* mapper.
*/
subordinateTransaction.enlistSynchronization(new CleanupSynchronization(subordinateTransaction.get_uid().stringForm(), _theRegistrar));
_theRegistrar.associate(subordinateTransaction);
return subordinateTransaction;
} catch (Exception ex) {
throw new SystemException(ex.toString());
}
}
use of com.arjuna.mw.wsas.exceptions.SystemException in project narayana by jbosstm.
the class ArjunaContextImple method initialiseContext.
public void initialiseContext(Object param) {
try {
BACoordinator currentCoordinator = (BACoordinator) param;
ActivityHierarchy hier = null;
try {
hier = UserActivityFactory.userActivity().currentActivity();
} catch (SystemException ex) {
ex.printStackTrace();
}
if ((currentCoordinator != null) && (hier != null)) {
/*
* Do the manditory stuff first.
*/
ActionHierarchy txHier = currentCoordinator.getHierarchy();
final int depth = txHier.depth();
_identifierValues = new String[depth];
_expiresValues = new int[depth];
_identifierValues[0] = txHier.getDeepestActionUid().stringForm();
_expiresValues[0] = hier.activity(hier.size() - 1).getTimeout();
/*
* Now let's do the optional stuff.
*/
for (int count = 1, index = 0; count < depth; count++, index++) {
_identifierValues[count] = txHier.getActionUid(index).stringForm();
_expiresValues[count] = hier.activity(index).getTimeout();
}
}
} catch (ClassCastException ex) {
throw new IllegalArgumentException();
}
}
Aggregations