use of com.arjuna.mw.wsas.activity.HLS in project narayana by jbosstm.
the class UserActivityImple method resume.
/**
* Given a token representing a context, associate it with the current
* thread of control. This will implicitly disassociate the thread from any
* activities that it may already be associated with. If the parameter is
* null then the thread is associated with no activity.
*
* @param tx The activity to associate with this thread. This
* may be null in which case the current thread becomes associated with
* no activity.
*
* @exception InvalidActivityException Thrown if the activity handle
* is invalid in this context.
* @exception SystemException Thrown if any other error occurs.
*/
public void resume(ActivityHierarchy tx) throws InvalidActivityException, SystemException {
if (tx == null) {
purge();
} else {
if (tx instanceof ActivityHierarchyImple) {
try {
for (int i = 0; i < tx.size(); i++) {
ActivityHandleImple handle = (ActivityHandleImple) tx.activity(i);
push(handle.getActivity());
}
} catch (Exception ex) {
ex.printStackTrace();
purge();
}
} else
throw new InvalidActivityException(wsasLogger.i18NLogger.get_UserActivityImple_51());
}
ActivityImple currentActivity = current();
String serviceType = currentActivity.serviceType();
HLS hls = HLSManager.getHighLevelService(serviceType);
if (hls != null) {
try {
hls.resumed();
} catch (SystemException ex) {
wsasLogger.i18NLogger.warn_UserActivityImple_5(ex);
}
}
}
use of com.arjuna.mw.wsas.activity.HLS in project narayana by jbosstm.
the class ActivityImple method end.
/**
* Complete the activity with the completion status provided.
*
* @param cs The CompletionStatus to use.
*
* @exception InvalidActivityException
* Thrown if the current activity is not known about by the
* activity system.
* @exception WrongStateException
* Thrown if the current activity is not in a state that
* allows it to be completed, or is incompatible with the
* completion status provided.
* @exception ProtocolViolationException
* Thrown if the a violation of the activity service or HLS
* protocol occurs.
* @exception NoPermissionException
* Thrown if the invoking thread does not have permission to
* terminate the transaction.
* @exception SystemException
* Thrown if some other error occurred.
*
* @return the result of completing the activity. Null is valid and must be
* interpreted within the context of any HLS that may exist.
*
* @see com.arjuna.mw.wsas.Outcome
*/
public Outcome end(com.arjuna.mw.wsas.completionstatus.CompletionStatus cs) throws InvalidActivityException, WrongStateException, ProtocolViolationException, NoPermissionException, SystemException {
synchronized (this) {
if (_status.equals(Active.instance())) {
if (activeChildren()) {
throw new InvalidActivityException(wsasLogger.i18NLogger.get_activity_ActivityImple_2() + " " + this);
}
Outcome result = null;
try {
setCompletionStatus(cs);
} catch (Exception ex) {
// ignore and complete with the status we have.
}
_status = Completing.instance();
try {
HLS hls = HLSManager.getHighLevelService(_serviceType);
if (hls != null) {
result = hls.complete(getCompletionStatus());
} else {
result = new OutcomeImple(Failure.instance());
}
} catch (SystemException ex) {
/*
* Currently if an exception occurs and we get here, then we
* forget all of the other outcomes and just return the
* exception. Does this make sense? How will applications be
* able to tell which HLSes have processed the outcome and
* which have not?
*/
result = new OutcomeImple(new HLSException(ex), Failure.instance());
}
if (_parent != null) {
_parent.removeChild(this);
_parent = null;
}
_status = Completed.instance();
_result = result;
return _result;
} else {
if (_result != null)
return _result;
else {
throw new WrongStateException(wsasLogger.i18NLogger.get_activity_ActivityImple_3() + " " + _status);
}
}
}
}
use of com.arjuna.mw.wsas.activity.HLS in project narayana by jbosstm.
the class ContextManager method context.
/**
* message com.arjuna.mw.wsas.context.ContextManager_3 [com.arjuna.mw.wsas.context.ContextManager_3] - getHighLevelServices threw:
* message com.arjuna.mw.wsas.context.ContextManager_4 [com.arjuna.mw.wsas.context.ContextManager_4] - assembling context and received:
*/
public final Context context(String serviceType) {
Context ctx = null;
HLS service = null;
try {
// ensure we are in an activity associated with the correct service type
String currentServiceType = UserActivityFactory.userActivity().serviceType();
if (currentServiceType.equals(serviceType)) {
service = _manager.getHighLevelService(serviceType);
}
} catch (NoActivityException nae) {
// ignore
} catch (Exception ex) {
wsasLogger.i18NLogger.warn_context_ContextManager_1(ex);
}
if (service != null) {
try {
ctx = service.context();
} catch (Exception ex) {
wsasLogger.i18NLogger.warn_context_ContextManager_2(ex);
ctx = null;
}
}
return ctx;
}
use of com.arjuna.mw.wsas.activity.HLS in project narayana by jbosstm.
the class Context2Test method testContext2.
@Test
public void testContext2() throws Exception {
UserActivity ua = UserActivityFactory.userActivity();
DemoHLS demoHLS = new DemoHLS();
// this constructor means it will not fail
FailureHLS failureHLS = new FailureHLS();
HLS[] currentHLS = ActivityManagerFactory.activityManager().allHighLevelServices();
for (HLS hls : currentHLS) {
ActivityManagerFactory.activityManager().removeHLS(hls);
}
try {
ActivityManagerFactory.activityManager().addHLS(demoHLS);
ActivityManagerFactory.activityManager().addHLS(failureHLS);
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
org.w3c.dom.Document doc = docBuilder.newDocument();
org.w3c.dom.Element root = doc.createElement("Context2-test");
doc.appendChild(root);
String demoServiceType = demoHLS.identity();
String failureServiceType = failureHLS.identity();
ua.start(demoServiceType);
System.out.println("Started: " + ua.activityName());
ua.start(failureServiceType);
System.out.println("Started: " + ua.activityName() + "\n");
String currentServiceType = ua.serviceType();
if (currentServiceType != failureServiceType) {
fail("invalid service type for current activity");
}
ContextManager contextManager = new ContextManager();
Context demoServiceContext;
Context failureServiceContext;
demoServiceContext = contextManager.context(demoServiceType);
failureServiceContext = contextManager.context(failureServiceType);
if (failureServiceContext == null) {
fail("Failure context not found");
} else if (demoServiceContext != null) {
fail("Found multiple contexts");
}
if (!(failureServiceContext instanceof DemoSOAPContextImple)) {
fail("Failure context not found");
}
((SOAPContext) failureServiceContext).serialiseToElement(root);
System.out.println("Faiure Context is " + root.getTextContent());
ua.end();
System.out.println("\nFinished child activity.\n");
currentServiceType = ua.serviceType();
if (currentServiceType != demoServiceType) {
fail("invalid service type for current activity");
}
demoServiceContext = contextManager.context(demoServiceType);
failureServiceContext = contextManager.context(failureServiceType);
if (demoServiceContext == null) {
fail("Demo context not found");
} else if (failureServiceContext != null) {
fail("Found multiple contexts");
}
if (!(demoServiceContext instanceof DemoSOAPContextImple)) {
fail("Demo context not found");
}
((SOAPContext) demoServiceContext).serialiseToElement(root);
System.out.println("Demo Context is " + root.getTextContent());
ua.end();
System.out.println("\nFinished parent activity.\n");
} catch (Exception ex) {
WSASTestUtils.cleanup(ua);
throw ex;
} finally {
try {
for (HLS hls : currentHLS) {
ActivityManagerFactory.activityManager().addHLS(hls);
}
} catch (Exception ex) {
// ignore this
}
try {
if (demoHLS != null) {
ActivityManagerFactory.activityManager().removeHLS(demoHLS);
}
} catch (Exception ex) {
// ignore this
}
try {
if (failureHLS != null) {
ActivityManagerFactory.activityManager().removeHLS(failureHLS);
}
} catch (Exception ex) {
// ignore this
}
}
}
use of com.arjuna.mw.wsas.activity.HLS in project narayana by jbosstm.
the class Context1Test method testContext1.
@Test
public void testContext1() throws Exception {
UserActivity ua = UserActivityFactory.userActivity();
DemoHLS demoHLS = new DemoHLS();
HLS[] currentHLS = ActivityManagerFactory.activityManager().allHighLevelServices();
for (HLS hls : currentHLS) {
ActivityManagerFactory.activityManager().removeHLS(hls);
}
try {
ActivityManagerFactory.activityManager().addHLS(demoHLS);
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
org.w3c.dom.Document doc = docBuilder.newDocument();
org.w3c.dom.Element root = doc.createElement("Context1-test");
doc.appendChild(root);
String coordinationType = demoHLS.identity();
ua.start(coordinationType);
System.out.println("Started: " + ua.activityName());
ua.start(coordinationType);
System.out.println("Started: " + ua.activityName() + "\n");
ContextManager contextManager = new ContextManager();
Context theContext = contextManager.context(coordinationType);
if (theContext == null) {
fail("Demo context not found");
}
if (!(theContext instanceof DemoSOAPContextImple)) {
fail("Demo context not found");
}
((SOAPContext) theContext).serialiseToElement(root);
System.out.println("Context is " + root.getTextContent());
ua.end();
System.out.println("\nFinished child activity.\n");
theContext = contextManager.context(coordinationType);
if (theContext == null) {
fail("Demo context not found");
}
if (!(theContext instanceof DemoSOAPContextImple)) {
fail("Demo context not found");
}
doc = docBuilder.newDocument();
root = doc.createElement("Context1-test");
doc.appendChild(root);
((SOAPContext) theContext).serialiseToElement(root);
System.out.println("Context is " + root.getTextContent());
ua.end();
System.out.println("\nFinished parent activity.\n");
theContext = contextManager.context(coordinationType);
if (theContext != null) {
fail("Demo context not removed");
}
} catch (Exception ex) {
WSASTestUtils.cleanup(ua);
throw ex;
} finally {
try {
for (HLS hls : currentHLS) {
ActivityManagerFactory.activityManager().addHLS(hls);
}
} catch (Exception ex) {
// ignore this
}
try {
if (demoHLS != null) {
ActivityManagerFactory.activityManager().removeHLS(demoHLS);
}
} catch (Exception ex) {
// ignore this
}
}
}
Aggregations