1 package org.apache.commons.jcs.auxiliary.remote.util;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Set;
23
24 import org.apache.commons.jcs.auxiliary.remote.value.RemoteCacheRequest;
25 import org.apache.commons.jcs.auxiliary.remote.value.RemoteRequestType;
26 import org.apache.commons.jcs.engine.behavior.ICacheElement;
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29
30
31
32
33
34 public class RemoteCacheRequestFactory
35 {
36
37 private static final Log log = LogFactory.getLog( RemoteCacheRequestFactory.class );
38
39
40
41
42
43
44
45
46 private static <K, V> RemoteCacheRequest<K, V> createRequest(String cacheName, RemoteRequestType requestType, long requesterId)
47 {
48 RemoteCacheRequest<K, V> request = new RemoteCacheRequest<K, V>();
49 request.setCacheName( cacheName );
50 request.setRequestType( requestType );
51 request.setRequesterId( requesterId );
52
53 if ( log.isDebugEnabled() )
54 {
55 log.debug( "Created: " + request );
56 }
57
58 return request;
59 }
60
61
62
63
64
65
66
67
68
69 public static <K, V> RemoteCacheRequest<K, V> createGetRequest( String cacheName, K key, long requesterId )
70 {
71 RemoteCacheRequest<K, V> request = createRequest(cacheName, RemoteRequestType.GET, requesterId);
72 request.setKey( key );
73
74 return request;
75 }
76
77
78
79
80
81
82
83
84
85 public static <K, V> RemoteCacheRequest<K, V> createGetMatchingRequest( String cacheName, String pattern, long requesterId )
86 {
87 RemoteCacheRequest<K, V> request = createRequest(cacheName, RemoteRequestType.GET_MATCHING, requesterId);
88 request.setPattern( pattern );
89
90 return request;
91 }
92
93
94
95
96
97
98
99
100
101 public static <K, V> RemoteCacheRequest<K, V> createGetMultipleRequest( String cacheName, Set<K> keys, long requesterId )
102 {
103 RemoteCacheRequest<K, V> request = createRequest(cacheName, RemoteRequestType.GET_MULTIPLE, requesterId);
104 request.setKeySet(keys);
105
106 return request;
107 }
108
109
110
111
112
113
114
115
116
117 public static <K, V> RemoteCacheRequest<K, V> createRemoveRequest( String cacheName, K key, long requesterId )
118 {
119 RemoteCacheRequest<K, V> request = createRequest(cacheName, RemoteRequestType.REMOVE, requesterId);
120 request.setKey( key );
121
122 return request;
123 }
124
125
126
127
128
129
130
131
132 public static RemoteCacheRequest<String, String> createGetKeySetRequest( String cacheName, long requesterId )
133 {
134 RemoteCacheRequest<String, String> request = createRequest(cacheName, RemoteRequestType.GET_KEYSET, requesterId);
135 request.setKey( cacheName );
136
137 return request;
138 }
139
140
141
142
143
144
145
146
147 public static <K, V> RemoteCacheRequest<K, V> createRemoveAllRequest( String cacheName, long requesterId )
148 {
149 RemoteCacheRequest<K, V> request = createRequest(cacheName, RemoteRequestType.REMOVE_ALL, requesterId);
150
151 return request;
152 }
153
154
155
156
157
158
159
160
161 public static <K, V> RemoteCacheRequest<K, V> createDisposeRequest( String cacheName, long requesterId )
162 {
163 RemoteCacheRequest<K, V> request = createRequest(cacheName, RemoteRequestType.DISPOSE, requesterId);
164
165 return request;
166 }
167
168
169
170
171
172
173
174
175 public static <K, V> RemoteCacheRequest<K, V> createUpdateRequest( ICacheElement<K, V> cacheElement, long requesterId )
176 {
177 RemoteCacheRequest<K, V> request = createRequest(null, RemoteRequestType.UPDATE, requesterId);
178 if ( cacheElement != null )
179 {
180 request.setCacheName( cacheElement.getCacheName() );
181 request.setCacheElement( cacheElement );
182 request.setKey( cacheElement.getKey() );
183 }
184 else
185 {
186 log.error( "Can't create a proper update request for a null cache element." );
187 }
188
189 return request;
190 }
191
192
193
194
195
196
197
198 public static <K, V> RemoteCacheRequest<K, V> createAliveCheckRequest( long requesterId )
199 {
200 RemoteCacheRequest<K, V> request = createRequest(null, RemoteRequestType.ALIVE_CHECK, requesterId);
201
202 return request;
203 }
204 }