Hi, Andy. I'm still using @Aspectj, and also the signature is fine (since it
worked as soon as I removed the @Configurable annotation so that it's not
being managed by spring). For the lack of a better example, below is what I
have. To re-iterate, this aspect works fine without
@Configurable/@Autowired.


package ramin.aj;

import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;

import org.apache.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;

//@Configurable(dependencyCheck = true)
@Aspect
public abstract class AspectCache {

        public AspectCache() {
                logger = Logger.getLogger("CSSOPASPECTLOGGER");

                // these values will be set by spring, however we need to have 
values
                // for as long as spring has not initialized us
                exprationPeriod = 300;
                cleanupPeriod = 3600;
                ExecutorService threadExecutor = 
Executors.newSingleThreadExecutor();
                threadExecutor.execute(new Runnable() {
                        public void run() {
                                while (true) {
                                        try {
                                                Thread.sleep(cleanupPeriod * 
1000);
                                                for (Object k : cache.keySet()) 
{
                                                        Value v = cache.get(k);
                                                        if 
(System.currentTimeMillis() - v.whenCached > exprationPeriod *
1000) {
                                                                if 
(logger.isDebugEnabled()) {
                                                                        
logger.debug("expiring cache entry key = "
                                                                                
        + k + " value = " + v);
                                                                }
                                                                cache.remove(k);
                                                        }
                                                }
                                                if (logger.isDebugEnabled()) {
                                                        logger.debug("cache[" + 
exprationPeriod + ","
                                                                        + 
cleanupPeriod + "] has " + cache.size()
                                                                        + " 
elements");
                                                }
                                        } catch (Throwable e) {
                                                logger.error("caching aspect 
cleanup thread: " + e);
                                        }

                                }
                        }
                });
        }

        protected final Logger logger;

        private ConcurrentMap<Object, Value> cache = new 
ConcurrentHashMap<Object,
Value>();
        
//      @Autowired
//      private ConfigManager cf;
        
        private long exprationPeriod; // in seconds needs to be set through 
config
        private long cleanupPeriod; // in seconds needs to be set through config

        @Pointcut
        protected abstract void caching();

        @Around("caching()")
        public Object doProcess(final ProceedingJoinPoint pjp) throws Throwable 
{
                Object[] arguments = pjp.getArgs();
                Object k = arguments[0];

                Value v = cache.get(k);
                if (v == null
                                || System.currentTimeMillis() - v.whenCached > 
exprationPeriod * 1000) {
                        cache.remove(k);
                        Callable eval = new Callable() {
                                public Object call() throws 
InterruptedException {
                                        try {
                                                return pjp.proceed();
                                        } catch (Throwable e) {
                                                logger.error("caching aspect: " 
+ e);
                                                throw new 
InterruptedException();
                                        }
                                }
                        };
                        FutureTask ft = new FutureTask(eval);
                        Value newValue = new Value();
                        newValue.whenCached = System.currentTimeMillis();
                        newValue.futureValue = ft;
                        v = cache.putIfAbsent(k, newValue);
                        if (v == null) {
                                v = newValue;
                                newValue.futureValue.run();
                                if (logger.isDebugEnabled()) {
                                        logger.debug("caching value from cache 
key = " + k
                                                        + " value = " + v);
                                }
                        } else {
                                if (logger.isDebugEnabled()) {
                                        logger.debug("retrieving value from 
cache key = " + k
                                                        + " value = " + v);
                                }
                        }
                }
                return v.futureValue.get();
        }

        private class Value {
                private FutureTask futureValue;
                private long whenCached;

                @Override
                public String toString() {
                        String s = "";
                        try {
                                s = "Value[" + futureValue.get().toString() + 
"," + whenCached
                                                + "]";
                        } catch (Exception e) {
                                logger.error("caching aspect: " + e);
                        }
                        return s;
                }
        }

}



The Pointcut as catching some method which is in the form of 

"SomeType computeTheValueOf(SomeOtherType)"
-- 
View this message in context: 
http://aspectj.2085585.n4.nabble.com/java-lang-VerifyError-class-MyAspect-method-init-signature-V-Illegal-type-in-constant-pool-tp3209499p3209728.html
Sent from the AspectJ - users mailing list archive at Nabble.com.
_______________________________________________
aspectj-users mailing list
aspectj-users@eclipse.org
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Reply via email to