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