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) 1998, 1999, 2000, 2001,
  *
  * Arjuna Solutions Limited,
  * Newcastle upon Tyne,
  * Tyne and Wear,
  * UK.
  *
  * $Id: ThreadActionData.java 2342 2006-03-30 13:06:17Z  $
  */
 
 package com.arjuna.ats.internal.arjuna.thread;
 
 
This class maintains a mapping between a thread and its notion of the current transaction. Essentially this is a stack of transactions.

Author(s):
Mark Little (mark@arjuna.com)
Version:
$Id: ThreadActionData.java 2342 2006-03-30 13:06:17Z $
Since:
JTS 1.0.
 
 
 public class ThreadActionData
 {
 
 	public static BasicAction currentAction ()
 	{
 		ThreadActionData.setup();
 		Stack txs = (Stack.get();
 
 		if (txs != null && !txs.isEmpty())
 		{
 			return (BasicActiontxs.peek();
 		}
 
 		return null;
 	}
 
 	public static void pushAction (BasicAction a)
 	{
 		pushAction(atrue);
 	}

By setting the register flag accordingly, information about the thread may not be propagated to the action, i.e., only the thread's notion of current changes.
 
 
 	public static void pushAction (BasicAction aboolean register)
 	{
 		Thread t = Thread.currentThread();
 		Stack txs = (Stack.get();
 
 		if (txs == null)
 		{
 			txs = new Stack();
 			txs.push(a);
 
 		}
 		else
 			txs.push(a);
 
 		if (register)
 	}

Put back the entire hierarchy, removing whatever is already there.
 
	public static void restoreActions (BasicAction act)
	{
		if (act != null)
		{
			/*
			 * First get the hierarchy from the bottom up.
			 */
			java.util.Stack s = new java.util.Stack();
			BasicAction nextLevel = act.parent();
			s.push(act);
			while (nextLevel != null)
			{
				s.push(nextLevel);
				nextLevel = nextLevel.parent();
			}
			/*
			 * Now push the hierarchy onto the thread stack.
			 */
			try
			{
				while (!s.empty())
				{
				}
			}
			catch (Exception ex)
			{
			}
		}
	}
	public static BasicAction popAction () throws EmptyStackException
	{
		return popAction(ThreadUtil.getThreadId(), true);
	}
	public static BasicAction popAction (boolean unregister)
	{
		return popAction(ThreadUtil.getThreadId(), unregister);
	}
	public static BasicAction popAction (String threadId)
	{
		return popAction(threadIdtrue);
	}

By setting the unregister flag accordingly, information about the thread is not removed from the action.
	public static BasicAction popAction (String threadIdboolean unregister)
	{
		Stack txs = (Stack.get();
		if (txs != null)
		{
			BasicAction a = (BasicActiontxs.pop();
			if ((a != null) && (unregister))
			{
				a.removeChildThread(threadId);
			}
			if (txs.size() == 0)
			{
			}
			return a;
		}
		return null;
	}
	public static void purgeAction (BasicAction act)
	{
		ThreadActionData.purgeAction(act, Thread.currentThread(), true);
	}
	public static void purgeAction (BasicAction actThread t)
	{
		ThreadActionData.purgeAction(actttrue);
	}
	public static void purgeAction (BasicAction actThread tboolean unregister)
	{
		if ((act != null) && (unregister))
        {
			act.removeChildThread(ThreadUtil.getThreadId(t));
        }
		Stack txs = (Stack.get();
		if (txs != null)
		{
			txs.removeElement(act);
			if (txs.size() == 0)
			{
			}
		}
	}
	public static void purgeActions ()
	{
		purgeActions(Thread.currentThread(), true);
	}
	public static void purgeActions (Thread t)
	{
		purgeActions(ttrue);
	}
	public static void purgeActions (Thread tboolean unregister)
	{
		Stack txs = (Stack.get();
		if (txs != null)
		{
			if (unregister)
			{
				while (!txs.empty())
				{
					BasicAction act = (BasicActiontxs.pop();
					if (act != null)
                    {
						act.removeChildThread(ThreadUtil.getThreadId(t));
                    }
				}
			}
		}
	}

Add a per thread setup object to the global list. This should only happen before the transaction service really begins, or you risk having some threads see one view of the list that is different to other threads.

Parameters:
s the setup to add.
	public static void addSetup (ThreadSetup s)
	{
		synchronized ()
		{
		}
	}

Remove a per thread setup object to the global list. This should only happen after the transaction service really ends, or you risk having some threads see one view of the list that is different to other threads.

Parameters:
s the setup to add.
	public static boolean removeSetup (ThreadSetup s)
	{
		synchronized ()
		{
		}
	}
	private static void setup ()
	{
		for (int i = 0; i < .size(); i++)
		{
			if (s != null)
				s.setup();
		}
	}
	private static ThreadLocal _threadList = new ThreadLocal();
	private static ArrayList _threadSetups = new ArrayList();
New to GrepCode? Check out our FAQ X