1 package org.apache.jcs.engine;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.IOException;
23 import java.io.Serializable;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.apache.jcs.engine.behavior.ICache;
28 import org.apache.jcs.engine.behavior.ICacheElement;
29 import org.apache.jcs.engine.behavior.ICacheListener;
30
31 /***
32 * Used for Cache-to-Cache messaging purposes. These are used in the balking
33 * facades in the lateral and remote caches.
34 */
35 public class CacheAdaptor
36 implements ICacheListener
37 {
38 /*** The logger */
39 private final static Log log = LogFactory.getLog( CacheAdaptor.class );
40
41 /*** The cache we are adadpting. */
42 private final ICache cache;
43
44 /*** The unique id of this listener. */
45 protected long listenerId = 0;
46
47 /***
48 * Sets the listenerId attribute of the CacheAdaptor object
49 * <p>
50 * @param id
51 * The new listenerId value
52 * @throws IOException
53 */
54 public void setListenerId( long id )
55 throws IOException
56 {
57 this.listenerId = id;
58 log.debug( "listenerId = " + id );
59 }
60
61 /***
62 * Gets the listenerId attribute of the CacheAdaptor object
63 * <p>
64 * @return The listenerId value
65 * @throws IOException
66 */
67 public long getListenerId()
68 throws IOException
69 {
70 return this.listenerId;
71 }
72
73 /***
74 * Constructor for the CacheAdaptor object
75 * <p>
76 * @param cache
77 */
78 public CacheAdaptor( ICache cache )
79 {
80 this.cache = cache;
81 }
82
83 /***
84 * Puts an item into the cache.
85 * <p>
86 * @param item
87 * @throws IOException
88 */
89 public void handlePut( ICacheElement item )
90 throws IOException
91 {
92 try
93 {
94 cache.update( item );
95 }
96 catch ( Exception e )
97 {
98
99 }
100 }
101
102 /***
103 * Removes an item.
104 * <p>
105 * @param cacheName
106 * @param key
107 * @throws IOException
108 */
109 public void handleRemove( String cacheName, Serializable key )
110 throws IOException
111 {
112 cache.remove( key );
113 }
114
115 /***
116 * Clears the region.
117 * <p>
118 * @param cacheName
119 * @throws IOException
120 */
121 public void handleRemoveAll( String cacheName )
122 throws IOException
123 {
124 cache.removeAll();
125 }
126
127 /***
128 * Shutdown call.
129 * <p>
130 * @param cacheName
131 * @throws IOException
132 */
133 public void handleDispose( String cacheName )
134 throws IOException
135 {
136 cache.dispose();
137 }
138 }