KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > eviction > BaseEvictionPolicy


1 package org.jboss.cache.eviction;
2
3 import org.jboss.cache.CacheException;
4 import org.jboss.cache.CacheImpl;
5 import org.jboss.cache.Fqn;
6 import org.jboss.cache.NodeSPI;
7
8 import java.util.Set JavaDoc;
9
10 /**
11  * Base class implementation of EvictionPolicy and TreeCacheListener.
12  *
13  * @author Ben Wang 2-2004
14  * @author Daniel Huang - dhuang@jboss.org
15  * @version $Revision: 1.7 $
16  */

17 public abstract class BaseEvictionPolicy implements EvictionPolicy
18 {
19    protected CacheImpl cache_;
20
21    public BaseEvictionPolicy()
22    {
23    }
24
25    /** EvictionPolicy interface implementation */
26
27    /**
28     * Evict the node under given Fqn from cache.
29     *
30     * @param fqn The fqn of a node in cache.
31     * @throws Exception
32     */

33    public void evict(Fqn fqn) throws Exception JavaDoc
34    {
35       cache_.evict(fqn);
36    }
37
38    /**
39     * Return a set of child names under a given Fqn.
40     *
41     * @param fqn Get child names for given Fqn in cache.
42     * @return Set of children name as Objects
43     */

44    public Set JavaDoc getChildrenNames(Fqn fqn)
45    {
46       try
47       {
48          return cache_.getChildrenNames(fqn);
49       }
50       catch (CacheException e)
51       {
52          e.printStackTrace();
53       }
54       return null;
55    }
56
57    public boolean hasChild(Fqn fqn)
58    {
59       return cache_.hasChild(fqn);
60    }
61
62    public Object JavaDoc getCacheData(Fqn fqn, Object JavaDoc key)
63    {
64       try
65       {
66          NodeSPI n = cache_.peek(fqn);
67          if (n == null)
68          {
69             return null;
70          }
71
72          return n.getDirect(key);
73       }
74       catch (CacheException e)
75       {
76          throw new CacheException("Failed locating key for " + fqn, e);
77       }
78    }
79
80    public void configure(CacheImpl cache)
81    {
82       this.cache_ = cache;
83    }
84
85    /*
86     * (non-Javadoc)
87     * @see org.jboss.cache.eviction.EvictionPolicy#canIgnoreEvent(org.jboss.cache.Fqn)
88     *
89     */

90    public boolean canIgnoreEvent(Fqn fqn, NodeEventType eventType)
91    {
92       return false;
93    }
94 }
95
Popular Tags