1 package org.apache.commons.jcs.auxiliary.remote; 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.util.List; 23 24 import org.apache.commons.jcs.auxiliary.remote.behavior.IRemoteCacheAttributes; 25 26 /** 27 * These objects are used to configure the remote cache client. 28 */ 29 public class RemoteCacheAttributes 30 extends CommonRemoteCacheAttributes 31 implements IRemoteCacheAttributes 32 { 33 /** Don't change */ 34 private static final long serialVersionUID = -1555143736942374000L; 35 36 /** 37 * Failover servers will be used by local caches one at a time. Listeners will be registered 38 * with all cluster servers. If we add a get from cluster attribute we will have the ability to 39 * chain clusters and have them get from each other. 40 */ 41 private String failoverServers = ""; 42 43 /** callback */ 44 private int localPort = 0; 45 46 /** what failover server we are connected to. */ 47 private int failoverIndex = 0; 48 49 /** List of failover server addresses */ 50 private List<RemoteLocation> failovers; 51 52 /** default name is remote_cache_client */ 53 private String threadPoolName = "remote_cache_client"; 54 55 /** must be greater than 0 for a pool to be used. */ 56 private int getTimeoutMillis = -1; 57 58 /** 59 * Can we receive from the server. You might have a 0 local store and keep everything on the 60 * remote. If so, you don't want to be notified of updates. 61 */ 62 private boolean receive = DEFAULT_RECEIVE; 63 64 /** If the primary fails, we will queue items before reconnect. This limits the number of items that can be queued. */ 65 private int zombieQueueMaxSize = DEFAULT_ZOMBIE_QUEUE_MAX_SIZE; 66 67 /** Default constructor for the RemoteCacheAttributes object */ 68 public RemoteCacheAttributes() 69 { 70 super(); 71 } 72 73 /** 74 * Gets the failoverIndex attribute of the RemoteCacheAttributes object. 75 * <p> 76 * @return The failoverIndex value 77 */ 78 @Override 79 public int getFailoverIndex() 80 { 81 return failoverIndex; 82 } 83 84 /** 85 * Sets the failoverIndex attribute of the RemoteCacheAttributes object. 86 * <p> 87 * @param p The new failoverIndex value 88 */ 89 @Override 90 public void setFailoverIndex( int p ) 91 { 92 this.failoverIndex = p; 93 } 94 95 /** 96 * Gets the failovers attribute of the RemoteCacheAttributes object. 97 * <p> 98 * @return The failovers value 99 */ 100 @Override 101 public List<RemoteLocation> getFailovers() 102 { 103 return this.failovers; 104 } 105 106 /** 107 * Sets the failovers attribute of the RemoteCacheAttributes object. 108 * <p> 109 * @param failovers The new failovers value 110 */ 111 @Override 112 public void setFailovers( List<RemoteLocation> failovers ) 113 { 114 this.failovers = failovers; 115 } 116 117 /** 118 * Gets the failoverServers attribute of the RemoteCacheAttributes object. 119 * <p> 120 * @return The failoverServers value 121 */ 122 @Override 123 public String getFailoverServers() 124 { 125 return this.failoverServers; 126 } 127 128 /** 129 * Sets the failoverServers attribute of the RemoteCacheAttributes object. 130 * <p> 131 * @param s The new failoverServers value 132 */ 133 @Override 134 public void setFailoverServers( String s ) 135 { 136 this.failoverServers = s; 137 } 138 139 /** 140 * Gets the localPort attribute of the RemoteCacheAttributes object. 141 * <p> 142 * @return The localPort value 143 */ 144 @Override 145 public int getLocalPort() 146 { 147 return this.localPort; 148 } 149 150 /** 151 * Sets the localPort attribute of the RemoteCacheAttributes object 152 * @param p The new localPort value 153 */ 154 @Override 155 public void setLocalPort( int p ) 156 { 157 this.localPort = p; 158 } 159 160 /** 161 * @return the name of the pool 162 */ 163 @Override 164 public String getThreadPoolName() 165 { 166 return threadPoolName; 167 } 168 169 /** 170 * @param name 171 */ 172 @Override 173 public void setThreadPoolName( String name ) 174 { 175 threadPoolName = name; 176 } 177 178 /** 179 * @return getTimeoutMillis 180 */ 181 @Override 182 public int getGetTimeoutMillis() 183 { 184 return getTimeoutMillis; 185 } 186 187 /** 188 * @param millis 189 */ 190 @Override 191 public void setGetTimeoutMillis( int millis ) 192 { 193 getTimeoutMillis = millis; 194 } 195 196 /** 197 * By default this option is true. If you set it to false, you will not receive updates or 198 * removes from the remote server. 199 * <p> 200 * @param receive 201 */ 202 @Override 203 public void setReceive( boolean receive ) 204 { 205 this.receive = receive; 206 } 207 208 /** 209 * If RECEIVE is false then the remote cache will not register a listener with the remote 210 * server. This allows you to configure a remote server as a repository from which you can get 211 * and to which you put, but from which you do not receive any notifications. That is, you will 212 * not receive updates or removes. 213 * <p> 214 * If you set this option to false, you should set your local memory size to 0. 215 * <p> 216 * The remote cache manager uses this value to decide whether or not to register a listener. 217 * @return the receive value. 218 */ 219 @Override 220 public boolean isReceive() 221 { 222 return this.receive; 223 } 224 225 /** 226 * The number of elements the zombie queue will hold. This queue is used to store events if we 227 * loose our connection with the server. 228 * <p> 229 * @param zombieQueueMaxSize The zombieQueueMaxSize to set. 230 */ 231 @Override 232 public void setZombieQueueMaxSize( int zombieQueueMaxSize ) 233 { 234 this.zombieQueueMaxSize = zombieQueueMaxSize; 235 } 236 237 /** 238 * The number of elements the zombie queue will hold. This queue is used to store events if we 239 * loose our connection with the server. 240 * <p> 241 * @return Returns the zombieQueueMaxSize. 242 */ 243 @Override 244 public int getZombieQueueMaxSize() 245 { 246 return zombieQueueMaxSize; 247 } 248 249 /** 250 * @return String, all the important values that can be configured 251 */ 252 @Override 253 public String toString() 254 { 255 StringBuilder buf = new StringBuilder(super.toString()); 256 buf.append( "\n receive = [" + isReceive() + "]" ); 257 buf.append( "\n getTimeoutMillis = [" + getGetTimeoutMillis() + "]" ); 258 buf.append( "\n threadPoolName = [" + getThreadPoolName() + "]" ); 259 buf.append( "\n localClusterConsistency = [" + isLocalClusterConsistency() + "]" ); 260 buf.append( "\n zombieQueueMaxSize = [" + getZombieQueueMaxSize() + "]" ); 261 return buf.toString(); 262 } 263 }