KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > util > CachePolicy


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.util;
23
24 /**
25  * Interface that specifies a policy for caches. <p>
26  * Implementation classes can implement a LRU policy, a random one,
27  * a MRU one, or any other suitable policy.
28  *
29  * @author <a HREF="mailto:simone.bordet@compaq.com">Simone Bordet</a>
30  * @version $Revision: 1958 $
31  */

32 public interface CachePolicy
33 {
34    /**
35     * Returns the object paired with the specified key if it's
36     * present in the cache, otherwise must return null. <br>
37     * Implementations of this method must have complexity of order O(1).
38     * Differently from {@link #peek} this method not only return whether
39     * the object is present in the cache or not, but also
40     * applies the implemented policy that will "refresh" the cached
41     * object in the cache, because this cached object
42     * was really requested.
43     *
44     * @param key the key paired with the object
45     * @see #peek
46     */

47    Object JavaDoc get(Object JavaDoc key);
48
49    /**
50     * Returns the object paired with the specified key if it's
51     * present in the cache, otherwise must return null. <br>
52     * Implementations of this method must have complexity of order O(1).
53     * This method should not apply the implemented caching policy to the
54     * object paired with the given key, so that a client can
55     * query if an object is cached without "refresh" its cache status. Real
56     * requests for the object must be done using {@link #get}.
57     *
58     * @param key the key paired with the object
59     * @see #get
60     */

61    Object JavaDoc peek(Object JavaDoc key);
62    
63    /**
64     * Inserts the specified object into the cache following the
65     * implemented policy. <br>
66     * Implementations of this method must have complexity of order O(1).
67     *
68     * @param key the key paired with the object
69     * @param object the object to cache
70     * @see #remove
71     */

72    void insert(Object JavaDoc key, Object JavaDoc object);
73    
74    /**
75     * Remove the cached object paired with the specified key. <br>
76     * Implementations of this method must have complexity of order O(1).
77     *
78     * @param key the key paired with the object
79     * @see #insert
80     */

81    void remove(Object JavaDoc key);
82    
83    /**
84     * Flushes the cached objects from the cache.
85     */

86    void flush();
87
88    /**
89     * Get the size of the cache.
90     */

91    int size();
92
93
94
95    /**
96     * create the service, do expensive operations etc
97     */

98    void create() throws Exception JavaDoc;
99    
100    /**
101     * start the service, create is already called
102     */

103    void start() throws Exception JavaDoc;
104    
105    /**
106     * stop the service
107     */

108    void stop();
109    
110    /**
111     * destroy the service, tear down
112     */

113    void destroy();
114 }
115
Popular Tags