01: /**
02: * Copyright 2003-2007 Luck Consulting Pty Ltd
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */package net.sf.ehcache.extension;
16:
17: import net.sf.ehcache.CacheException;
18: import net.sf.ehcache.Ehcache;
19: import net.sf.ehcache.Status;
20:
21: /**
22: * This is a general purpose mechanism to allow generic extensions to a Cache.
23: * <p/>
24: * CacheExtensions are tied into the Cache lifecycle. For that reason this interface has the lifecycle
25: * methods.
26: * <p/>
27: * CacheExtensions are created using the CacheExtensionFactory which has a <code>createCacheCacheExtension()</code>
28: * method which takes as a parameter a Cache and properties. It can thus call back into any public method on Cache,
29: * including, of course, the load methods.
30: * <p/>
31: * CacheExtensions are suitable for timing services, where you want to create a timer to perform
32: * cache operations. The other way of adding Cache behaviour is to decorate a cache. See
33: * {@link net.sf.ehcache.constructs.blocking.BlockingCache} for an example of how to do this.
34: * <p/>
35: * Because a CacheExtension holds a reference to a Cache, the CacheExtension can do things such as registering a
36: * CacheEventListener or even a CacheManagerEventListener, all from within a CacheExtension, creating more
37: * opportunities for customisation.
38: *
39: * @author <a href="mailto:gluck@gregluck.com">Greg Luck</a>
40: * @version $Id: CacheExtension.java 535 2007-08-12 01:32:14Z gregluck $
41: */
42: public interface CacheExtension {
43:
44: /**
45: * Notifies providers to initialise themselves.
46: * <p/>
47: * This method is called during the Cache's initialise method after it has changed it's status to alive.
48: * Cache operations are legal in this method.
49: *
50: * @throws CacheException
51: */
52: void init();
53:
54: /**
55: * Providers may be doing all sorts of exotic things and need to be able to clean up on
56: * dispose.
57: * <p/>
58: * Cache operations are illegal when this method is called. The cache itself is partly disposed when this method
59: * is called.
60: *
61: * @throws CacheException
62: */
63: void dispose() throws CacheException;
64:
65: /**
66: * Creates a clone of this extension. This method will only be called by ehcache before a
67: * cache is initialized.
68: * <p/>
69: * Implementations should throw CloneNotSupportedException if they do not support clone but that
70: * will stop them from being used with defaultCache.
71: *
72: * @return a clone
73: * @throws CloneNotSupportedException if the extension could not be cloned.
74: */
75: public CacheExtension clone(Ehcache cache)
76: throws CloneNotSupportedException;
77:
78: /**
79: * @return the status of the extension
80: */
81: public Status getStatus();
82: }
|