Author: echatellier Date: 2012-08-24 14:57:23 +0200 (Fri, 24 Aug 2012) New Revision: 3729 Url: http://forge.codelutin.com/repositories/revision/isis-fish/3729 Log: fixes #1411 : Add annotation to not cache method or class call Added: trunk/src/main/java/fr/ifremer/isisfish/util/Nocache.java Modified: trunk/src/main/java/fr/ifremer/isisfish/aspect/Cache.java Modified: trunk/src/main/java/fr/ifremer/isisfish/aspect/Cache.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/aspect/Cache.java 2012-08-24 12:19:40 UTC (rev 3728) +++ trunk/src/main/java/fr/ifremer/isisfish/aspect/Cache.java 2012-08-24 12:57:23 UTC (rev 3729) @@ -47,6 +47,7 @@ import fr.ifremer.isisfish.IsisFishRuntimeException; import fr.ifremer.isisfish.simulator.SimulationContext; +import fr.ifremer.isisfish.util.Nocache; /** * Cache aspect. @@ -61,7 +62,7 @@ */ @Aspect("perJVM") public class Cache { - + /** to use log facility, just put in your code: log.info(\"...\"); */ static private Log log = LogFactory.getLog(Cache.class); @@ -117,23 +118,32 @@ @Around("scriptsMethod") public Object call(final JoinPoint jp) throws Throwable { totalCall++; - Object key = computeKey(jp); - Object result = cache.get(key); - if (result == null) { - - // computation increment (/ by 0) - // FIXME need to be called, but fail with empty stack - //Method method = ((MethodSignature)jp.getSignature()).getMethod(); - //getTrace().traceAfterComputation(method); + Object result = null; + Method method = ((MethodSignature)jp.getSignature()).getMethod(); + if (method.getAnnotation(Nocache.class) != null || + method.getDeclaringClass().getAnnotation(Nocache.class) != null) { result = realCall(jp); -// addListenerFor(key); // pas necessaire car on a la date et pour une date donnée rien ne peut changer - if (result != null) { // util pour les methodes retournant void, ne fonctionne pas si on met AND !execute(void *(..)) dans l'aspect. En fait fonction seulement si utilisé avec les traces :( - cache.put(key, result); + } else { + Object key = computeKey(jp); + result = cache.get(key); + if (result == null) { + + // computation increment (/ by 0) + // FIXME need to be called, but fail with empty stack + //Method method = ((MethodSignature)jp.getSignature()).getMethod(); + //getTrace().traceAfterComputation(method); + + result = realCall(jp); + // addListenerFor(key); // pas necessaire car on a la date et pour une date donnée rien ne peut changer + if (result != null) { // util pour les methodes retournant void, ne fonctionne pas si on met AND !execute(void *(..)) dans l'aspect. En fait fonction seulement si utilisé avec les traces :( + cache.put(key, result); + } + } else { + cacheUsed++; } - } else { - cacheUsed++; } + if (log.isTraceEnabled()) { log.trace(((MethodSignature)jp.getSignature()).getMethod() + " args " + Arrays.toString(((MethodRtti)jp.getRtti()).getParameterValues()) Added: trunk/src/main/java/fr/ifremer/isisfish/util/Nocache.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/util/Nocache.java (rev 0) +++ trunk/src/main/java/fr/ifremer/isisfish/util/Nocache.java 2012-08-24 12:57:23 UTC (rev 3729) @@ -0,0 +1,47 @@ +/* + * #%L + * IsisFish + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Ifremer, Code Lutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-2.0.html>. + * #L% + */ + +package fr.ifremer.isisfish.util; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation pour specifier à l'aspect du cache que l'on ne souhaite ne pas + * mettre en cache l'appel d'une méthode ou des méthodes d'une classe. + * + * @author echatellier + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.METHOD, ElementType.TYPE}) +public @interface Nocache { + +} Property changes on: trunk/src/main/java/fr/ifremer/isisfish/util/Nocache.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL