[jboss-cvs] JBossAS SVN: r72743 - projects/jboss-aspects/trunk/current-invocation/src/main/java/org/jboss/aspects/currentinvocation.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Apr 25 19:36:41 EDT 2008
Author: ALRubinger
Date: 2008-04-25 19:36:41 -0400 (Fri, 25 Apr 2008)
New Revision: 72743
Modified:
projects/jboss-aspects/trunk/current-invocation/src/main/java/org/jboss/aspects/currentinvocation/CurrentInvocation.java
projects/jboss-aspects/trunk/current-invocation/src/main/java/org/jboss/aspects/currentinvocation/CurrentInvocationInterceptor.java
Log:
[JBASPECT-8] Implemented stack-based registry of Invocations to handle subinvocations
Modified: projects/jboss-aspects/trunk/current-invocation/src/main/java/org/jboss/aspects/currentinvocation/CurrentInvocation.java
===================================================================
--- projects/jboss-aspects/trunk/current-invocation/src/main/java/org/jboss/aspects/currentinvocation/CurrentInvocation.java 2008-04-25 20:49:13 UTC (rev 72742)
+++ projects/jboss-aspects/trunk/current-invocation/src/main/java/org/jboss/aspects/currentinvocation/CurrentInvocation.java 2008-04-25 23:36:41 UTC (rev 72743)
@@ -21,6 +21,9 @@
*/
package org.jboss.aspects.currentinvocation;
+import java.util.EmptyStackException;
+import java.util.Stack;
+
import org.jboss.aop.joinpoint.Invocation;
import org.jboss.logging.Logger;
@@ -54,14 +57,7 @@
/*
* Registry for the current Invocation
*/
- private static final ThreadLocal<Invocation> registry = new ThreadLocal<Invocation>()
- {
- @Override
- protected Invocation initialValue()
- {
- return null;
- }
- };
+ private static final StackThreadLocal<Invocation> registry = new StackThreadLocal<Invocation>();
// -------------------------------------------------------------------------------------------------||
// Functional Methods ------------------------------------------------------------------------------||
@@ -76,40 +72,88 @@
*/
public static Invocation getCurrentInvocation()
{
- return CurrentInvocation.getRegistry().get();
+ try
+ {
+ return CurrentInvocation.getRegistry().peek();
+ }
+ // In case there's no invocation on the stack
+ catch (EmptyStackException ese)
+ {
+ return null;
+ }
}
/**
- * Clears the current Thread / request association
- * with an Invocation, if one exists
+ * Associates the specified invocation with the current
+ * Thread / request and sets it as the current invocation
+ *
+ * @param invocation
*/
- static void clear()
+ static void registerInvocation(Invocation invocation)
{
// Log
- logger.trace("Clearing Thread " + Thread.currentThread().toString() + " of association with Invocation");
- CurrentInvocation.getRegistry().remove();
+ logger.trace("Placing invocation " + invocation + " into scope for Thread " + Thread.currentThread().toString());
+
+ // Push
+ CurrentInvocation.getRegistry().push(invocation);
}
/**
- * Associates the specified invocation with the current
- * Thread / request
- *
- * @param invocation
+ * Deregisters the current invocation
*/
- static void setCurrentInvocation(Invocation invocation)
+ static void deregisterCurrentInvocation()
{
- // Log
- logger.trace("Placing invocation " + invocation + " into scope for Thread " + Thread.currentThread().toString());
- CurrentInvocation.getRegistry().set(invocation);
+ // Pop
+ Invocation current = CurrentInvocation.getRegistry().pop();
+
+ // Log and pop
+ logger
+ .trace("Cleared Thread " + Thread.currentThread().toString() + " of association with Invocation " + current);
}
// -------------------------------------------------------------------------------------------------||
// Accessors ---------------------------------------------------------------------------------------||
// -------------------------------------------------------------------------------------------------||
- private static ThreadLocal<Invocation> getRegistry()
+ private static StackThreadLocal<Invocation> getRegistry()
{
return CurrentInvocation.registry;
}
+ // -------------------------------------------------------------------------------------------------||
+ // Inner Classes ----------------------------------------------------------------------------------||
+ // -------------------------------------------------------------------------------------------------||
+
+ /**
+ * StackThreadLocal
+ *
+ * An Enhanced ThreadLocal implementation using a stack-based
+ * backend to push/pop Invocations
+ */
+ private static class StackThreadLocal<T extends Invocation> extends ThreadLocal<Stack<T>>
+ {
+
+ public T peek()
+ {
+ return this.get().peek();
+ }
+
+ public void push(T invocation)
+ {
+ this.get().push(invocation);
+ }
+
+ public T pop()
+ {
+ return this.get().pop();
+ }
+
+ @Override
+ protected Stack<T> initialValue()
+ {
+ // Initialize to a new Stack
+ return new Stack<T>();
+ }
+ }
+
}
Modified: projects/jboss-aspects/trunk/current-invocation/src/main/java/org/jboss/aspects/currentinvocation/CurrentInvocationInterceptor.java
===================================================================
--- projects/jboss-aspects/trunk/current-invocation/src/main/java/org/jboss/aspects/currentinvocation/CurrentInvocationInterceptor.java 2008-04-25 20:49:13 UTC (rev 72742)
+++ projects/jboss-aspects/trunk/current-invocation/src/main/java/org/jboss/aspects/currentinvocation/CurrentInvocationInterceptor.java 2008-04-25 23:36:41 UTC (rev 72743)
@@ -61,15 +61,15 @@
try
{
// Place the Invocation in Request scope
- CurrentInvocation.setCurrentInvocation(invocation);
+ CurrentInvocation.registerInvocation(invocation);
// Carry on
return invocation.invokeNext();
}
finally
{
- // Clean up for return to Thread Pool
- CurrentInvocation.clear();
+ // Clean up from this invocation
+ CurrentInvocation.deregisterCurrentInvocation();
}
}
}
More information about the jboss-cvs-commits
mailing list