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