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: CoordinatorServiceImple.java,v 1.5 2005/05/19 12:13:37 nmcl Exp $
  */
 
 package com.arjuna.mwlabs.wscf.model.sagas.arjunacore;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
The user portion of the coordinator API. An implementation of this interface presents each thread with the capability to create and manage coordinators. It is very similar to the OTS Current and JTA UserTransaction.

Author(s):
Mark Little (mark.little@arjuna.com)
Version:
$Id: CoordinatorServiceImple.java,v 1.5 2005/05/19 12:13:37 nmcl Exp $
Since:
1.0.
 
 
 {
 
     public CoordinatorServiceImple ()
     {
 	super();
 
     }

    
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).

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 begin (String coordinationTypethrows WrongStateExceptionSystemException
     {
	UserActivityFactory.userActivity().start(coordinationType);
    }

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

Parameters:
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 begin (String coordinationTypeint timeoutthrows WrongStateExceptionInvalidTimeoutExceptionSystemException
    {
	UserActivityFactory.userActivity().start(coordinationTypetimeout);
    }	


    
Create a subordinate coordinator via the coordination control.
    {
        return .createSubordinate();
    }
    
Confirm the activity.

Throws:
com.arjuna.mw.wsas.exceptions.InvalidActivityException Thrown if the current activity is a parent activity with active children.
com.arjuna.mw.wsas.exceptions.WrongStateException Thrown if the current activity is not in a state that allows it to be completed in the status requested.
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.
    {
	try
	{
	    Outcome res = UserActivityFactory.userActivity().end(Success.instance());
	    /*
	     * TODO
	     *
	     * What happens if the coordinator has already been terminated?
	     */
	    if (res != null)
	    {
		if (res instanceof CoordinationOutcome)
		{
		    
		    switch (co.result())
		    {
			break;
			throw new ProtocolViolationException("HeuristicMixed");
			throw new WrongStateException();
		    default:
			throw new ProtocolViolationException("HeuristicHazard");
		    }
		}
		else
	    }
	}
	{
	    throw new NoCoordinatorException();
	}
	{
	    // ?? assume the coordination protocol will cancel children anyway.
	}
    }
    
    
Cancel the activity.

Throws:
com.arjuna.mw.wsas.exceptions.InvalidActivityException Thrown if the current activity is a parent activity with active children.
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.
    {
	try
	{
	    Outcome res = UserActivityFactory.userActivity().end(Failure.instance());
	    
	    if (res != null)
	    {
		if (res instanceof CoordinationOutcome)
		{
		    
		    switch (co.result())
		    {
			break;
			throw new ProtocolViolationException("HeuristicMixed");
			throw new WrongStateException();
		    default:
			throw new ProtocolViolationException("HeuristicHazard");
		    }
		}
		else
	    }
	}
	{
	    throw new NoCoordinatorException();
	}
	{
	    // ?? assume the coordination protocol will cancel children anyway.
	}
    }

    
Complete the activity.

Throws:
com.arjuna.mw.wsas.exceptions.InvalidActivityException Thrown if the current activity is a parent activity with active children.
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.
    {
    }
    
    
Set the termination status for the current activity to cancel only.

Throws:
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.
    {
	try
	{
	    UserActivityFactory.userActivity().setCompletionStatus(FailureOnly.instance());
	}
	{
	    throw new NoCoordinatorException();
	}
    }	

    
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 UserActivityFactory.userActivity().getTimeout();
    }	

    
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
    {
	UserActivityFactory.userActivity().setTimeout(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();
    }
    
    
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
    {
	return UserActivityFactory.userActivity().suspend();
    }

    
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.
    {
	UserActivityFactory.userActivity().resume(tx);
    }

    
Enrol the specified participant with the coordinator associated with the current thread.

Parameters:
act The participant.
Throws:
com.arjuna.mw.wsas.exceptions.WrongStateException Thrown if the coordinator is not in a state that allows participants to be enrolled.
com.arjuna.mw.wscf.exceptions.DuplicateParticipantException Thrown if the participant has already been enrolled and the coordination protocol does not support multiple entries.
com.arjuna.mw.wscf.exceptions.InvalidParticipantException Thrown if the participant is invalid.
com.arjuna.mw.wsas.exceptions.SystemException Thrown if any other error occurs.
    {
    }

    
Remove the specified participant from the coordinator's list.

Throws:
com.arjuna.mw.wscf.exceptions.InvalidParticipantException Thrown if the participant is not known of by the coordinator.
com.arjuna.mw.wsas.exceptions.WrongStateException Thrown if the state of the coordinator does not allow the participant to be removed (e.g., in a two-phase protocol the coordinator is committing.)
com.arjuna.mw.wsas.exceptions.SystemException Thrown if any other error occurs.
    
    {
    }
    {
    }
    {
	try
	{
	    setCancelOnly();
	}
	catch (Exception ex)
	{
	    throw new SystemException(ex.toString());
	}
    }
    
    {
	try
	{
	    setCancelOnly();
	}
	catch (Exception ex)
	{
	    throw new SystemException(ex.toString());
	}
    }

    

Returns:
the token representing the current activity context hierarchy, or null if there is none associated with the invoking thread.
Throws:
com.arjuna.mw.wsas.exceptions.SystemException Thrown if any error occurs.
    {
	return UserActivityFactory.userActivity().currentActivity();
    }

    

Returns:
the unique coordinator identifier.
    {
	if (curr == null)
	    throw new NoActivityException();
    }
    public final ActivityImple current ()
    {
	UserActivityImple imple = (UserActivityImple) UserActivityFactory.userActivity();
	return imple.current();
    }
    
New to GrepCode? Check out our FAQ X