Search in sources :

Example 6 with HLS

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);
        }
    }
}
Also used : InvalidActivityException(com.arjuna.mw.wsas.exceptions.InvalidActivityException) SystemException(com.arjuna.mw.wsas.exceptions.SystemException) ActivityImple(com.arjuna.mwlabs.wsas.activity.ActivityImple) ActivityHierarchyImple(com.arjuna.mwlabs.wsas.activity.ActivityHierarchyImple) ActivityHandleImple(com.arjuna.mwlabs.wsas.activity.ActivityHandleImple) EmptyStackException(java.util.EmptyStackException) SystemException(com.arjuna.mw.wsas.exceptions.SystemException) InvalidTimeoutException(com.arjuna.mw.wsas.exceptions.InvalidTimeoutException) ActiveChildException(com.arjuna.mw.wsas.exceptions.ActiveChildException) NoPermissionException(com.arjuna.mw.wsas.exceptions.NoPermissionException) NoActivityException(com.arjuna.mw.wsas.exceptions.NoActivityException) WrongStateException(com.arjuna.mw.wsas.exceptions.WrongStateException) InvalidActivityException(com.arjuna.mw.wsas.exceptions.InvalidActivityException) ProtocolViolationException(com.arjuna.mw.wsas.exceptions.ProtocolViolationException) HLS(com.arjuna.mw.wsas.activity.HLS)

Example 7 with HLS

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);
            }
        }
    }
}
Also used : InvalidActivityException(com.arjuna.mw.wsas.exceptions.InvalidActivityException) SystemException(com.arjuna.mw.wsas.exceptions.SystemException) Outcome(com.arjuna.mw.wsas.activity.Outcome) WrongStateException(com.arjuna.mw.wsas.exceptions.WrongStateException) HLSException(com.arjuna.mw.wsas.exceptions.HLSException) SystemException(com.arjuna.mw.wsas.exceptions.SystemException) HLSException(com.arjuna.mw.wsas.exceptions.HLSException) InvalidTimeoutException(com.arjuna.mw.wsas.exceptions.InvalidTimeoutException) NoPermissionException(com.arjuna.mw.wsas.exceptions.NoPermissionException) NoActivityException(com.arjuna.mw.wsas.exceptions.NoActivityException) WrongStateException(com.arjuna.mw.wsas.exceptions.WrongStateException) InvalidActivityException(com.arjuna.mw.wsas.exceptions.InvalidActivityException) ProtocolViolationException(com.arjuna.mw.wsas.exceptions.ProtocolViolationException) HLS(com.arjuna.mw.wsas.activity.HLS)

Example 8 with HLS

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;
}
Also used : NoActivityException(com.arjuna.mw.wsas.exceptions.NoActivityException) HLS(com.arjuna.mw.wsas.activity.HLS) NoActivityException(com.arjuna.mw.wsas.exceptions.NoActivityException)

Example 9 with HLS

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
        }
    }
}
Also used : Context(com.arjuna.mw.wsas.context.Context) SOAPContext(com.arjuna.mw.wsas.context.soap.SOAPContext) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DemoSOAPContextImple(com.arjuna.wsas.tests.DemoSOAPContextImple) UserActivity(com.arjuna.mw.wsas.UserActivity) FailureHLS(com.arjuna.wsas.tests.FailureHLS) DemoHLS(com.arjuna.wsas.tests.DemoHLS) HLS(com.arjuna.mw.wsas.activity.HLS) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ContextManager(com.arjuna.mw.wsas.context.ContextManager) DemoHLS(com.arjuna.wsas.tests.DemoHLS) SOAPContext(com.arjuna.mw.wsas.context.soap.SOAPContext) FailureHLS(com.arjuna.wsas.tests.FailureHLS) Test(org.junit.Test)

Example 10 with HLS

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
        }
    }
}
Also used : Context(com.arjuna.mw.wsas.context.Context) SOAPContext(com.arjuna.mw.wsas.context.soap.SOAPContext) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DemoSOAPContextImple(com.arjuna.wsas.tests.DemoSOAPContextImple) UserActivity(com.arjuna.mw.wsas.UserActivity) DemoHLS(com.arjuna.wsas.tests.DemoHLS) HLS(com.arjuna.mw.wsas.activity.HLS) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ContextManager(com.arjuna.mw.wsas.context.ContextManager) DemoHLS(com.arjuna.wsas.tests.DemoHLS) SOAPContext(com.arjuna.mw.wsas.context.soap.SOAPContext) Test(org.junit.Test)

Aggregations

HLS (com.arjuna.mw.wsas.activity.HLS)11 NoActivityException (com.arjuna.mw.wsas.exceptions.NoActivityException)6 SystemException (com.arjuna.mw.wsas.exceptions.SystemException)6 InvalidActivityException (com.arjuna.mw.wsas.exceptions.InvalidActivityException)5 InvalidTimeoutException (com.arjuna.mw.wsas.exceptions.InvalidTimeoutException)5 NoPermissionException (com.arjuna.mw.wsas.exceptions.NoPermissionException)5 ProtocolViolationException (com.arjuna.mw.wsas.exceptions.ProtocolViolationException)5 WrongStateException (com.arjuna.mw.wsas.exceptions.WrongStateException)5 ActivityImple (com.arjuna.mwlabs.wsas.activity.ActivityImple)5 ActiveChildException (com.arjuna.mw.wsas.exceptions.ActiveChildException)4 EmptyStackException (java.util.EmptyStackException)4 UserActivity (com.arjuna.mw.wsas.UserActivity)3 Outcome (com.arjuna.mw.wsas.activity.Outcome)3 ContextManager (com.arjuna.mw.wsas.context.ContextManager)3 Test (org.junit.Test)3 Context (com.arjuna.mw.wsas.context.Context)2 SOAPContext (com.arjuna.mw.wsas.context.soap.SOAPContext)2 ActivityHierarchyImple (com.arjuna.mwlabs.wsas.activity.ActivityHierarchyImple)2 DemoHLS (com.arjuna.wsas.tests.DemoHLS)2 DemoSOAPContextImple (com.arjuna.wsas.tests.DemoSOAPContextImple)2