[jboss-cvs] JBossAS SVN: r68510 - in projects/aop/trunk/aop/src/main/org/jboss/aop: instrument and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Dec 21 07:43:37 EST 2007
Author: flavia.rainone at jboss.com
Date: 2007-12-21 07:43:37 -0500 (Fri, 21 Dec 2007)
New Revision: 68510
Modified:
projects/aop/trunk/aop/src/main/org/jboss/aop/JoinPointInfo.java
projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorCallerTransformer.java
projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorConstructionTransformer.java
projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorConstructorExecutionTransformer.java
projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorFieldAccessTransformer.java
projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorInstrumentor.java
projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorMethodExecutionTransformer.java
Log:
[JBAOP-480] Sync mechanism added.
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/JoinPointInfo.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/JoinPointInfo.java 2007-12-21 12:39:35 UTC (rev 68509)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/JoinPointInfo.java 2007-12-21 12:43:37 UTC (rev 68510)
@@ -23,7 +23,7 @@
import java.lang.ref.WeakReference;
import java.util.ArrayList;
-import java.util.Collection;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.jboss.aop.advice.GeneratedAdvisorInterceptor;
import org.jboss.aop.advice.Interceptor;
@@ -32,6 +32,8 @@
public abstract class JoinPointInfo implements JoinPointBean
{
+ private ReentrantReadWriteLock interceptorChainLock = new ReentrantReadWriteLock();
+
private Interceptor[] interceptors;
private ArrayList<Interceptor> interceptorChain = new ArrayList<Interceptor>();
@@ -97,21 +99,37 @@
public boolean hasAdvices()
{
- return (interceptors != null && interceptors.length > 0);
+ this.interceptorChainLock.readLock().lock();
+ try
+ {
+ return (interceptors != null && interceptors.length > 0);
+ }
+ finally
+ {
+ this.interceptorChainLock.readLock().unlock();
+ }
}
public boolean equalChains(Interceptor[] otherInterceptors)
{
- if (this.interceptors == null && otherInterceptors == null) return true;
- if (!(this.interceptors != null && otherInterceptors != null))return false;
- if (this.interceptors.length != otherInterceptors.length) return false;
+ this.interceptorChainLock.readLock().lock();
+ try
+ {
+ if (this.interceptors == null && otherInterceptors == null) return true;
+ if (!(this.interceptors != null && otherInterceptors != null))return false;
+ if (this.interceptors.length != otherInterceptors.length) return false;
- for (int i = 0 ; i < this.interceptors.length ; i++)
+ for (int i = 0 ; i < this.interceptors.length ; i++)
+ {
+ if(!this.interceptors[i].equals(otherInterceptors[i])) return false;
+ }
+
+ return true;
+ }
+ finally
{
- if(!this.interceptors[i].equals(otherInterceptors[i])) return false;
+ this.interceptorChainLock.readLock().unlock();
}
-
- return true;
}
public Joinpoint getJoinpoint()
@@ -124,16 +142,34 @@
}
public ArrayList<Interceptor> getInterceptorChain() {
- return interceptorChain;
+ this.interceptorChainLock.readLock().lock();
+ try
+ {
+ return interceptorChain;
+ }
+ finally
+ {
+ this.interceptorChainLock.readLock().unlock();
+ }
}
public Interceptor[] getInterceptors() {
- return interceptors;
+ this.interceptorChainLock.readLock().lock();
+ try
+ {
+ return interceptors;
+ }
+ finally
+ {
+ this.interceptorChainLock.readLock().unlock();
+ }
}
public void setInterceptors(Interceptor[] interceptors) {
+ this.interceptorChainLock.writeLock().lock();
adviceString = null;
this.interceptors = interceptors;
+ this.interceptorChainLock.writeLock().unlock();
}
protected abstract Joinpoint internalGetJoinpoint();
@@ -161,14 +197,24 @@
public void cloneChains(JoinPointInfo other)
{
- interceptorChain = (ArrayList)other.interceptorChain.clone();
- if (other.interceptors == null)
+ this.interceptorChainLock.writeLock().lock();
+ other.interceptorChainLock.readLock().lock();
+ try
{
- interceptors = null;
+ interceptorChain = (ArrayList) other.interceptorChain.clone();
+ if (other.interceptors == null)
+ {
+ interceptors = null;
+ }
+ else
+ {
+ interceptors = other.interceptors.clone();
+ }
}
- else
+ finally
{
- interceptors = other.interceptors.clone();
+ this.interceptorChainLock.writeLock().unlock();
+ other.interceptorChainLock.readLock().unlock();
}
}
@@ -198,4 +244,9 @@
return adviceString;
}
+
+ public final ReentrantReadWriteLock.ReadLock getInterceptorChainReadLock()
+ {
+ return this.interceptorChainLock.readLock();
+ }
}
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorCallerTransformer.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorCallerTransformer.java 2007-12-21 12:39:35 UTC (rev 68509)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorCallerTransformer.java 2007-12-21 12:43:37 UTC (rev 68510)
@@ -144,7 +144,16 @@
"{" +
" if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" +
" {" +
- " super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");" +
+ GeneratedAdvisorInstrumentor.generateInterceptorChainLockCode(infoName) +
+ " try" +
+ " {" +
+ " if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" +
+ " {" +
+ " super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");" +
+ " }" +
+ " } finally {" +
+ GeneratedAdvisorInstrumentor.generateInterceptorChainUnlockCode(infoName) +
+ " }" +
" }" +
" if (" + joinpointName + " == null)" +
" { " +
@@ -246,7 +255,16 @@
"{" +
" if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" +
" {" +
- " super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");" +
+ GeneratedAdvisorInstrumentor.generateInterceptorChainLockCode(infoName) +
+ " try" +
+ " {" +
+ " if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" +
+ " {" +
+ " super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");" +
+ " }" +
+ " } finally {" +
+ GeneratedAdvisorInstrumentor.generateInterceptorChainUnlockCode(infoName) +
+ " }" +
" }" +
" if (" + joinpointName + " == null)" +
" { " +
@@ -338,7 +356,16 @@
code.append("{");
code.append(" if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())");
code.append(" {");
- code.append(" super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");");
+ code.append(GeneratedAdvisorInstrumentor.generateInterceptorChainLockCode(infoName));
+ code.append(" try" );
+ code.append(" {");
+ code.append(" if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())");
+ code.append(" {");
+ code.append(" super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");");
+ code.append(" }");
+ code.append(" } finally {");
+ code.append(GeneratedAdvisorInstrumentor.generateInterceptorChainUnlockCode(infoName));
+ code.append(" }");
code.append(" }");
code.append(" if (" + joinpointName + " == null)");
code.append(" { ");
@@ -419,7 +446,16 @@
"{" +
" if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" +
" {" +
- " super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");" +
+ GeneratedAdvisorInstrumentor.generateInterceptorChainLockCode(infoName) +
+ " try" +
+ " {" +
+ " if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" +
+ " {" +
+ " super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");" +
+ " }" +
+ " } finally {" +
+ GeneratedAdvisorInstrumentor.generateInterceptorChainUnlockCode(infoName) +
+ " }" +
" }" +
" if (" + joinpointName + " == null)" +
" { " +
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorConstructionTransformer.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorConstructionTransformer.java 2007-12-21 12:39:35 UTC (rev 68509)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorConstructionTransformer.java 2007-12-21 12:43:37 UTC (rev 68510)
@@ -147,7 +147,16 @@
"{" +
" if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" +
" {" +
- " super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");" +
+ GeneratedAdvisorInstrumentor.generateInterceptorChainLockCode(infoName) +
+ " try" +
+ " {" +
+ " if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" +
+ " {" +
+ " super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");" +
+ " }" +
+ " } finally {" +
+ GeneratedAdvisorInstrumentor.generateInterceptorChainUnlockCode(infoName) +
+ " }" +
" }" +
" if (" + joinpointName + " != null)" +
" { " +
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorConstructorExecutionTransformer.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorConstructorExecutionTransformer.java 2007-12-21 12:39:35 UTC (rev 68509)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorConstructorExecutionTransformer.java 2007-12-21 12:43:37 UTC (rev 68510)
@@ -223,7 +223,16 @@
"{" +
" if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" +
" {" +
- " super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");" +
+ GeneratedAdvisorInstrumentor.generateInterceptorChainLockCode(infoName) +
+ " try" +
+ " {" +
+ " if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" +
+ " {" +
+ " super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");" +
+ " }" +
+ " } finally {" +
+ GeneratedAdvisorInstrumentor.generateInterceptorChainUnlockCode(infoName) +
+ " }" +
" }" +
" if (" + joinpointName + " == null)" +
" { " +
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorFieldAccessTransformer.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorFieldAccessTransformer.java 2007-12-21 12:39:35 UTC (rev 68509)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorFieldAccessTransformer.java 2007-12-21 12:43:37 UTC (rev 68510)
@@ -264,7 +264,16 @@
"{" +
" if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" +
" {" +
- " super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");" +
+ GeneratedAdvisorInstrumentor.generateInterceptorChainLockCode(infoName) +
+ " try" +
+ " {" +
+ " if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" +
+ " {" +
+ " super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");" +
+ " }" +
+ " } finally {" +
+ GeneratedAdvisorInstrumentor.generateInterceptorChainUnlockCode(infoName) +
+ " }" +
" }" +
" if (" + joinpointName + " == null)" +
" { " +
@@ -282,7 +291,16 @@
"{" +
" if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" +
" {" +
- " super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");" +
+ GeneratedAdvisorInstrumentor.generateInterceptorChainLockCode(infoName) +
+ " try" +
+ " {" +
+ " if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" +
+ " {" +
+ " super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");" +
+ " }" +
+ " } finally {" +
+ GeneratedAdvisorInstrumentor.generateInterceptorChainUnlockCode(infoName) +
+ " }" +
" }" +
" if (" + joinpointName + " == null)" +
" { " +
@@ -314,7 +332,16 @@
" " + getArrayWriteRegistration(shouldReplaceArrayAccess, targetString, field, fieldString, "$2") +
" if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" +
" {" +
- " super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");" +
+ GeneratedAdvisorInstrumentor.generateInterceptorChainLockCode(infoName) +
+ " try" +
+ " {" +
+ " if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" +
+ " {" +
+ " super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");" +
+ " }" +
+ " } finally {" +
+ GeneratedAdvisorInstrumentor.generateInterceptorChainUnlockCode(infoName) +
+ " }" +
" }" +
" if (" + joinpointName + " == null)" +
" { " +
@@ -335,7 +362,16 @@
" " + getArrayWriteRegistration(shouldReplaceArrayAccess, targetString, field, fieldString, "$2") +
" if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" +
" {" +
- " super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");" +
+ GeneratedAdvisorInstrumentor.generateInterceptorChainLockCode(infoName) +
+ " try" +
+ " {" +
+ " if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" +
+ " {" +
+ " super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");" +
+ " }" +
+ " } finally {" +
+ GeneratedAdvisorInstrumentor.generateInterceptorChainUnlockCode(infoName) +
+ " }" +
" }" +
" if (" + joinpointName + " == null)" +
" { " +
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorInstrumentor.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorInstrumentor.java 2007-12-21 12:39:35 UTC (rev 68509)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorInstrumentor.java 2007-12-21 12:43:37 UTC (rev 68510)
@@ -831,7 +831,17 @@
addCodeToInitialiseMethod(genadvisor, infoName + " = " + init + ";", INITIALISE_CALLERS);
}
-
+ // TODO remove this code and put it somewhere common to all ga transformers.
+ static String generateInterceptorChainLockCode(String infoName)
+ {
+ return infoName + ".getInterceptorChainReadLock().lock();";
+ }
+
+ static String generateInterceptorChainUnlockCode(String infoName)
+ {
+ return infoName + ".getInterceptorChainReadLock().unlock();";
+ }
+
private void addCodeToInitialiseMethod(CtClass clazz, String code, String methodName) throws NotFoundException
{
CtMethod method = clazz.getDeclaredMethod(methodName);
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorMethodExecutionTransformer.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorMethodExecutionTransformer.java 2007-12-21 12:39:35 UTC (rev 68509)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorMethodExecutionTransformer.java 2007-12-21 12:43:37 UTC (rev 68510)
@@ -436,7 +436,16 @@
"{" +
" if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" +
" {" +
- " super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");" +
+ GeneratedAdvisorInstrumentor.generateInterceptorChainLockCode(infoName) +
+ " try" +
+ " {" +
+ " if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" +
+ " {" +
+ " super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");" +
+ " }" +
+ " } finally {" +
+ GeneratedAdvisorInstrumentor.generateInterceptorChainUnlockCode(infoName) +
+ " }" +
" }" +
" if (" + joinpointName + " == null)" +
" { " +
@@ -460,7 +469,16 @@
"{" +
" if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" +
" {" +
- " super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");" +
+ GeneratedAdvisorInstrumentor.generateInterceptorChainLockCode(infoName) +
+ " try" +
+ " {" +
+ " if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" +
+ " {" +
+ " super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");" +
+ " }" +
+ " } finally {" +
+ GeneratedAdvisorInstrumentor.generateInterceptorChainUnlockCode(infoName) +
+ " }" +
" }" +
" if (" + joinpointName + " == null)" +
" { " +
More information about the jboss-cvs-commits
mailing list