1 package org.apache.jcs.auxiliary.lateral;
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 java.io.Serializable;
23
24 import org.apache.jcs.auxiliary.AbstractAuxiliaryCacheAttributes;
25 import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
26 import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheAttributes;
27
28 /**
29 * This class stores attributes for all of the available lateral cache auxiliaries.
30 */
31 public class LateralCacheAttributes
32 extends AbstractAuxiliaryCacheAttributes
33 implements Serializable, ILateralCacheAttributes
34 {
35 /** Don't change */
36 private static final long serialVersionUID = -3408449508837393660L;
37
38 /** Default receive setting */
39 private static final boolean DEFAULT_RECEIVE = true;
40
41 /** THe type of lateral */
42 private String transmissionTypeName = "UDP";
43
44 /** indicates the lateral type, this needs to change */
45 private int transmissionType = UDP;
46
47 /** The heep servers */
48 private String httpServers;
49
50 /** used to identify the service that this manager will be operating on */
51 private String httpServer = "";
52
53 /** this needs to change */
54 private String udpMulticastAddr = "228.5.6.7";
55
56 /** this needs to change */
57 private int udpMulticastPort = 6789;
58
59 /** this needs to change */
60 private int httpListenerPort = 8080;
61
62 /** disables gets from laterals */
63 boolean putOnlyMode = true;
64
65 /**
66 * do we receive and broadcast or only broadcast this is useful when you don't want to get any
67 * notifications
68 */
69 private boolean receive = DEFAULT_RECEIVE;
70
71 /** If the primary fails, we will queue items before reconnect. This limits the number of items that can be queued. */
72 private int zombieQueueMaxSize = DEFAULT_ZOMBIE_QUEUE_MAX_SIZE;
73
74 /**
75 * Sets the httpServer attribute of the LateralCacheAttributes object
76 * <P>
77 * @param val The new httpServer value
78 */
79 public void setHttpServer( String val )
80 {
81 httpServer = val;
82 }
83
84 /**
85 * Gets the httpServer attribute of the LateralCacheAttributes object
86 * @return The httpServer value
87 */
88 public String getHttpServer()
89 {
90 return httpServer;
91 }
92
93 /**
94 * Sets the httpServers attribute of the LateralCacheAttributes object
95 * @param val The new httpServers value
96 */
97 public void setHttpServers( String val )
98 {
99 httpServers = val;
100 }
101
102 /**
103 * Gets the httpSrvers attribute of the LateralCacheAttributes object
104 * @return The httpServers value
105 */
106 public String getHttpServers()
107 {
108 return httpServers;
109 }
110
111 /**
112 * Sets the httpListenerPort attribute of the ILateralCacheAttributes object
113 * @param val The new tcpListenerPort value
114 */
115 public void setHttpListenerPort( int val )
116 {
117 this.httpListenerPort = val;
118 }
119
120 /**
121 * Gets the httpListenerPort attribute of the ILateralCacheAttributes object
122 * @return The httpListenerPort value
123 */
124 public int getHttpListenerPort()
125 {
126 return this.httpListenerPort;
127 }
128
129 /**
130 * Sets the udpMulticastAddr attribute of the LateralCacheAttributes object
131 * @param val The new udpMulticastAddr value
132 */
133 public void setUdpMulticastAddr( String val )
134 {
135 udpMulticastAddr = val;
136 }
137
138 /**
139 * Gets the udpMulticastAddr attribute of the LateralCacheAttributes object
140 * @return The udpMulticastAddr value
141 */
142 public String getUdpMulticastAddr()
143 {
144 return udpMulticastAddr;
145 }
146
147 /**
148 * Sets the udpMulticastPort attribute of the LateralCacheAttributes object
149 * @param val The new udpMulticastPort value
150 */
151 public void setUdpMulticastPort( int val )
152 {
153 udpMulticastPort = val;
154 }
155
156 /**
157 * Gets the udpMulticastPort attribute of the LateralCacheAttributes object
158 * @return The udpMulticastPort value
159 */
160 public int getUdpMulticastPort()
161 {
162 return udpMulticastPort;
163 }
164
165 /**
166 * Sets the transmissionType attribute of the LateralCacheAttributes object
167 * @param val The new transmissionType value
168 */
169 public void setTransmissionType( int val )
170 {
171 this.transmissionType = val;
172 if ( val == UDP )
173 {
174 transmissionTypeName = "UDP";
175 }
176 else if ( val == HTTP )
177 {
178 transmissionTypeName = "HTTP";
179 }
180 else if ( val == TCP )
181 {
182 transmissionTypeName = "TCP";
183 }
184 else if ( val == XMLRPC )
185 {
186 transmissionTypeName = "XMLRPC";
187 }
188 }
189
190 /**
191 * Gets the transmissionType attribute of the LateralCacheAttributes object
192 * @return The transmissionType value
193 */
194 public int getTransmissionType()
195 {
196 return this.transmissionType;
197 }
198
199 /**
200 * Sets the transmissionTypeName attribute of the LateralCacheAttributes object
201 * @param val The new transmissionTypeName value
202 */
203 public void setTransmissionTypeName( String val )
204 {
205 this.transmissionTypeName = val;
206 if ( val.equals( "UDP" ) )
207 {
208 transmissionType = UDP;
209 }
210 else if ( val.equals( "HTTP" ) )
211 {
212 transmissionType = HTTP;
213 }
214 else if ( val.equals( "TCP" ) )
215 {
216 transmissionType = TCP;
217 }
218 else if ( val.equals( "XMLRPC" ) )
219 {
220 transmissionType = XMLRPC;
221 }
222 }
223
224 /**
225 * Gets the transmissionTypeName attribute of the LateralCacheAttributes object
226 * @return The transmissionTypeName value
227 */
228 public String getTransmissionTypeName()
229 {
230 return this.transmissionTypeName;
231 }
232
233 /**
234 * Sets the outgoingOnlyMode attribute of the ILateralCacheAttributes. When this is true the
235 * lateral cache will only issue put and remove order and will not try to retrieve elements from
236 * other lateral caches.
237 * @param val The new transmissionTypeName value
238 */
239 public void setPutOnlyMode( boolean val )
240 {
241 this.putOnlyMode = val;
242 }
243
244 /**
245 * @return The outgoingOnlyMode value. Stops gets from going remote.
246 */
247 public boolean getPutOnlyMode()
248 {
249 return putOnlyMode;
250 }
251
252 /**
253 * Returns a clone of the attributes.
254 * @return Self
255 */
256 public AuxiliaryCacheAttributes copy()
257 {
258 try
259 {
260 return (AuxiliaryCacheAttributes) this.clone();
261 }
262 catch ( Exception e )
263 {
264 //noop
265 }
266 return this;
267 }
268
269 /**
270 * @param receive The receive to set.
271 */
272 public void setReceive( boolean receive )
273 {
274 this.receive = receive;
275 }
276
277 /**
278 * @return Returns the receive.
279 */
280 public boolean isReceive()
281 {
282 return receive;
283 }
284
285 /**
286 * The number of elements the zombie queue will hold. This queue is used to store events if we
287 * loose our connection with the server.
288 * <p>
289 * @param zombieQueueMaxSize The zombieQueueMaxSize to set.
290 */
291 public void setZombieQueueMaxSize( int zombieQueueMaxSize )
292 {
293 this.zombieQueueMaxSize = zombieQueueMaxSize;
294 }
295
296 /**
297 * The number of elements the zombie queue will hold. This queue is used to store events if we
298 * loose our connection with the server.
299 * <p>
300 * @return Returns the zombieQueueMaxSize.
301 */
302 public int getZombieQueueMaxSize()
303 {
304 return zombieQueueMaxSize;
305 }
306
307 /**
308 * @return debug string.
309 */
310 public String toString()
311 {
312 StringBuffer buf = new StringBuffer();
313 //buf.append( "cacheName=" + cacheName + "\n" );
314 //buf.append( "putOnlyMode=" + putOnlyMode + "\n" );
315 //buf.append( "transmissionTypeName=" + transmissionTypeName + "\n" );
316 //buf.append( "transmissionType=" + transmissionType + "\n" );
317 //buf.append( "tcpServer=" + tcpServer + "\n" );
318 buf.append( transmissionTypeName + httpServer + udpMulticastAddr + String.valueOf( udpMulticastPort ) );
319 return buf.toString();
320 }
321 }