KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > cache > CacheAC


1 /*
2   Copyright (C) 2002 Laurent Martelli <laurent@aopsys.com>
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public License
15   along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

17
18 package org.objectweb.jac.aspects.cache;
19
20 import java.util.Iterator JavaDoc;
21 import org.apache.log4j.Logger;
22 import org.objectweb.jac.core.AspectComponent;
23 import org.objectweb.jac.core.rtti.AbstractMethodItem;
24
25 /**
26  * This aspect handle caching of method results.
27  */

28
29 public class CacheAC extends AspectComponent implements CacheConf {
30     static final Logger logger = Logger.getLogger("cache");
31
32     public static final String JavaDoc IGNORED_PARAMETERS = "CacheAC.IGNORED_PARAMETERS";
33
34     /**
35      * Cache a method result.
36      *
37      * @param classExpr the classes
38      * @param methodExpr the methods cached
39      */

40     public void cache(String JavaDoc classExpr, String JavaDoc methodExpr)
41     {
42         logger.info("cache "+classExpr+"."+methodExpr);
43
44         pointcut("ALL",classExpr,methodExpr,
45                  "org.objectweb.jac.aspects.cache.CacheWrapper",
46                  null,NOT_SHARED);
47     }
48
49     public void cacheWithTimeStamps(
50         String JavaDoc classExpr, String JavaDoc methodExpr,
51         String JavaDoc stampsName)
52     {
53         logger.info("cache "+classExpr+"."+methodExpr);
54
55         pointcut(
56             "ALL", classExpr, methodExpr,
57             "org.objectweb.jac.aspects.cache.CacheWrapper",
58             new Object JavaDoc[] {stampsName},
59             null,
60             NOT_SHARED);
61     }
62
63     public void setIgnoredParameters(AbstractMethodItem method,
64                                      int[] ignored)
65     {
66         method.setAttribute(IGNORED_PARAMETERS,ignored);
67     }
68
69     public void invalidateCache() {
70         Iterator JavaDoc i = wrappers.iterator();
71         while(i.hasNext()) {
72             CacheWrapper wrapper = (CacheWrapper)i.next();
73             wrapper.invalidate();
74         }
75     }
76 }
77
Popular Tags