1 package org.apache.jcs.auxiliary.remote.server;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
5 * agreements. See the NOTICE file distributed with this work for additional information regarding
6 * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance with the License. You may obtain a
8 * copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
15 * the License.
16 */
17
18 import org.apache.jcs.auxiliary.AbstractAuxiliaryCacheAttributes;
19 import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
20 import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheConstants;
21 import org.apache.jcs.auxiliary.remote.server.behavior.IRemoteCacheServerAttributes;
22
23 /**
24 * These attributes are used to configure the remote cache server.
25 */
26 public class RemoteCacheServerAttributes
27 extends AbstractAuxiliaryCacheAttributes
28 implements IRemoteCacheServerAttributes
29 {
30 /** Don't change */
31 private static final long serialVersionUID = -2741662082869155365L;
32
33 /** Name of the remote service. */
34 private String remoteServiceName = IRemoteCacheConstants.REMOTE_CACHE_SERVICE_VAL;
35
36 /** The remote host. */
37 private String remoteHost;
38
39 /** The registry remote port. */
40 private int remotePort;
41
42 /**
43 * Failover servers will be used by local caches one at a time. Listeners will be registered
44 * with all cluster servers. If we add a get from cluster attribute we will have the ability to
45 * chain clusters and have them get from each other.
46 */
47 private String clusterServers = "";
48
49 /** port the server will listen to */
50 private int servicePort = 0;
51
52 /** Cluster or local */
53 private int remoteType = LOCAL;
54
55 /** Remove item when put */
56 private boolean removeUponRemotePut = true;
57
58 /** Ony get, don't put */
59 private boolean getOnly = false;
60
61 /** Can a cluster remote put to other remotes */
62 private boolean localClusterConsistency = true;
63
64 /** Can a cluster remote get from other remotes */
65 private boolean allowClusterGet = true;
66
67 /** The config file, the initializationis multistage. Remote cache then composite cache. */
68 private String configFileName = "";
69
70 /** Factory socket time out. */
71 public static final int DEFAULT_RMI_SOCKET_FACTORY_TIMEOUT_MS = 10000;
72
73 /** Connect and read timeout. */
74 private int rmiSocketFactoryTimeoutMillis = DEFAULT_RMI_SOCKET_FACTORY_TIMEOUT_MS;
75
76 /** Should we start the registry */
77 private boolean DEFAULT_START_REGISTRY = true;
78
79 /** Should we start the registry */
80 private boolean startRegistry = DEFAULT_START_REGISTRY;
81
82 /** Should we try to keep the registry alive */
83 private boolean DEFAULT_USE_REGISTRY_KEEP_ALIVE = true;
84
85 /** Should we try to keep the registry alive */
86 private boolean useRegistryKeepAlive = DEFAULT_USE_REGISTRY_KEEP_ALIVE;
87
88 /** The delay between runs */
89 private long registryKeepAliveDelayMillis = 15 * 1000;
90
91 /** Default constructor for the RemoteCacheAttributes object */
92 public RemoteCacheServerAttributes()
93 {
94 super();
95 }
96
97 /**
98 * Gets the remoteTypeName attribute of the RemoteCacheAttributes object
99 * <p>
100 * @return The remoteTypeName value
101 */
102 public String getRemoteTypeName()
103 {
104 if ( remoteType == LOCAL )
105 {
106 return "LOCAL";
107 }
108 else if ( remoteType == CLUSTER )
109 {
110 return "CLUSTER";
111 }
112 return "LOCAL";
113 }
114
115 /**
116 * Sets the remoteTypeName attribute of the RemoteCacheAttributes object
117 * <p>
118 * @param s The new remoteTypeName value
119 */
120 public void setRemoteTypeName( String s )
121 {
122 if ( s.equals( "LOCAL" ) )
123 {
124 remoteType = LOCAL;
125 }
126 else if ( s.equals( "CLUSTER" ) )
127 {
128 remoteType = CLUSTER;
129 }
130 }
131
132 /**
133 * Gets the remoteType attribute of the RemoteCacheAttributes object
134 * <p>
135 * @return The remoteType value
136 */
137 public int getRemoteType()
138 {
139 return remoteType;
140 }
141
142 /**
143 * Sets the remoteType attribute of the RemoteCacheAttributes object
144 * <p>
145 * @param p The new remoteType value
146 */
147 public void setRemoteType( int p )
148 {
149 this.remoteType = p;
150 }
151
152 /**
153 * clones
154 * <p>
155 * @return AuxiliaryCacheAttributes clone
156 */
157 public AuxiliaryCacheAttributes copy()
158 {
159 try
160 {
161 return (AuxiliaryCacheAttributes) this.clone();
162 }
163 catch ( Exception e )
164 {
165 // swallow
166 }
167 return this;
168 }
169
170 /**
171 * Gets the remoteServiceName attribute of the RemoteCacheAttributes object
172 * <p>
173 * @return The remoteServiceName value
174 */
175 public String getRemoteServiceName()
176 {
177 return this.remoteServiceName;
178 }
179
180 /**
181 * Sets the remoteServiceName attribute of the RemoteCacheAttributes object
182 * <p>
183 * @param s The new remoteServiceName value
184 */
185 public void setRemoteServiceName( String s )
186 {
187 this.remoteServiceName = s;
188 }
189
190 /**
191 * Gets the remoteHost attribute of the RemoteCacheAttributes object
192 * <p>
193 * @return The remoteHost value
194 */
195 public String getRemoteHost()
196 {
197 return this.remoteHost;
198 }
199
200 /**
201 * Sets the remoteHost attribute of the RemoteCacheAttributes object
202 * <p>
203 * @param s The new remoteHost value
204 */
205 public void setRemoteHost( String s )
206 {
207 this.remoteHost = s;
208 }
209
210 /**
211 * Gets the remotePort attribute of the RemoteCacheAttributes object
212 * <p>
213 * @return The remotePort value
214 */
215 public int getRemotePort()
216 {
217 return this.remotePort;
218 }
219
220 /**
221 * Sets the remotePort attribute of the RemoteCacheAttributes object
222 * <p>
223 * @param p The new remotePort value
224 */
225 public void setRemotePort( int p )
226 {
227 this.remotePort = p;
228 }
229
230 /**
231 * Gets the clusterServers attribute of the RemoteCacheAttributes object
232 * <p>
233 * @return The clusterServers value
234 */
235 public String getClusterServers()
236 {
237 return this.clusterServers;
238 }
239
240 /**
241 * Sets the clusterServers attribute of the RemoteCacheAttributes object
242 * <p>
243 * @param s The new clusterServers value
244 */
245 public void setClusterServers( String s )
246 {
247 this.clusterServers = s;
248 }
249
250 /**
251 * Gets the localPort attribute of the RemoteCacheAttributes object
252 * <p>
253 * @return The localPort value
254 */
255 public int getServicePort()
256 {
257 return this.servicePort;
258 }
259
260 /**
261 * Sets the localPort attribute of the RemoteCacheAttributes object
262 * <p>
263 * @param p The new localPort value
264 */
265 public void setServicePort( int p )
266 {
267 this.servicePort = p;
268 }
269
270 /**
271 * Gets the removeUponRemotePut attribute of the RemoteCacheAttributes object
272 * <p>
273 * @return The removeUponRemotePut value
274 */
275 public boolean getRemoveUponRemotePut()
276 {
277 return this.removeUponRemotePut;
278 }
279
280 /**
281 * Sets the removeUponRemotePut attribute of the RemoteCacheAttributes object
282 * <p>
283 * @param r The new removeUponRemotePut value
284 */
285 public void setRemoveUponRemotePut( boolean r )
286 {
287 this.removeUponRemotePut = r;
288 }
289
290 /**
291 * Gets the getOnly attribute of the RemoteCacheAttributes object
292 * <p>
293 * @return The getOnly value
294 */
295 public boolean getGetOnly()
296 {
297 return this.getOnly;
298 }
299
300 /**
301 * Sets the getOnly attribute of the RemoteCacheAttributes object
302 * <p>
303 * @param r The new getOnly value
304 */
305 public void setGetOnly( boolean r )
306 {
307 this.getOnly = r;
308 }
309
310 /**
311 * Should cluster updates be propagated to the locals
312 * <p>
313 * @return The localClusterConsistency value
314 */
315 public boolean getLocalClusterConsistency()
316 {
317 return isLocalClusterConsistency();
318 }
319
320 /**
321 * Should cluster updates be propagated to the locals
322 * <p>
323 * @return The localClusterConsistency value
324 */
325 public boolean isLocalClusterConsistency()
326 {
327 return localClusterConsistency;
328 }
329
330 /**
331 * Should cluster updates be propagated to the locals
332 * <p>
333 * @param r The new localClusterConsistency value
334 */
335 public void setLocalClusterConsistency( boolean r )
336 {
337 this.localClusterConsistency = r;
338 }
339
340 /**
341 * Should gets from non-cluster clients be allowed to get from other remote auxiliaries.
342 * <p>
343 * @return The localClusterConsistency value
344 */
345 public boolean getAllowClusterGet()
346 {
347 return isAllowClusterGet();
348 }
349
350 /**
351 * Should gets from non-cluster clients be allowed to get from other remote auxiliaries.
352 * <p>
353 * @return The localClusterConsistency value
354 */
355 public boolean isAllowClusterGet()
356 {
357 return allowClusterGet;
358 }
359
360 /**
361 * Should we try to get from other cluster servers if we don't find the items locally.
362 * <p>
363 * @param r The new localClusterConsistency value
364 */
365 public void setAllowClusterGet( boolean r )
366 {
367 allowClusterGet = r;
368 }
369
370 /**
371 * Gets the ConfigFileName attribute of the IRemoteCacheAttributes object
372 * <p>
373 * @return The clusterServers value
374 */
375 public String getConfigFileName()
376 {
377 return configFileName;
378 }
379
380 /**
381 * Sets the ConfigFileName attribute of the IRemoteCacheAttributes object
382 * <p>
383 * @param s The new clusterServers value
384 */
385 public void setConfigFileName( String s )
386 {
387 configFileName = s;
388 }
389
390 /**
391 * @param rmiSocketFactoryTimeoutMillis The rmiSocketFactoryTimeoutMillis to set.
392 */
393 public void setRmiSocketFactoryTimeoutMillis( int rmiSocketFactoryTimeoutMillis )
394 {
395 this.rmiSocketFactoryTimeoutMillis = rmiSocketFactoryTimeoutMillis;
396 }
397
398 /**
399 * @return Returns the rmiSocketFactoryTimeoutMillis.
400 */
401 public int getRmiSocketFactoryTimeoutMillis()
402 {
403 return rmiSocketFactoryTimeoutMillis;
404 }
405
406 /**
407 * Should we try to keep the registry alive
408 * <p>
409 * @param useRegistryKeepAlive the useRegistryKeepAlive to set
410 */
411 public void setUseRegistryKeepAlive( boolean useRegistryKeepAlive )
412 {
413 this.useRegistryKeepAlive = useRegistryKeepAlive;
414 }
415
416 /**
417 * Should we start the registry
418 * <p>
419 * @param startRegistry the startRegistry to set
420 */
421 public void setStartRegistry( boolean startRegistry )
422 {
423 this.startRegistry = startRegistry;
424 }
425
426 /**
427 * Should we start the registry
428 * <p>
429 * @return the startRegistry
430 */
431 public boolean isStartRegistry()
432 {
433 return startRegistry;
434 }
435
436 /**
437 * Should we try to keep the registry alive
438 * <p>
439 * @return the useRegistryKeepAlive
440 */
441 public boolean isUseRegistryKeepAlive()
442 {
443 return useRegistryKeepAlive;
444 }
445
446 /**
447 * @param registryKeepAliveDelayMillis the registryKeepAliveDelayMillis to set
448 */
449 public void setRegistryKeepAliveDelayMillis( long registryKeepAliveDelayMillis )
450 {
451 this.registryKeepAliveDelayMillis = registryKeepAliveDelayMillis;
452 }
453
454 /**
455 * @return the registryKeepAliveDelayMillis
456 */
457 public long getRegistryKeepAliveDelayMillis()
458 {
459 return registryKeepAliveDelayMillis;
460 }
461
462 /**
463 * @return String details
464 */
465 public String toString()
466 {
467 StringBuffer buf = new StringBuffer();
468 buf.append( "\n remoteHost = [" + this.getRemoteHost() + "]" );
469 buf.append( "\n remotePort = [" + this.getRemotePort() + "]" );
470 buf.append( "\n servicePort = [" + this.getServicePort() + "]" );
471 buf.append( "\n cacheName = [" + this.getCacheName() + "]" );
472 buf.append( "\n removeUponRemotePut = [" + this.getRemoveUponRemotePut() + "]" );
473 buf.append( "\n getOnly = [" + this.getGetOnly() + "]" );
474 buf.append( "\n allowClusterGet = [" + this.getAllowClusterGet() + "]" );
475 buf.append( "\n localClusterConsistency = [" + this.getLocalClusterConsistency() + "]" );
476 buf.append( "\n configFileName = [" + this.getConfigFileName() + "]" );
477 buf.append( "\n rmiSocketFactoryTimeoutMillis = [" + this.getRmiSocketFactoryTimeoutMillis() + "]" );
478 buf.append( "\n startRegistry = [" + this.isStartRegistry() + "]" );
479 buf.append( "\n useRegistryKeepAlive = [" + this.isUseRegistryKeepAlive() + "]" );
480 buf.append( "\n registryKeepAliveDelayMillis = [" + this.getRegistryKeepAliveDelayMillis() + "]" );
481 buf.append( "\n eventQueueType = [" + this.getEventQueueType() + "]" );
482 buf.append( "\n eventQueuePoolName = [" + this.getEventQueuePoolName() + "]" );
483 return buf.toString();
484 }
485 }