001package org.apache.commons.jcs3.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.jcs3.auxiliary.AbstractAuxiliaryCacheAttributes; 023import org.apache.commons.jcs3.auxiliary.remote.behavior.ICommonRemoteCacheAttributes; 024import org.apache.commons.jcs3.auxiliary.remote.behavior.IRemoteCacheConstants; 025import org.apache.commons.jcs3.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; 054 055 /** Should we put and get from the clusters. */ 056 private boolean localClusterConsistency; 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 } 065 066 /** 067 * Gets the remoteTypeName attribute of the RemoteCacheAttributes object. 068 * <p> 069 * @return The remoteTypeName value 070 */ 071 @Override 072 public String getRemoteTypeName() 073 { 074 return remoteType != null ? remoteType.toString() : RemoteType.LOCAL.toString(); 075 } 076 077 /** 078 * Sets the remoteTypeName attribute of the RemoteCacheAttributes object. 079 * <p> 080 * @param s The new remoteTypeName value 081 */ 082 @Override 083 public void setRemoteTypeName( final String s ) 084 { 085 this.remoteType = RemoteType.valueOf(s); 086 } 087 088 /** 089 * Gets the remoteType attribute of the RemoteCacheAttributes object. 090 * <p> 091 * @return The remoteType value 092 */ 093 @Override 094 public RemoteType getRemoteType() 095 { 096 return remoteType; 097 } 098 099 /** 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}