View Javadoc

1   package org.apache.jcs.auxiliary.lateral.socket.tcp;
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.AuxiliaryCacheAttributes;
23  import org.apache.jcs.auxiliary.lateral.LateralCacheAttributes;
24  import org.apache.jcs.auxiliary.lateral.socket.tcp.behavior.ITCPLateralCacheAttributes;
25  
26  /**
27   * This interface defines functions that are particular to the TCP Lateral Cache plugin. It extends
28   * the generic LateralCacheAttributes interface which in turn extends the AuxiliaryCache interface.
29   */
30  public class TCPLateralCacheAttributes
31      extends LateralCacheAttributes
32      implements ITCPLateralCacheAttributes
33  {
34      /** Don't change. */
35      private static final long serialVersionUID = 1077889204513905220L;
36  
37      /** default */
38      private static final String DEFAULT_UDP_DISCOVERY_ADDRESS = "228.5.6.7";
39  
40      /** default */
41      private static final int DEFAULT_UDP_DISCOVERY_PORT = 6789;
42  
43      /** default */
44      private static final boolean DEFAULT_UDP_DISCOVERY_ENABLED = true;
45  
46      /** default */
47      private static final boolean DEFAULT_ALLOW_GET = true;
48  
49      /** default */
50      private static final boolean DEFAULT_ALLOW_PUT = true;
51  
52      /** default */
53      private static final boolean DEFAULT_ISSUE_REMOVE_FOR_PUT = false;
54  
55      /** default */
56      private static final boolean DEFAULT_FILTER_REMOVE_BY_HASH_CODE = true;
57  
58      /** default - Only block for 1 second before timing out on a read.*/
59      private static final int DEFAULT_SOCKET_TIME_OUT = 1000;
60  
61      /** default - Only block for 2 seconds before timing out on startup.*/
62      private static final int DEFAULT_OPEN_TIMEOUT = 2000;
63  
64      /** TCP -------------------------------------------- */
65      private String tcpServers = "";
66  
67      /** used to identify the service that this manager will be operating on */
68      private String tcpServer = "";
69  
70      /** The pot */
71      private int tcpListenerPort = 0;
72  
73      /** udp discovery for tcp server */
74      private String udpDiscoveryAddr = DEFAULT_UDP_DISCOVERY_ADDRESS;
75  
76      /** discovery port */
77      private int udpDiscoveryPort = DEFAULT_UDP_DISCOVERY_PORT;
78  
79      /** discovery switch */
80      private boolean udpDiscoveryEnabled = DEFAULT_UDP_DISCOVERY_ENABLED;
81  
82      /** can we put */
83      private boolean allowPut = DEFAULT_ALLOW_GET;
84  
85      /** can we go laterally for a get */
86      private boolean allowGet = DEFAULT_ALLOW_PUT;
87  
88      /** call remove when there is a put */
89      private boolean issueRemoveOnPut = DEFAULT_ISSUE_REMOVE_FOR_PUT;
90  
91      /** don't remove it the hashcode is the same */
92      private boolean filterRemoveByHashCode = DEFAULT_FILTER_REMOVE_BY_HASH_CODE;
93     
94      /** Only block for socketTimeOut seconds before timing out on a read.  */
95      private int socketTimeOut = DEFAULT_SOCKET_TIME_OUT;
96  
97      /** Only block for openTimeOut seconds before timing out on startup. */
98      private int openTimeOut = DEFAULT_OPEN_TIMEOUT;
99      
100     /**
101      * Sets the tcpServer attribute of the ILateralCacheAttributes object
102      * <p>
103      * @param val The new tcpServer value
104      */
105     public void setTcpServer( String val )
106     {
107         this.tcpServer = val;
108     }
109 
110     /**
111      * Gets the tcpServer attribute of the ILateralCacheAttributes object
112      * <p>
113      * @return The tcpServer value
114      */
115     public String getTcpServer()
116     {
117         return this.tcpServer;
118     }
119 
120     /**
121      * Sets the tcpServers attribute of the ILateralCacheAttributes object
122      * <p>
123      * @param val The new tcpServers value
124      */
125     public void setTcpServers( String val )
126     {
127         this.tcpServers = val;
128     }
129 
130     /**
131      * Gets the tcpServers attribute of the ILateralCacheAttributes object
132      * <p>
133      * @return The tcpServers value
134      */
135     public String getTcpServers()
136     {
137         return this.tcpServers;
138     }
139 
140     /**
141      * Sets the tcpListenerPort attribute of the ILateralCacheAttributes object
142      * <p>
143      * @param val The new tcpListenerPort value
144      */
145     public void setTcpListenerPort( int val )
146     {
147         this.tcpListenerPort = val;
148     }
149 
150     /**
151      * Gets the tcpListenerPort attribute of the ILateralCacheAttributes object
152      * <p>
153      * @return The tcpListenerPort value
154      */
155     public int getTcpListenerPort()
156     {
157         return this.tcpListenerPort;
158     }
159 
160     /**
161      * Can setup UDP Discovery. This only works for TCp laterals right now. It allows TCP laterals
162      * to find each other by broadcasting to a multicast port.
163      * <p>
164      * @param udpDiscoveryEnabled The udpDiscoveryEnabled to set.
165      */
166     public void setUdpDiscoveryEnabled( boolean udpDiscoveryEnabled )
167     {
168         this.udpDiscoveryEnabled = udpDiscoveryEnabled;
169     }
170 
171     /**
172      * Whether or not TCP laterals can try to find each other by multicast communication.
173      * <p>
174      * @return Returns the udpDiscoveryEnabled.
175      */
176     public boolean isUdpDiscoveryEnabled()
177     {
178         return this.udpDiscoveryEnabled;
179     }
180 
181     /**
182      * The port to use if UDPDiscovery is enabled.
183      * <p>
184      * @return Returns the udpDiscoveryPort.
185      */
186     public int getUdpDiscoveryPort()
187     {
188         return this.udpDiscoveryPort;
189     }
190 
191     /**
192      * Sets the port to use if UDPDiscovery is enabled.
193      * <p>
194      * @param udpDiscoveryPort The udpDiscoveryPort to set.
195      */
196     public void setUdpDiscoveryPort( int udpDiscoveryPort )
197     {
198         this.udpDiscoveryPort = udpDiscoveryPort;
199     }
200 
201     /**
202      * The address to broadcast to if UDPDiscovery is enabled.
203      * <p>
204      * @return Returns the udpDiscoveryAddr.
205      */
206     public String getUdpDiscoveryAddr()
207     {
208         return this.udpDiscoveryAddr;
209     }
210 
211     /**
212      * Sets the address to broadcast to if UDPDiscovery is enabled.
213      * <p>
214      * @param udpDiscoveryAddr The udpDiscoveryAddr to set.
215      */
216     public void setUdpDiscoveryAddr( String udpDiscoveryAddr )
217     {
218         this.udpDiscoveryAddr = udpDiscoveryAddr;
219     }
220 
221     /**
222      * Is the lateral allowed to try and get from other laterals.
223      * <p>
224      * This replaces the old putOnlyMode
225      * <p>
226      * @param allowGet
227      */
228     public void setAllowGet( boolean allowGet )
229     {
230         this.allowGet = allowGet;
231     }
232 
233     /**
234      * Is the lateral allowed to try and get from other laterals.
235      * <p>
236      * @return true if the lateral will try to get
237      */
238     public boolean isAllowGet()
239     {
240         return this.allowGet;
241     }
242 
243     /**
244      * Is the lateral allowed to put objects to other laterals.
245      * <p>
246      * @param allowPut
247      */
248     public void setAllowPut( boolean allowPut )
249     {
250         this.allowPut = allowPut;
251     }
252 
253     /**
254      * Is the lateral allowed to put objects to other laterals.
255      * <p>
256      * @return true if puts are allowed
257      */
258     public boolean isAllowPut()
259     {
260         return this.allowPut;
261     }
262 
263     /**
264      * Should the client send a remove command rather than a put when update is called. This is a
265      * client option, not a receiver option. This allows you to prevent the lateral from serializing
266      * objects.
267      * <p>
268      * @param issueRemoveOnPut
269      */
270     public void setIssueRemoveOnPut( boolean issueRemoveOnPut )
271     {
272         this.issueRemoveOnPut = issueRemoveOnPut;
273     }
274 
275     /**
276      * Should the client send a remove command rather than a put when update is called. This is a
277      * client option, not a receiver option. This allows you to prevent the lateral from serializing
278      * objects.
279      * <p>
280      * @return true if updates will result in a remove command being sent.
281      */
282     public boolean isIssueRemoveOnPut()
283     {
284         return this.issueRemoveOnPut;
285     }
286 
287     /**
288      * @return AuxiliaryCacheAttributes
289      */
290     public AuxiliaryCacheAttributes copy()
291     {
292         try
293         {
294             return (AuxiliaryCacheAttributes) this.clone();
295         }
296         catch ( Exception e )
297         {
298             //noop
299         }
300         return this;
301     }
302 
303     /**
304      * Should the receiver try to match hashcodes. If true, the receiver will see if the client
305      * supplied a hshcode. If it did, then it will try to get the item locally. If the item exists,
306      * then it will compare the hashcode. if they are the same, it will not remove. This isn't
307      * perfect since different objects can have the same hashcode, but it is unlikely of objects of
308      * the same type.
309      * <p>
310      * @return boolean
311      */
312     public boolean isFilterRemoveByHashCode()
313     {
314         return this.filterRemoveByHashCode;
315     }
316 
317     /**
318      * Should the receiver try to match hashcodes. If true, the receiver will see if the client
319      * supplied a hshcode. If it did, then it will try to get the item locally. If the item exists,
320      * then it will compare the hashcode. if they are the same, it will not remove. This isn't
321      * perfect since different objects can have the same hashcode, but it is unlikely of objects of
322      * the same type.
323      * <p>
324      * @param filter
325      */
326     public void setFilterRemoveByHashCode( boolean filter )
327     {
328         this.filterRemoveByHashCode = filter;
329     }
330 
331     /**
332      * @param socketTimeOut the socketTimeOut to set
333      */
334     public void setSocketTimeOut( int socketTimeOut )
335     {
336         this.socketTimeOut = socketTimeOut;
337     }
338 
339     /**
340      * @return the socketTimeOut
341      */
342     public int getSocketTimeOut()
343     {
344         return socketTimeOut;
345     }
346 
347     /**
348      * @param openTimeOut the openTimeOut to set
349      */
350     public void setOpenTimeOut( int openTimeOut )
351     {
352         this.openTimeOut = openTimeOut;
353     }
354 
355     /**
356      * @return the openTimeOut
357      */
358     public int getOpenTimeOut()
359     {
360         return openTimeOut;
361     }
362 
363     /**
364      * Used to key the instance TODO create another method for this and use toString for debugging
365      * only.
366      * <p>
367      * @return String
368      */
369     public String toString()
370     {
371         return this.getTcpServer() + ":" + this.getTcpListenerPort();
372     }
373 }