diff options
Diffstat (limited to 'tests/bugs196/558995/foo/SynchronizedAspect.aj')
-rw-r--r-- | tests/bugs196/558995/foo/SynchronizedAspect.aj | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/tests/bugs196/558995/foo/SynchronizedAspect.aj b/tests/bugs196/558995/foo/SynchronizedAspect.aj new file mode 100644 index 000000000..127778742 --- /dev/null +++ b/tests/bugs196/558995/foo/SynchronizedAspect.aj @@ -0,0 +1,91 @@ +package foo; + +import org.aspectj.lang.annotation.SuppressAjWarnings; + +public aspect SynchronizedAspect perthis(@this(Synchronized)) { + +// private static final Logger log = LogManager.getLogger(SynchronizedAspect.class); +// private Lock objectLock = new ReentrantLock(); +// private static long timeout = 1800; +// private static TimeUnit unit = TimeUnit.SECONDS; +// private static boolean timeoutInitialized = false; + +// @SuppressWarnings({"rawtypes"}) +// private final static synchronized void initTimeout(Class cl) { +// timeout = SynchronizedStaticAspect.aspectOf(cl).timeout; +// unit = SynchronizedStaticAspect.aspectOf(cl).unit; +// timeoutInitialized = true; +// log.trace("timeout inialized with " + timeout + " " + unit); +// } + + pointcut synchronizedMethods() : + execution(@Synchronized !synchronized !static * *..*.*(..)) + ; + + pointcut synchronizedStaticMethods() : + execution(@Synchronized !synchronized static * *..*.*(..)) + ; + + pointcut ignoredSynchronized() : + execution(@Synchronized * *..*.*(..)) + && !synchronizedMethods() + && !synchronizedStaticMethods() + ; + + declare warning : ignoredSynchronized() : + "@Synchronized is ignored here"; + + declare warning : + (synchronizedStaticMethods() || synchronizedMethods()) + && !@within(Synchronized) : + "@Synchronized is ignored here because @Synchronized for class is missing"; + + /** + * Uses the Lock class of Java 5 to put a synchronization wrapper around + * a method. Advantage of this Lock class is the posibility to use a + * timeout to avoid dead locks. + * + * @return the return value of the wrapped method + */ + @SuppressAjWarnings({"adviceDidNotMatch"}) + Object around() : synchronizedMethods() && @within(Synchronized) { +return proceed(); +/* + if (!timeoutInitialized) { + initTimeout(thisJoinPointStaticPart.getSignature().getDeclaringType()); + } + if (log.isTraceEnabled()) { + log.trace("synchronizing " + thisJoinPoint.getSignature().toShortString() + "..."); + } + try { + if (objectLock.tryLock(timeout, unit)) { + if (log.isTraceEnabled()) { + log.trace("lock granted for " + + thisJoinPoint.getSignature().toShortString()); + } + try { + return proceed(); + } finally { + objectLock.unlock(); + if (log.isTraceEnabled()) { + log.trace("lock released for " + + thisJoinPoint.getSignature().toShortString()); + } + } + } else { + String msg = "can't get " + objectLock + " for " + + thisJoinPoint.getSignature().toShortString() + + " after " + timeout + " " + unit; + log.error(msg); + throw new RuntimeException(msg); + } + } catch (InterruptedException ie) { + String msg = "interrupted: " + + thisJoinPoint.getSignature().toShortString(); + log.warn(msg, ie); + throw new RuntimeException(msg, ie); + } +*/ + } + +} |