View Javadoc

1   package org.apache.jcs.auxiliary.remote.server;
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.IRemoteCacheConstants;
25  import org.apache.jcs.auxiliary.remote.server.behavior.IRemoteCacheServerAttributes;
26  
27  /***
28   * These attributes are used to configure the remote cache server.
29   */
30  public class RemoteCacheServerAttributes
31      extends AbstractAuxiliaryCacheAttributes
32      implements IRemoteCacheServerAttributes
33  {
34      private static final long serialVersionUID = -2741662082869155365L;
35  
36      private String remoteServiceName = IRemoteCacheConstants.REMOTE_CACHE_SERVICE_VAL;
37  
38      private String remoteHost;
39  
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      private int servicePort = 0;
50  
51      private int remoteType = LOCAL;
52  
53      private boolean removeUponRemotePut = true;
54  
55      private boolean getOnly = false;
56  
57      private boolean localClusterConsistency = false;
58  
59      private boolean allowClusterGet = true;
60  
61      private String configFileName = "";
62  
63      /*** Default constructor for the RemoteCacheAttributes object */
64      public RemoteCacheServerAttributes()
65      {
66          super();
67      }
68  
69      /***
70       * Gets the remoteTypeName attribute of the RemoteCacheAttributes object
71       * <p>
72       * @return The remoteTypeName value
73       */
74      public String getRemoteTypeName()
75      {
76          if ( remoteType == LOCAL )
77          {
78              return "LOCAL";
79          }
80          else if ( remoteType == CLUSTER )
81          {
82              return "CLUSTER";
83          }
84          return "LOCAL";
85      }
86  
87      /***
88       * Sets the remoteTypeName attribute of the RemoteCacheAttributes object
89       * <p>
90       * @param s The new remoteTypeName value
91       */
92      public void setRemoteTypeName( String s )
93      {
94          if ( s.equals( "LOCAL" ) )
95          {
96              remoteType = LOCAL;
97          }
98          else if ( s.equals( "CLUSTER" ) )
99          {
100             remoteType = CLUSTER;
101         }
102     }
103 
104     /***
105      * Gets the remoteType attribute of the RemoteCacheAttributes object
106      * <p>
107      * @return The remoteType value
108      */
109     public int getRemoteType()
110     {
111         return remoteType;
112     }
113 
114     /***
115      * Sets the remoteType attribute of the RemoteCacheAttributes object
116      * <p>
117      * @param p The new remoteType value
118      */
119     public void setRemoteType( int p )
120     {
121         this.remoteType = p;
122     }
123 
124     /***
125      * clones
126      * <p>
127      * @return AuxiliaryCacheAttributes clone
128      */
129     public AuxiliaryCacheAttributes copy()
130     {
131         try
132         {
133             return (AuxiliaryCacheAttributes) this.clone();
134         }
135         catch ( Exception e )
136         {
137             // swallow
138         }
139         return this;
140     }
141 
142     /***
143      * Gets the remoteServiceName attribute of the RemoteCacheAttributes object
144      * <p>
145      * @return The remoteServiceName value
146      */
147     public String getRemoteServiceName()
148     {
149         return this.remoteServiceName;
150     }
151 
152     /***
153      * Sets the remoteServiceName attribute of the RemoteCacheAttributes object
154      * <p>
155      * @param s The new remoteServiceName value
156      */
157     public void setRemoteServiceName( String s )
158     {
159         this.remoteServiceName = s;
160     }
161 
162     /***
163      * Gets the remoteHost attribute of the RemoteCacheAttributes object
164      * <p>
165      * @return The remoteHost value
166      */
167     public String getRemoteHost()
168     {
169         return this.remoteHost;
170     }
171 
172     /***
173      * Sets the remoteHost attribute of the RemoteCacheAttributes object
174      * <p>
175      * @param s The new remoteHost value
176      */
177     public void setRemoteHost( String s )
178     {
179         this.remoteHost = s;
180     }
181 
182     /***
183      * Gets the remotePort attribute of the RemoteCacheAttributes object
184      * <p>
185      * @return The remotePort value
186      */
187     public int getRemotePort()
188     {
189         return this.remotePort;
190     }
191 
192     /***
193      * Sets the remotePort attribute of the RemoteCacheAttributes object
194      * <p>
195      * @param p The new remotePort value
196      */
197     public void setRemotePort( int p )
198     {
199         this.remotePort = p;
200     }
201 
202     /***
203      * Gets the clusterServers attribute of the RemoteCacheAttributes object
204      * <p>
205      * @return The clusterServers value
206      */
207     public String getClusterServers()
208     {
209         return this.clusterServers;
210     }
211 
212     /***
213      * Sets the clusterServers attribute of the RemoteCacheAttributes object
214      * <p>
215      * @param s The new clusterServers value
216      */
217     public void setClusterServers( String s )
218     {
219         this.clusterServers = s;
220     }
221 
222     /***
223      * Gets the localPort attribute of the RemoteCacheAttributes object
224      * <p>
225      * @return The localPort value
226      */
227     public int getServicePort()
228     {
229         return this.servicePort;
230     }
231 
232     /***
233      * Sets the localPort attribute of the RemoteCacheAttributes object
234      * <p>
235      * @param p The new localPort value
236      */
237     public void setServicePort( int p )
238     {
239         this.servicePort = p;
240     }
241 
242     /***
243      * Gets the removeUponRemotePut attribute of the RemoteCacheAttributes object
244      * <p>
245      * @return The removeUponRemotePut value
246      */
247     public boolean getRemoveUponRemotePut()
248     {
249         return this.removeUponRemotePut;
250     }
251 
252     /***
253      * Sets the removeUponRemotePut attribute of the RemoteCacheAttributes object
254      * <p>
255      * @param r The new removeUponRemotePut value
256      */
257     public void setRemoveUponRemotePut( boolean r )
258     {
259         this.removeUponRemotePut = r;
260     }
261 
262     /***
263      * Gets the getOnly attribute of the RemoteCacheAttributes object
264      * <p>
265      * @return The getOnly value
266      */
267     public boolean getGetOnly()
268     {
269         return this.getOnly;
270     }
271 
272     /***
273      * Sets the getOnly attribute of the RemoteCacheAttributes object
274      * <p>
275      * @param r The new getOnly value
276      */
277     public void setGetOnly( boolean r )
278     {
279         this.getOnly = r;
280     }
281 
282     /***
283      * Should cluster updates be propogated to the locals
284      * <p>
285      * @return The localClusterConsistency value
286      */
287     public boolean getLocalClusterConsistency()
288     {
289         return localClusterConsistency;
290     }
291 
292     /***
293      * Should cluster updates be propogated to the locals
294      * <p>
295      * @param r The new localClusterConsistency value
296      */
297     public void setLocalClusterConsistency( boolean r )
298     {
299         this.localClusterConsistency = r;
300     }
301 
302     /***
303      * Should gets from non-cluster clients be allowed to get from other remote auxiliaries.
304      * <p>
305      * @return The localClusterConsistency value
306      */
307     public boolean getAllowClusterGet()
308     {
309         return allowClusterGet;
310     }
311 
312     /***
313      * Should we try to get from other cluster servers if we don't find the items locally.
314      * <p>
315      * @param r The new localClusterConsistency value
316      */
317     public void setAllowClusterGet( boolean r )
318     {
319         allowClusterGet = r;
320     }
321 
322     /***
323      * Gets the ConfigFileName attribute of the IRemoteCacheAttributes object
324      * <p>
325      * @return The clusterServers value
326      */
327     public String getConfigFileName()
328     {
329         return configFileName;
330     }
331 
332     /***
333      * Sets the ConfigFileName attribute of the IRemoteCacheAttributes object
334      * <p>
335      * @param s The new clusterServers value
336      */
337     public void setConfigFileName( String s )
338     {
339         configFileName = s;
340     }
341 
342     /*
343      * (non-Javadoc)
344      * @see java.lang.Object#toString()
345      */
346     public String toString()
347     {
348         StringBuffer buf = new StringBuffer();
349         buf.append( "\n remoteHost = " + this.getRemoteHost() );
350         buf.append( "\n remotePort = " + this.getRemotePort() );
351         buf.append( "\n cacheName = " + this.getCacheName() );
352         buf.append( "\n removeUponRemotePut = " + this.getRemoveUponRemotePut() );
353         buf.append( "\n getOnly = " + this.getGetOnly() );
354         buf.append( "\n allowClusterGet = " + this.getAllowClusterGet() );
355         buf.append( "\n localClusterConsistency = " + this.getLocalClusterConsistency() );
356         buf.append( "\n getConfigFileName = " + this.getConfigFileName() );
357         return buf.toString();
358     }
359 }