Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2006, Red Hat Middleware LLC, and individual contributors
   * as indicated by the @author tags. 
   * See the copyright.txt in the distribution for a full listing 
   * of individual contributors.
   * This copyrighted material is made available to anyone wishing to use,
   * modify, copy, or redistribute it subject to the terms and conditions
   * of the GNU Lesser General Public License, v. 2.1.
  * This program is distributed in the hope that it will be useful, but WITHOUT A
  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
  * You should have received a copy of the GNU Lesser General Public License,
  * v.2.1 along with this distribution; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  * MA  02110-1301, USA.
  * 
  * (C) 2005-2006,
  * @author JBoss Inc.
  */
 /*
  * Copyright (C) 2002,
  *
  * Arjuna Technologies Limited,
  * Newcastle upon Tyne,
  * Tyne and Wear,
  * UK.
  *
  * $Id: UserActivityImple.java,v 1.4 2005/03/10 15:37:00 nmcl Exp $
  */
 
 package com.arjuna.mwlabs.wsas;
 
 
 
 
 
 
 
 
 
 
 
The user portion of the activity API. An implementation of this interface presents each thread with the capability to create and manage activities. It is very similar to the OTS Current and JTA UserTransaction.

Author(s):
Mark Little (mark.little@arjuna.com)
Version:
$Id: UserActivityImple.java,v 1.4 2005/03/10 15:37:00 nmcl Exp $
Since:
1.0.
 
 
 public class UserActivityImple implements UserActivity
 {
    
Start a new activity. If there is already an activity associated with the thread then it will be nested. An implementation specific timeout will be associated with the activity (which may be no timeout).

Parameters:
serviceType specifies the type of coordinator which will be instantiated to manage the activity.
Throws:
com.arjuna.mw.wsas.exceptions.WrongStateException Thrown if the any currently associated activity is in a state that does not allow a new activity to be enlisted.
com.arjuna.mw.wsas.exceptions.SystemException Thrown in any other situation.
 
 
     public void start (String serviceTypethrows WrongStateExceptionSystemException
     {
 	try
 	{
 	    start(serviceTypegetTimeout());
	}
	{
	}
    }

    
Start a new activity. If there is already an activity associated with the thread then it will be nested.

Parameters:
serviceType specifies the type of coordinator which will be instantiated to manage the activity.
timeout The timeout associated with the activity. If the activity has not been terminated by the time this period elapses, then it will automatically be terminated.
Throws:
com.arjuna.mw.wsas.exceptions.WrongStateException Thrown if the currently associated activity is in a state that does not allow a new activity to be enlisted as a child.
com.arjuna.mw.wsas.exceptions.InvalidTimeoutException Thrown if the specified timeout is invalid within the current working environment.
com.arjuna.mw.wsas.exceptions.SystemException Thrown in any other situation.
    public void start (String serviceTypeint timeoutthrows WrongStateExceptionInvalidTimeoutExceptionSystemException
    {
        if (timeout < 0)
            throw new InvalidTimeoutException();
        else
        {
            if (timeout == 0)
                timeout = getTimeout();
        }
        ActivityImple currentActivity = new ActivityImple(current(), serviceType);
        currentActivity.start(timeout);
        push(currentActivity);
        HLS hls = HLSManager.getHighLevelService(serviceType);
        try {
            if (hls != null)
            {
                hls.begun();
            }
        } catch (SystemException ex) {
            try {
                setCompletionStatus(FailureOnly.instance());
            } catch (Exception e) {
                ..warn_UserActivityImple_1(e);
            }
            throw ex;
        }
    }
    
    
Complete the activity with the completion status provided.

Returns:
the result of completing the activity. Null is valid and must be interpreted within the context of any HLS that may exist.
Throws:
com.arjuna.mw.wsas.exceptions.InvalidActivityException Thrown if the current activity is invalid in the execution environment.
com.arjuna.mw.wsas.exceptions.ActiveChildException Thrown if the current activity is a
com.arjuna.mw.wsas.exceptions.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.
com.arjuna.mw.wsas.exceptions.ProtocolViolationException Thrown if the a violation of the activity service or HLS protocol occurs.
com.arjuna.mw.wsas.exceptions.NoActivityException Thrown if there is no activity associated with the invoking thread or none with the given type of coordinator.
com.arjuna.mw.wsas.exceptions.NoPermissionException Thrown if the invoking thread does not have permission to terminate the transaction.
com.arjuna.mw.wsas.exceptions.SystemException Thrown if some other error occurred.
See also:
com.arjuna.mw.wsas.activity.Outcome
Message:
com.arjuna.mwlabs.wsas.UserActivityImple_2 [com.arjuna.mwlabs.wsas.UserActivityImple_2] - currentActivity.end threw:
Message:
com.arjuna.mwlabs.wsas.UserActivityImple_3 [com.arjuna.mwlabs.wsas.UserActivityImple_3] - Activity.completed caught:
    {
        ActivityImple currentActivity = current();
        if (currentActivity == null) {
            throw new NoActivityException();
        }
        Outcome res = null;
        String serviceType = currentActivity.serviceType();
        try {
            res = currentActivity.end();
        } catch (Exception ex) {
        }
        HLS hls = HLSManager.getHighLevelService(serviceType);
        if (hls != null)
        {
            try
            {
                hls.completed();
            }
            catch (SystemException ex)
            {
                ..warn_UserActivityImple_3(ex);
            }
        }
        pop();
        return res;
    }

    
Complete the activity with the completion status provided.

Parameters:
cs The CompletionStatus to use.
Returns:
the result of completing the activity. Null is valid and must be interpreted within the context of any HLS that may exist.
Throws:
com.arjuna.mw.wsas.exceptions.InvalidActivityException Thrown if the current activity is invalid in the execution environment.
com.arjuna.mw.wsas.exceptions.ActiveChildException Thrown if the current activity is a
com.arjuna.mw.wsas.exceptions.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.
com.arjuna.mw.wsas.exceptions.ProtocolViolationException Thrown if the a violation of the activity service or HLS protocol occurs.
com.arjuna.mw.wsas.exceptions.NoActivityException Thrown if there is no activity associated with the invoking thread or none with the given type of coordinator.
com.arjuna.mw.wsas.exceptions.NoPermissionException Thrown if the invoking thread does not have permission to terminate the transaction.
com.arjuna.mw.wsas.exceptions.SystemException Thrown if some other error occurred.
See also:
com.arjuna.mw.wsas.Outcome
    {
        ActivityImple currentActivity = current();
        if (currentActivity == null) {
            throw new NoActivityException();
        }
        /*
	if (currentActivity.parent() != null)
	    throw new ActiveChildException();
	*/
        Outcome res = null;
        String serviceType = currentActivity.serviceType();
        try {
            res = currentActivity.end(cs);
        } catch (Exception ex) {
        }
        HLS hls = HLSManager.getHighLevelService(serviceType);
        if (hls != null)
        {
            try {
                hls.completed();
            } catch (SystemException ex) {
                ..warn_UserActivityImple_3(ex);
            }
        }
        pop();
        return res;
    }

    
Set the termination status for the current activity, if any.

Parameters:
endStatus The state in which the activity should attempt to terminate. This may be one of the default values provided by WSAS or may be extended in an implementation specific manner by an HLS.
Throws:
com.arjuna.mw.wsas.exceptions.NoActivityException Thrown if there is no activity associated with the invoking thread.
com.arjuna.mw.wsas.exceptions.WrongStateException Thrown if the completion status is incompatible with the current state of the activity.
com.arjuna.mw.wsas.exceptions.SystemException Thrown if any other error occurs.
    {
	if (curr == null)
	    throw new NoActivityException();
	curr.setCompletionStatus(endStatus);
    }

    
Get the completion status currently associated with the activity.

Returns:
the termination status for the current activity, if any.
Throws:
com.arjuna.mw.wsas.exceptions.NoActivityException Thrown if there is no activity associated with the current thread.
com.arjuna.mw.wsas.exceptions.SystemException Thrown if any other error occurs.
    {
	if (curr == null)
	    throw new NoActivityException();
	else
	    return curr.getCompletionStatus();
    }

    
Get the timeout value currently associated with activities.

Returns:
the timeout value in seconds, or 0 if no application specified timeout has been provided.
Throws:
com.arjuna.mw.wsas.exceptions.SystemException Thrown if any error occurs.
    public int getTimeout () throws SystemException
    {
	int val = ;
	if (t != null)
	    val = t.intValue();
	return val;
    }

    
Set the timeout to be associated with all subsequently created activities. A default value of 0 is automatically associated with each thread and this means that no application specified timeout is set for activities.

Parameters:
timeout The timeout (in seconds) to associate with all subsequently created activities. This value must be 0 or greater.
Throws:
com.arjuna.mw.wsas.exceptions.InvalidTimeoutException Thrown if the timeout value provided is negative, too large, or if timeouts are simply not supported by the activity implementation.
com.arjuna.mw.wsas.exceptions.SystemException Thrown if any other error occurs.
    public void setTimeout (int timeoutthrows InvalidTimeoutExceptionSystemException
    {
	if (timeout < 0)
	    throw new InvalidTimeoutException();
	.set(new Integer(timeout));
    }
    
    

Returns:
the status of the current activity. If there is no activity associated with the thread then NoActivity will be returned.
Throws:
com.arjuna.mw.wsas.exceptions.SystemException Thrown if any error occurs.
See also:
com.arjuna.mw.wsas.status.Status
    public com.arjuna.mw.wsas.status.Status status () throws SystemException
    {
	if (curr == null)
	    return NoActivity.instance();
	else
	    return curr.status();
    }

    
What is the name of the current activity? Use only for debugging purposes!

Returns:
the name of the activity.
Throws:
com.arjuna.mw.wsas.exceptions.NoActivityException Thrown if there is no activity associated with the invoking thread.
com.arjuna.mw.wsas.exceptions.SystemException Thrown if any other error occurs.
    {
	if (curr == null)
	    throw new NoActivityException();  // or return null?
	else
	    return curr.activityName();
    }
    {
	if (curr == null)
	    throw new NoActivityException();  // or return null?
	else
	    return curr.getGlobalId();
    }

    
Suspend the current activity from this thread and return the token representing the context, if any, or null otherwise. Once called, the thread will have no activities associated with it.

Returns:
the token representing the current context, if any, or null otherwise.
Throws:
com.arjuna.mw.wsas.exceptions.SystemException Thrown if any error occurs.
    public ActivityHierarchy suspend () throws SystemException
    {
        ActivityImple currentActivity = current();
        if (currentActivity == null) {
            return null;
        }
        String serviceType = currentActivity.serviceType();
        
        HLS hls = HLSManager.getHighLevelService(serviceType);
        if (hls != null) {
            try {
                hls.suspended();
            } catch (SystemException ex) {
                ..warn_UserActivityImple_4(ex);
            }
        }
        currentActivity = purge();
        if (currentActivity != null) {
            return new ActivityHierarchyImple(currentActivity);
        } else {
            return null;
        }
    }

    
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.

Parameters:
tx The activity to associate with this thread. This may be null in which case the current thread becomes associated with no activity.
Throws:
com.arjuna.mw.wsas.exceptions.InvalidActivityException Thrown if the activity handle is invalid in this context.
com.arjuna.mw.wsas.exceptions.SystemException Thrown if any other error occurs.
    {
        if (tx == null)
        {
            purge();
        }
        else
        {
            if (tx instanceof ActivityHierarchyImple)
            {
                try
                {
                    for (int i = 0; i < tx.size(); i++)
                    {
                        ActivityHandleImple handle = (ActivityHandleImpletx.activity(i);
                        push(handle.getActivity());
                    }
                }
                catch (Exception ex)
                {
                    ex.printStackTrace();
		    
                    purge();
                }
            }
            else
                throw new InvalidActivityException(..get_UserActivityImple_51());
        }
        ActivityImple currentActivity = current();
        String serviceType = currentActivity.serviceType();
        HLS hls = HLSManager.getHighLevelService(serviceType);
        if (hls != null) {
            try	{
                hls.resumed();
            } catch (SystemException ex) {
                ..warn_UserActivityImple_5(ex);
            }
        }
    }
    {
	if (curr != null)
	    return new ActivityHierarchyImple(curr);
	else
	    return null;
    }
    public String serviceType() throws NoActivityExceptionSystemException {
        ActivityImple currentActivity = current();
        if (currentActivity == null) {
            throw new NoActivityException();
        }
        return currentActivity.serviceType();
    }
    public final ActivityImple current ()
    {
	Stack hier = (Stack.get();
	ActivityImple currentActivity = null;
	if (hier != null)
	{
	    try
	    {
		currentActivity = (ActivityImplehier.peek();
	    }
	    catch (EmptyStackException ex)
	    {
	    }
	}
	return currentActivity;
    }
    
    private final void push (ActivityImple currentActivity)
    {
	Stack hier = (Stack.get();
	if (hier == null)
	{
	    hier = new Stack();
	    .set(hier);
	}
	hier.push(currentActivity);
    }
    
    private final ActivityImple pop ()
    {
	Stack hier = (Stack.get();
	ActivityImple currentActivity = null;
	if (hier != null)
	{
	    try
	    {
		currentActivity = (ActivityImplehier.pop();
		if (hier.size() == 0)
		    .set(null);
	    }
	    catch (EmptyStackException ex)
	    {
	    }
	}
	return currentActivity;
    }
    private final ActivityImple purge ()
    {
	Stack hier = (Stack.get();
	ActivityImple currentActivity = null;
	if (hier != null)
	{
	    .set(null) ;
	    try
	    {
		currentActivity = (ActivityImplehier.peek();
	    }
	    catch (EmptyStackException ex)
	    {
	    }
	}
	return currentActivity;
    }
    
    private static ThreadLocal _threadAxData = new ThreadLocal() ;
    private static ThreadLocal _timeouts = new ThreadLocal() ;
    private static final int _defaultTimeout = 0;
    
New to GrepCode? Check out our FAQ X