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: ActivityImple.java,v 1.6 2005/05/19 12:13:18 nmcl Exp $
  */
 
 package com.arjuna.mwlabs.wsas.activity;
 
 
 
 
 // TODO: obtain via configuration
 
 
 
 
 
 
 
The Activity.

Author(s):
Mark Little (mark.little@arjuna.com)
Version:
$Id: ActivityImple.java,v 1.6 2005/05/19 12:13:18 nmcl Exp $
Since:
1.0.
 
 
 public class ActivityImple
 {
 
 	public ActivityImple (String coordinationType)
 	{
 		this(nullcoordinationType);
 	}
 
 	public ActivityImple (ActivityImple parentString serviceType)
 	{
 		 = parent;
 		 = new Hashtable();
 		 = Created.instance();
 		 = Failure.instance();
 		 = 0;
 		 = null;
          = serviceType;
 	}

Start a new activity.

Parameters:
int 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 () throws WrongStateExceptionSystemException
	{
		try
		{
		}
		{
		}
	}

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

Parameters:
int 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 (int timeoutthrows WrongStateException,
	{
		if (timeout < 0)
		synchronized (this)
		{
			 = timeout;
			if (.equals(Created.instance()))
			{
				try
				{
					if ( != null)
				}
				{
					 = Completed.instance();
					throw new WrongStateException(ex.toString());
				}
				if ( > 0)
				{
					if (!ActivityReaper.activityReaper(true).insert(this))
					{
					}
				}
				 = Active.instance();
			}
			else
                        ..get_activity_ActivityImple_1()
                                + " " + this + " " + );
		}
	}

Complete the activity with the current completion status.

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 not known about by the activity system.
com.arjuna.mw.wsas.exceptions.WrongStateException Thrown if the current activity is not in a state that allows it to be completed.
com.arjuna.mw.wsas.exceptions.ProtocolViolationException Thrown if the a violation of the activity service or HLS protocol occurs.
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
	{
	}

Complete the activity with the completion status provided.

Parameters:
CompletionStatus 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 not known about by the activity system.
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.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
	{
		/*
		 * TODO
		 *
		 * We need an exception that can be thrown to say that the activity is
		 * completing.
		 */
		synchronized (this)
		{
			if (.equals(Active.instance()))
			{
				{
					/*
					 * Can we do equivalent of rollback on all children and then
					 * rollback this?
					 */
                            ..get_activity_ActivityImple_2()
                                    + " " + this);
				}
				Outcome result = null;
				try
				{
				}
				catch (Exception ex)
				{
					// ignore and complete with the status we have.
				}
				 = Completing.instance();
				try
				{
                    HLS hls = HLSManager.getHighLevelService();
                    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 ( != null)
				{
					 = null;
				}
				 = Completed.instance();
				 = result;
				return ;
			}
			else
			{
				if ( != null)
					return ;
				else
				{
					// we can't have terminated yet!
                            ..get_activity_ActivityImple_3()
                                    + " " + );
				}
			}
		}
	}

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

Parameters:
CompletionStatus 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.
	public void setCompletionStatus (CompletionStatus endStatus)
	{
		synchronized (this)
		{
			if (.equals(Active.instance()))
			{
				completionValid(endStatus);
				 = endStatus;
			}
			else
                        ..get_activity_ActivityImple_4()
                                + " " + this + " " + );
		}
	}

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.
	{
		synchronized (this)
		{
		}
	}

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
	{
		return ;
	}

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
	{
		synchronized (this)
		{
			return ;
		}
	}

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.
	{
		return "ActivityImple: " + toString();
	}
	public String toString ()
	{
	}

Returns:
the unique identifier for this activity.
	public GlobalId getGlobalId ()
	{
		return ;
	}

Returns:
The parent of the activity, or null if it is top-level.
	public ActivityImple parent ()
	{
		return ;
	}

    

Returns:
the type of the coordinator employed for this activity
    public String serviceType()
    {
        return ;
    }
	public boolean equals (Object obj)
	{
		if (obj != null)
		{
			if (obj != this)
			{
				if (obj instanceof ActivityImple)
				{
						return true;
				}
				else
					return true;
			}
		}
		return false;
	}

Return the activity hierarchy that this activity is within. The zeroth element is the parent.
	public ActivityImple[] hierarchy ()
	{
		Stack hier = new Stack();
		ActivityImple ptr = this;
		while (ptr != null)
		{
			hier.push(ptr);
			ptr = ptr.parent();
		}
		int hierSize = hier.size();
		ActivityImple[] toReturn = new ActivityImple[hierSize];
		for (int i = 0; i < hierSizei++)
			toReturn[i] = (ActivityImplehier.pop();
		return toReturn;
	}

Check whether the specified completion status is compatible with the one currently assigned to the activity.

Parameters:
CompletionStatus cs The completion status to check.
Throws:
com.arjuna.mw.wsas.exceptions.WrongStateException Thrown if the specified status is incompatible with that currently possessed by this activity.
	public final void completionValid (CompletionStatus cs)
	{
		{
			if (.equals(FailureOnly.instance()))
                        ..get_activity_ActivityImple_5()
                                + " " +  + " " + cs);
		}
	}
	public int hashCode ()
	{
	}

Add the specified activity as a child of this activity.

Parameters:
ActivityImple child The child activity.
Throws:
com.arjuna.mw.wsas.exceptions.WrongStateException Thrown if the parent activity is not in a state that allows children to be added.
com.arjuna.mw.wsas.exceptions.InvalidActivityException Thrown if the child activity is invalid.
com.arjuna.mw.wsas.exceptions.SystemException Thrown if some other error occurs.
	final void addChild (ActivityImple childthrows WrongStateException,
	{
		if (child == null)
                    ..get_activity_ActivityImple_6());
		synchronized (this)
		{
			if (.equals(Active.instance()))
			{
				.put(child.getGlobalId(), child);
			}
			else
                        ..get_activity_ActivityImple_7()
                                + " " + );
		}
	}

Remove the specified child activity from this activity.

Parameters:
ActivityImple child The child activity to remove.
Throws:
com.arjuna.mw.wsas.exceptions.WrongStateException Thrown if the parent activity is not in a state that allows children to be removed.
com.arjuna.mw.wsas.exceptions.InvalidActivityException Thrown if the child activity is invalid.
com.arjuna.mw.wsas.exceptions.SystemException Thrown if some other error occurs.
	final void removeChild (ActivityImple childthrows WrongStateException,
	{
		if (child == null)
                    ..get_activity_ActivityImple_8());
		synchronized (this)
		{
			if (.equals(Active.instance()))
			{
				if (.get(child.getGlobalId()) == null)
                            ..get_activity_ActivityImple_9()
                                    + child);
			}
			else
                        ..get_activity_ActivityImple_10()
                                + );
		}
	}

Returns:
true if this activity has active children, false otherwise.
	private final boolean activeChildren ()
	{
		while (e.hasMoreElements())
		{
			try
			{
				if ((child != null)
						&& (child.status().equals(Active.instance())))
				{
					return true;
				}
			}
			catch (Exception ex)
			{
				return true// what else can we do?
			}
		}
		return false;
	}
	private Status _status;
	private int _timeout;
	private Outcome _result;
    private String _serviceType;
New to GrepCode? Check out our FAQ X