View Javadoc

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.ICommonRemoteCacheAttributes;
25  import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheConstants;
26  import org.apache.jcs.auxiliary.remote.server.behavior.RemoteType;
27  
28  /**
29   * Attributes common to remote cache client and server.
30   */
31  public class CommonRemoteCacheAttributes
32      extends AbstractAuxiliaryCacheAttributes
33      implements ICommonRemoteCacheAttributes
34  {
35      /** Don't change */
36      private static final long serialVersionUID = -1555143736942374000L;
37  
38      /** The service name */
39      private String remoteServiceName = IRemoteCacheConstants.REMOTE_CACHE_SERVICE_VAL;
40  
41      /** server host */
42      private String remoteHost;
43  
44      /** server port */
45      private int remotePort;
46  
47      /** Cluster chain */
48      private String clusterServers = "";
49  
50      /** THe type of remote cache, local or cluster */
51      private RemoteType remoteType = RemoteType.LOCAL;
52  
53      /** Should we issue a local remove if we get a put from a remote server */
54      private boolean removeUponRemotePut = true;
55  
56      /** Can we receive from or put to the remote. this probably shouldn't be used. Use receive. */
57      private boolean getOnly = false;
58  
59      /** Should we put and get from the clusters. */
60      private boolean localClusterConsistency = false;
61  
62      /** read and connect timeout */
63      private int rmiSocketFactoryTimeoutMillis = DEFAULT_RMI_SOCKET_FACTORY_TIMEOUT_MILLIS;
64  
65      /** Default constructor for the RemoteCacheAttributes object */
66      public CommonRemoteCacheAttributes()
67      {
68          super();
69      }
70  
71      /**
72       * Gets the remoteTypeName attribute of the RemoteCacheAttributes object.
73       * <p>
74       * @return The remoteTypeName value
75       */
76      public String getRemoteTypeName()
77      {
78          return remoteType != null ? remoteType.toString() : RemoteType.LOCAL.toString();
79      }
80  
81      /**
82       * Sets the remoteTypeName attribute of the RemoteCacheAttributes object.
83       * <p>
84       * @param s The new remoteTypeName value
85       */
86      public void setRemoteTypeName( String s )
87      {
88          RemoteType rt = RemoteType.valueOf(s);
89          if (rt != null)
90          {
91              this.remoteType = rt;
92          }
93      }
94  
95      /**
96       * Gets the remoteType attribute of the RemoteCacheAttributes object.
97       * <p>
98       * @return The remoteType value
99       */
100     public RemoteType getRemoteType()
101     {
102         return remoteType;
103     }
104 
105     /**
106      * Sets the remoteType attribute of the RemoteCacheAttributes object.
107      * <p>
108      * @param p The new remoteType value
109      */
110     public void setRemoteType( RemoteType p )
111     {
112         this.remoteType = p;
113     }
114 
115     /**
116      * @return AuxiliaryCacheAttributes
117      */
118     public AuxiliaryCacheAttributes copy()
119     {
120         try
121         {
122             return (AuxiliaryCacheAttributes) this.clone();
123         }
124         catch ( Exception e )
125         {
126             // swallow
127         }
128         return this;
129     }
130 
131     /**
132      * Gets the remoteServiceName attribute of the RemoteCacheAttributes object.
133      * <p>
134      * @return The remoteServiceName value
135      */
136     public String getRemoteServiceName()
137     {
138         return this.remoteServiceName;
139     }
140 
141     /**
142      * Sets the remoteServiceName attribute of the RemoteCacheAttributes object.
143      * <p>
144      * @param s The new remoteServiceName value
145      */
146     public void setRemoteServiceName( String s )
147     {
148         this.remoteServiceName = s;
149     }
150 
151     /**
152      * Gets the remoteHost attribute of the RemoteCacheAttributes object.
153      * <p>
154      * @return The remoteHost value
155      */
156     public String getRemoteHost()
157     {
158         return this.remoteHost;
159     }
160 
161     /**
162      * Sets the remoteHost attribute of the RemoteCacheAttributes object.
163      * <p>
164      * @param s The new remoteHost value
165      */
166     public void setRemoteHost( String s )
167     {
168         this.remoteHost = s;
169     }
170 
171     /**
172      * Gets the remotePort attribute of the RemoteCacheAttributes object.
173      * <p>
174      * @return The remotePort value
175      */
176     public int getRemotePort()
177     {
178         return this.remotePort;
179     }
180 
181     /**
182      * Sets the remotePort attribute of the RemoteCacheAttributes object.
183      * <p>
184      * @param p The new remotePort value
185      */
186     public void setRemotePort( int p )
187     {
188         this.remotePort = p;
189     }
190 
191     /**
192      * Gets the clusterServers attribute of the RemoteCacheAttributes object.
193      * <p>
194      * @return The clusterServers value
195      */
196     public String getClusterServers()
197     {
198         return this.clusterServers;
199     }
200 
201     /**
202      * Sets the clusterServers attribute of the RemoteCacheAttributes object.
203      * <p>
204      * @param s The new clusterServers value
205      */
206     public void setClusterServers( String s )
207     {
208         this.clusterServers = s;
209     }
210 
211     /**
212      * Gets the removeUponRemotePut attribute of the RemoteCacheAttributes object.
213      * <p>
214      * @return The removeUponRemotePut value
215      */
216     public boolean getRemoveUponRemotePut()
217     {
218         return this.removeUponRemotePut;
219     }
220 
221     /**
222      * Sets the removeUponRemotePut attribute of the RemoteCacheAttributes object.
223      * <p>
224      * @param r The new removeUponRemotePut value
225      */
226     public void setRemoveUponRemotePut( boolean r )
227     {
228         this.removeUponRemotePut = r;
229     }
230 
231     /**
232      * Gets the getOnly attribute of the RemoteCacheAttributes object.
233      * <p>
234      * @return The getOnly value
235      */
236     public boolean getGetOnly()
237     {
238         return this.getOnly;
239     }
240 
241     /**
242      * Sets the getOnly attribute of the RemoteCacheAttributes object
243      * @param r The new getOnly value
244      */
245     public void setGetOnly( boolean r )
246     {
247         this.getOnly = r;
248     }
249 
250     /**
251      * Should cluster updates be propagated to the locals.
252      * <p>
253      * @return The localClusterConsistency value
254      */
255     public boolean isLocalClusterConsistency()
256     {
257         return localClusterConsistency;
258     }
259 
260     /**
261      * Should cluster updates be propagated to the locals.
262      * <p>
263      * @param r The new localClusterConsistency value
264      */
265     public void setLocalClusterConsistency( boolean r )
266     {
267         this.localClusterConsistency = r;
268     }
269 
270     /**
271      * @param rmiSocketFactoryTimeoutMillis The rmiSocketFactoryTimeoutMillis to set.
272      */
273     public void setRmiSocketFactoryTimeoutMillis( int rmiSocketFactoryTimeoutMillis )
274     {
275         this.rmiSocketFactoryTimeoutMillis = rmiSocketFactoryTimeoutMillis;
276     }
277 
278     /**
279      * @return Returns the rmiSocketFactoryTimeoutMillis.
280      */
281     public int getRmiSocketFactoryTimeoutMillis()
282     {
283         return rmiSocketFactoryTimeoutMillis;
284     }
285 
286     /**
287      * @return String, all the important values that can be configured
288      */
289     @Override
290     public String toString()
291     {
292         StringBuffer buf = new StringBuffer();
293         buf.append( "\n RemoteCacheAttributes " );
294         buf.append( "\n remoteHost = [" + this.remoteHost + "]" );
295         buf.append( "\n remotePort = [" + this.remotePort + "]" );
296         buf.append( "\n cacheName = [" + this.cacheName + "]" );
297         buf.append( "\n remoteType = [" + remoteType + "]" );
298         buf.append( "\n removeUponRemotePut = [" + this.removeUponRemotePut + "]" );
299         buf.append( "\n getOnly = [" + getOnly + "]" );
300         return buf.toString();
301     }
302 }