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