001package org.apache.commons.jcs.auxiliary.remote; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import org.apache.commons.jcs.auxiliary.AbstractAuxiliaryCacheAttributes; 023import org.apache.commons.jcs.auxiliary.remote.behavior.ICommonRemoteCacheAttributes; 024import org.apache.commons.jcs.auxiliary.remote.behavior.IRemoteCacheConstants; 025import org.apache.commons.jcs.auxiliary.remote.server.behavior.RemoteType; 026 027/** 028 * Attributes common to remote cache client and server. 029 */ 030public class CommonRemoteCacheAttributes 031 extends AbstractAuxiliaryCacheAttributes 032 implements ICommonRemoteCacheAttributes 033{ 034 /** Don't change */ 035 private static final long serialVersionUID = -1555143736942374000L; 036 037 /** The service name */ 038 private String remoteServiceName = IRemoteCacheConstants.REMOTE_CACHE_SERVICE_VAL; 039 040 /** server host and port */ 041 private RemoteLocation location; 042 043 /** Cluster chain */ 044 private String clusterServers = ""; 045 046 /** THe type of remote cache, local or cluster */ 047 private RemoteType remoteType = RemoteType.LOCAL; 048 049 /** Should we issue a local remove if we get a put from a remote server */ 050 private boolean removeUponRemotePut = true; 051 052 /** Can we receive from or put to the remote. this probably shouldn't be used. Use receive. */ 053 private boolean getOnly = false; 054 055 /** Should we put and get from the clusters. */ 056 private boolean localClusterConsistency = false; 057 058 /** read and connect timeout */ 059 private int rmiSocketFactoryTimeoutMillis = DEFAULT_RMI_SOCKET_FACTORY_TIMEOUT_MILLIS; 060 061 /** Default constructor for the RemoteCacheAttributes object */ 062 public CommonRemoteCacheAttributes() 063 { 064 super(); 065 } 066 067 /** 068 * Gets the remoteTypeName attribute of the RemoteCacheAttributes object. 069 * <p> 070 * @return The remoteTypeName value 071 */ 072 @Override 073 public String getRemoteTypeName() 074 { 075 return remoteType != null ? remoteType.toString() : RemoteType.LOCAL.toString(); 076 } 077 078 /** 079 * Sets the remoteTypeName attribute of the RemoteCacheAttributes object. 080 * <p> 081 * @param s The new remoteTypeName value 082 */ 083 @Override 084 public void setRemoteTypeName( String s ) 085 { 086 RemoteType rt = RemoteType.valueOf(s); 087 if (rt != null) 088 { 089 this.remoteType = rt; 090 } 091 } 092 093 /** 094 * Gets the remoteType attribute of the RemoteCacheAttributes object. 095 * <p> 096 * @return The remoteType value 097 */ 098 @Override 099 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}