1 package org.apache.commons.jcs.auxiliary.remote;
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.rmi.RemoteException;
24 import java.rmi.server.UnicastRemoteObject;
25
26 import org.apache.commons.jcs.auxiliary.remote.behavior.IRemoteCacheAttributes;
27 import org.apache.commons.jcs.auxiliary.remote.behavior.IRemoteCacheConstants;
28 import org.apache.commons.jcs.engine.behavior.ICompositeCacheManager;
29 import org.apache.commons.jcs.engine.behavior.IElementSerializer;
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32
33
34
35
36
37
38
39
40 public class RemoteCacheListener<K, V>
41 extends AbstractRemoteCacheListener<K, V>
42 implements IRemoteCacheConstants
43 {
44
45 private static final Log log = LogFactory.getLog( RemoteCacheListener.class );
46
47
48 private boolean disposed = false;
49
50
51
52
53
54
55
56
57
58
59
60 public RemoteCacheListener( IRemoteCacheAttributes irca, ICompositeCacheManager cacheMgr, IElementSerializer elementSerializer )
61 {
62 super( irca, cacheMgr, elementSerializer );
63
64
65
66 try
67 {
68 UnicastRemoteObject.exportObject( this, irca.getLocalPort() );
69 }
70 catch ( RemoteException ex )
71 {
72 log.error( "Problem exporting object.", ex );
73 throw new IllegalStateException( ex.getMessage() );
74 }
75 }
76
77
78
79
80
81
82 @Override
83 public synchronized void dispose()
84 throws IOException
85 {
86 if ( !disposed )
87 {
88 if ( log.isInfoEnabled() )
89 {
90 log.info( "Unexporting listener." );
91 }
92 try
93 {
94 UnicastRemoteObject.unexportObject( this, true );
95 }
96 catch ( RemoteException ex )
97 {
98 log.error( "Problem unexporting the listener.", ex );
99 throw new IllegalStateException( ex.getMessage() );
100 }
101 disposed = true;
102 }
103 }
104
105
106
107
108
109
110 @Override
111 public String toString()
112 {
113 StringBuilder buf = new StringBuilder();
114 buf.append( "\n RemoteCacheListener: " );
115 buf.append( super.toString() );
116 return buf.toString();
117 }
118 }