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 java.util.List; 023 024import org.apache.commons.jcs.auxiliary.remote.behavior.IRemoteCacheAttributes; 025 026/** 027 * These objects are used to configure the remote cache client. 028 */ 029public class RemoteCacheAttributes 030 extends CommonRemoteCacheAttributes 031 implements IRemoteCacheAttributes 032{ 033 /** Don't change */ 034 private static final long serialVersionUID = -1555143736942374000L; 035 036 /** 037 * Failover servers will be used by local caches one at a time. Listeners will be registered 038 * with all cluster servers. If we add a get from cluster attribute we will have the ability to 039 * chain clusters and have them get from each other. 040 */ 041 private String failoverServers = ""; 042 043 /** callback */ 044 private int localPort = 0; 045 046 /** what failover server we are connected to. */ 047 private int failoverIndex = 0; 048 049 /** List of failover server addresses */ 050 private List<RemoteLocation> failovers; 051 052 /** default name is remote_cache_client */ 053 private String threadPoolName = "remote_cache_client"; 054 055 /** must be greater than 0 for a pool to be used. */ 056 private int getTimeoutMillis = -1; 057 058 /** 059 * Can we receive from the server. You might have a 0 local store and keep everything on the 060 * remote. If so, you don't want to be notified of updates. 061 */ 062 private boolean receive = DEFAULT_RECEIVE; 063 064 /** If the primary fails, we will queue items before reconnect. This limits the number of items that can be queued. */ 065 private int zombieQueueMaxSize = DEFAULT_ZOMBIE_QUEUE_MAX_SIZE; 066 067 /** Default constructor for the RemoteCacheAttributes object */ 068 public RemoteCacheAttributes() 069 { 070 super(); 071 } 072 073 /** 074 * Gets the failoverIndex attribute of the RemoteCacheAttributes object. 075 * <p> 076 * @return The failoverIndex value 077 */ 078 @Override 079 public int getFailoverIndex() 080 { 081 return failoverIndex; 082 } 083 084 /** 085 * Sets the failoverIndex attribute of the RemoteCacheAttributes object. 086 * <p> 087 * @param p The new failoverIndex value 088 */ 089 @Override 090 public void setFailoverIndex( int p ) 091 { 092 this.failoverIndex = p; 093 } 094 095 /** 096 * Gets the failovers attribute of the RemoteCacheAttributes object. 097 * <p> 098 * @return The failovers value 099 */ 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}