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 private final static Log log = LogFactory.getLog( CacheAdaptor.class );
39
40 private final ICache cache;
41
42 /*** The unique id of this listner. */
43 protected long listenerId = 0;
44
45 /***
46 * Sets the listenerId attribute of the CacheAdaptor object
47 * <p>
48 * @param id
49 * The new listenerId value
50 * @throws IOException
51 */
52 public void setListenerId( long id )
53 throws IOException
54 {
55 this.listenerId = id;
56 log.debug( "listenerId = " + id );
57 }
58
59 /***
60 * Gets the listenerId attribute of the CacheAdaptor object
61 * <p>
62 * @return The listenerId value
63 * @throws IOException
64 */
65 public long getListenerId()
66 throws IOException
67 {
68 return this.listenerId;
69 }
70
71 /***
72 * Constructor for the CacheAdaptor object
73 * @param cache
74 */
75 public CacheAdaptor( ICache cache )
76 {
77 this.cache = cache;
78 }
79
80 /***
81 * Puts an item into the cache.
82 * <p>
83 * @param item
84 * @throws IOException
85 */
86 public void handlePut( ICacheElement item )
87 throws IOException
88 {
89 try
90 {
91 cache.update( item );
92 }
93 catch ( Exception e )
94 {
95
96 }
97 }
98
99
100
101
102
103
104 public void handleRemove( String cacheName, Serializable key )
105 throws IOException
106 {
107 cache.remove( key );
108 }
109
110
111
112
113
114 public void handleRemoveAll( String cacheName )
115 throws IOException
116 {
117 cache.removeAll();
118 }
119
120
121
122
123
124 public void handleDispose( String cacheName )
125 throws IOException
126 {
127 cache.dispose();
128 }
129 }