1 package org.apache.jcs.auxiliary.remote;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import org.apache.jcs.auxiliary.AbstractAuxiliaryCacheAttributes;
23 import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
24 import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheAttributes;
25 import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheConstants;
26
27 /**
28 * These objects are used to configure the remote cache client.
29 */
30 public class RemoteCacheAttributes
31 extends AbstractAuxiliaryCacheAttributes
32 implements IRemoteCacheAttributes
33 {
34 /** Don't change */
35 private static final long serialVersionUID = -1555143736942374000L;
36
37 /** The service name */
38 private String remoteServiceName = IRemoteCacheConstants.REMOTE_CACHE_SERVICE_VAL;
39
40 /** server host */
41 private String remoteHost;
42
43 /** server port */
44 private int remotePort;
45
46 /**
47 * Failover servers will be used by local caches one at a time. Listeners will be registered
48 * with all cluster servers. If we add a get from cluster attribute we will have the ability to
49 * chain clusters and have them get from each other.
50 */
51 private String failoverServers = "";
52
53 /** Cluster chain */
54 private String clusterServers = "";
55
56 /** callback */
57 private int localPort = 0;
58
59 /** THe type of remote cache, local or cluster */
60 private int remoteType = LOCAL;
61
62 /** what failover server we are connected to. */
63 private int failoverIndex = 0;
64
65 /** Array of failover server addresses */
66 private String[] failovers;
67
68 /** Should we issue a local remove if we get a put from a remote server */
69 private boolean removeUponRemotePut = true;
70
71 /** Can we receive from or put to the remote. this probably shouldn't be used. Use receive. */
72 private boolean getOnly = false;
73
74 /** Should we put and get from the clusters. */
75 private boolean localClusterConsistency = false;
76
77 /** default name is remote_cache_client */
78 private String threadPoolName = "remote_cache_client";
79
80 /** must be greater than 0 for a pool to be used. */
81 private int getTimeoutMillis = -1;
82
83 /** read and connect timeout */
84 private int rmiSocketFactoryTimeoutMillis = DEFAULT_RMI_SOCKET_FACTORY_TIMEOUT_MILLIS;
85
86 /**
87 * Can we receive from the server. You might have a 0 local store and keep everything on the
88 * remote. If so, you don't want to be notified of updates.
89 */
90 private boolean receive = DEFAULT_RECEIVE;
91
92 /** If the primary fails, we will queue items before reconnect. This limits the number of items that can be queued. */
93 private int zombieQueueMaxSize = DEFAULT_ZOMBIE_QUEUE_MAX_SIZE;
94
95 /** Default constructor for the RemoteCacheAttributes object */
96 public RemoteCacheAttributes()
97 {
98 super();
99 }
100
101 /**
102 * Gets the remoteTypeName attribute of the RemoteCacheAttributes object.
103 * <p>
104 * @return The remoteTypeName value
105 */
106 public String getRemoteTypeName()
107 {
108 if ( remoteType == LOCAL )
109 {
110 return "LOCAL";
111 }
112 else if ( remoteType == CLUSTER )
113 {
114 return "CLUSTER";
115 }
116 return "LOCAL";
117 }
118
119 /**
120 * Sets the remoteTypeName attribute of the RemoteCacheAttributes object.
121 * <p>
122 * @param s The new remoteTypeName value
123 */
124 public void setRemoteTypeName( String s )
125 {
126 if ( s.equals( "LOCAL" ) )
127 {
128 remoteType = LOCAL;
129 }
130 else if ( s.equals( "CLUSTER" ) )
131 {
132 remoteType = CLUSTER;
133 }
134 }
135
136 /**
137 * Gets the failoverIndex attribute of the RemoteCacheAttributes object.
138 * <p>
139 * @return The failoverIndex value
140 */
141 public int getFailoverIndex()
142 {
143 return failoverIndex;
144 }
145
146 /**
147 * Sets the failoverIndex attribute of the RemoteCacheAttributes object.
148 * <p>
149 * @param p The new failoverIndex value
150 */
151 public void setFailoverIndex( int p )
152 {
153 this.failoverIndex = p;
154 }
155
156 /**
157 * Gets the failovers attribute of the RemoteCacheAttributes object.
158 * <p>
159 * @return The failovers value
160 */
161 public String[] getFailovers()
162 {
163 return this.failovers;
164 }
165
166 /**
167 * Sets the failovers attribute of the RemoteCacheAttributes object.
168 * <p>
169 * @param f The new failovers value
170 */
171 public void setFailovers( String[] f )
172 {
173 this.failovers = f;
174 }
175
176 /**
177 * Gets the remoteType attribute of the RemoteCacheAttributes object.
178 * <p>
179 * @return The remoteType value
180 */
181 public int getRemoteType()
182 {
183 return remoteType;
184 }
185
186 /**
187 * Sets the remoteType attribute of the RemoteCacheAttributes object.
188 * <p>
189 * @param p The new remoteType value
190 */
191 public void setRemoteType( int p )
192 {
193 this.remoteType = p;
194 }
195
196 /**
197 * @return AuxiliaryCacheAttributes
198 */
199 public AuxiliaryCacheAttributes copy()
200 {
201 try
202 {
203 return (AuxiliaryCacheAttributes) this.clone();
204 }
205 catch ( Exception e )
206 {
207 // swallow
208 }
209 return this;
210 }
211
212 /**
213 * Gets the remoteServiceName attribute of the RemoteCacheAttributes object.
214 * <p>
215 * @return The remoteServiceName value
216 */
217 public String getRemoteServiceName()
218 {
219 return this.remoteServiceName;
220 }
221
222 /**
223 * Sets the remoteServiceName attribute of the RemoteCacheAttributes object.
224 * <p>
225 * @param s The new remoteServiceName value
226 */
227 public void setRemoteServiceName( String s )
228 {
229 this.remoteServiceName = s;
230 }
231
232 /**
233 * Gets the remoteHost attribute of the RemoteCacheAttributes object.
234 * <p>
235 * @return The remoteHost value
236 */
237 public String getRemoteHost()
238 {
239 return this.remoteHost;
240 }
241
242 /**
243 * Sets the remoteHost attribute of the RemoteCacheAttributes object.
244 * <p>
245 * @param s The new remoteHost value
246 */
247 public void setRemoteHost( String s )
248 {
249 this.remoteHost = s;
250 }
251
252 /**
253 * Gets the remotePort attribute of the RemoteCacheAttributes object.
254 * <p>
255 * @return The remotePort value
256 */
257 public int getRemotePort()
258 {
259 return this.remotePort;
260 }
261
262 /**
263 * Sets the remotePort attribute of the RemoteCacheAttributes object.
264 * <p>
265 * @param p The new remotePort value
266 */
267 public void setRemotePort( int p )
268 {
269 this.remotePort = p;
270 }
271
272 /**
273 * Gets the clusterServers attribute of the RemoteCacheAttributes object.
274 * <p>
275 * @return The clusterServers value
276 */
277 public String getClusterServers()
278 {
279 return this.clusterServers;
280 }
281
282 /**
283 * Sets the clusterServers attribute of the RemoteCacheAttributes object.
284 * <p>
285 * @param s The new clusterServers value
286 */
287 public void setClusterServers( String s )
288 {
289 this.clusterServers = s;
290 }
291
292 /**
293 * Gets the failoverServers attribute of the RemoteCacheAttributes object.
294 * <p>
295 * @return The failoverServers value
296 */
297 public String getFailoverServers()
298 {
299 return this.failoverServers;
300 }
301
302 /**
303 * Sets the failoverServers attribute of the RemoteCacheAttributes object.
304 * <p>
305 * @param s The new failoverServers value
306 */
307 public void setFailoverServers( String s )
308 {
309 this.failoverServers = s;
310 }
311
312 /**
313 * Gets the localPort attribute of the RemoteCacheAttributes object.
314 * <p>
315 * @return The localPort value
316 */
317 public int getLocalPort()
318 {
319 return this.localPort;
320 }
321
322 /**
323 * Sets the localPort attribute of the RemoteCacheAttributes object
324 * @param p The new localPort value
325 */
326 public void setLocalPort( int p )
327 {
328 this.localPort = p;
329 }
330
331 /**
332 * Gets the removeUponRemotePut attribute of the RemoteCacheAttributes object.
333 * <p>
334 * @return The removeUponRemotePut value
335 */
336 public boolean getRemoveUponRemotePut()
337 {
338 return this.removeUponRemotePut;
339 }
340
341 /**
342 * Sets the removeUponRemotePut attribute of the RemoteCacheAttributes object.
343 * <p>
344 * @param r The new removeUponRemotePut value
345 */
346 public void setRemoveUponRemotePut( boolean r )
347 {
348 this.removeUponRemotePut = r;
349 }
350
351 /**
352 * Gets the getOnly attribute of the RemoteCacheAttributes object.
353 * <p>
354 * @return The getOnly value
355 */
356 public boolean getGetOnly()
357 {
358 return this.getOnly;
359 }
360
361 /**
362 * Sets the getOnly attribute of the RemoteCacheAttributes object
363 * @param r The new getOnly value
364 */
365 public void setGetOnly( boolean r )
366 {
367 this.getOnly = r;
368 }
369
370 /**
371 * Should cluster updates be propogated to the locals.
372 * <p>
373 * @return The localClusterConsistency value
374 */
375 public boolean getLocalClusterConsistency()
376 {
377 return localClusterConsistency;
378 }
379
380 /**
381 * Should cluster updates be propogated to the locals.
382 * <p>
383 * @param r The new localClusterConsistency value
384 */
385 public void setLocalClusterConsistency( boolean r )
386 {
387 this.localClusterConsistency = r;
388 }
389
390 /**
391 * @return the name of the pool
392 */
393 public String getThreadPoolName()
394 {
395 return threadPoolName;
396 }
397
398 /**
399 * @param name
400 */
401 public void setThreadPoolName( String name )
402 {
403 threadPoolName = name;
404 }
405
406 /**
407 * @return getTimeoutMillis
408 */
409 public int getGetTimeoutMillis()
410 {
411 return getTimeoutMillis;
412 }
413
414 /**
415 * @param millis
416 */
417 public void setGetTimeoutMillis( int millis )
418 {
419 getTimeoutMillis = millis;
420 }
421
422 /**
423 * @param rmiSocketFactoryTimeoutMillis The rmiSocketFactoryTimeoutMillis to set.
424 */
425 public void setRmiSocketFactoryTimeoutMillis( int rmiSocketFactoryTimeoutMillis )
426 {
427 this.rmiSocketFactoryTimeoutMillis = rmiSocketFactoryTimeoutMillis;
428 }
429
430 /**
431 * @return Returns the rmiSocketFactoryTimeoutMillis.
432 */
433 public int getRmiSocketFactoryTimeoutMillis()
434 {
435 return rmiSocketFactoryTimeoutMillis;
436 }
437
438 /**
439 * By default this option is true. If you set it to false, you will not receive updates or
440 * removes from the remote server.
441 * <p>
442 * @param receive
443 */
444 public void setReceive( boolean receive )
445 {
446 this.receive = receive;
447 }
448
449 /**
450 * If RECEIVE is false then the remote cache will not register a listener with the remote
451 * server. This allows you to configure a remote server as a repository from which you can get
452 * and to which you put, but from which you do not reveive any notifications. That is, you will
453 * not receive updates or removes.
454 * <p>
455 * If you set this option to false, you should set your locl memory size to 0.
456 * <p>
457 * The remote cache manager uses this value to decide whether or not to register a listener.
458 * @return the receive value.
459 */
460 public boolean isReceive()
461 {
462 return this.receive;
463 }
464
465 /**
466 * The number of elements the zombie queue will hold. This queue is used to store events if we
467 * loose our connection with the server.
468 * <p>
469 * @param zombieQueueMaxSize The zombieQueueMaxSize to set.
470 */
471 public void setZombieQueueMaxSize( int zombieQueueMaxSize )
472 {
473 this.zombieQueueMaxSize = zombieQueueMaxSize;
474 }
475
476 /**
477 * The number of elements the zombie queue will hold. This queue is used to store events if we
478 * loose our connection with the server.
479 * <p>
480 * @return Returns the zombieQueueMaxSize.
481 */
482 public int getZombieQueueMaxSize()
483 {
484 return zombieQueueMaxSize;
485 }
486
487 /**
488 * @return String, all the important values that can be configured
489 */
490 public String toString()
491 {
492 StringBuffer buf = new StringBuffer();
493 buf.append( "\n RemoteCacheAttributes " );
494 buf.append( "\n remoteHost = [" + this.remoteHost + "]" );
495 buf.append( "\n remotePort = [" + this.remotePort + "]" );
496 buf.append( "\n cacheName = [" + this.cacheName + "]" );
497 buf.append( "\n removeUponRemotePut = [" + this.removeUponRemotePut + "]" );
498 buf.append( "\n getOnly = [" + getOnly + "]" );
499 buf.append( "\n receive = [" + isReceive() + "]" );
500 buf.append( "\n getTimeoutMillis = [" + getGetTimeoutMillis() + "]" );
501 buf.append( "\n threadPoolName = [" + getThreadPoolName() + "]" );
502 buf.append( "\n remoteType = [" + remoteType + "]" );
503 buf.append( "\n localClusterConsistency = [" + getLocalClusterConsistency() + "]" );
504 buf.append( "\n zombieQueueMaxSize = [" + getZombieQueueMaxSize() + "]" );
505 return buf.toString();
506 }
507 }