| 1 | package org.apache.commons.jcs3.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.jcs3.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; |
| 45 | |
| 46 | /** what failover server we are connected to. */ |
| 47 | private int failoverIndex; |
| 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 | } |
| 71 | |
| 72 | /** |
| 73 | * Gets the failoverIndex attribute of the RemoteCacheAttributes object. |
| 74 | * <p> |
| 75 | * @return The failoverIndex value |
| 76 | */ |
| 77 | @Override |
| 78 | public int getFailoverIndex() |
| 79 | { |
| 80 | return failoverIndex; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Sets the failoverIndex attribute of the RemoteCacheAttributes object. |
| 85 | * <p> |
| 86 | * @param p The new failoverIndex value |
| 87 | */ |
| 88 | @Override |
| 89 | public void setFailoverIndex( final int p ) |
| 90 | { |
| 91 | this.failoverIndex = p; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Gets the failovers attribute of the RemoteCacheAttributes object. |
| 96 | * <p> |
| 97 | * @return The failovers value |
| 98 | */ |
| 99 | @Override |
| 100 | public List<RemoteLocation> getFailovers() |
| 101 | { |
| 102 | return this.failovers; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Sets the failovers attribute of the RemoteCacheAttributes object. |
| 107 | * <p> |
| 108 | * @param failovers The new failovers value |
| 109 | */ |
| 110 | @Override |
| 111 | public void setFailovers( final List<RemoteLocation> failovers ) |
| 112 | { |
| 113 | this.failovers = failovers; |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Gets the failoverServers attribute of the RemoteCacheAttributes object. |
| 118 | * <p> |
| 119 | * @return The failoverServers value |
| 120 | */ |
| 121 | @Override |
| 122 | public String getFailoverServers() |
| 123 | { |
| 124 | return this.failoverServers; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Sets the failoverServers attribute of the RemoteCacheAttributes object. |
| 129 | * <p> |
| 130 | * @param s The new failoverServers value |
| 131 | */ |
| 132 | @Override |
| 133 | public void setFailoverServers( final String s ) |
| 134 | { |
| 135 | this.failoverServers = s; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Gets the localPort attribute of the RemoteCacheAttributes object. |
| 140 | * <p> |
| 141 | * @return The localPort value |
| 142 | */ |
| 143 | @Override |
| 144 | public int getLocalPort() |
| 145 | { |
| 146 | return this.localPort; |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Sets the localPort attribute of the RemoteCacheAttributes object |
| 151 | * @param p The new localPort value |
| 152 | */ |
| 153 | @Override |
| 154 | public void setLocalPort( final int p ) |
| 155 | { |
| 156 | this.localPort = p; |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * @return the name of the pool |
| 161 | */ |
| 162 | @Override |
| 163 | public String getThreadPoolName() |
| 164 | { |
| 165 | return threadPoolName; |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * @param name |
| 170 | */ |
| 171 | @Override |
| 172 | public void setThreadPoolName( final String name ) |
| 173 | { |
| 174 | threadPoolName = name; |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * @return getTimeoutMillis |
| 179 | */ |
| 180 | @Override |
| 181 | public int getGetTimeoutMillis() |
| 182 | { |
| 183 | return getTimeoutMillis; |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * @param millis |
| 188 | */ |
| 189 | @Override |
| 190 | public void setGetTimeoutMillis( final int millis ) |
| 191 | { |
| 192 | getTimeoutMillis = millis; |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * By default this option is true. If you set it to false, you will not receive updates or |
| 197 | * removes from the remote server. |
| 198 | * <p> |
| 199 | * @param receive |
| 200 | */ |
| 201 | @Override |
| 202 | public void setReceive( final boolean receive ) |
| 203 | { |
| 204 | this.receive = receive; |
| 205 | } |
| 206 | |
| 207 | /** |
| 208 | * If RECEIVE is false then the remote cache will not register a listener with the remote |
| 209 | * server. This allows you to configure a remote server as a repository from which you can get |
| 210 | * and to which you put, but from which you do not receive any notifications. That is, you will |
| 211 | * not receive updates or removes. |
| 212 | * <p> |
| 213 | * If you set this option to false, you should set your local memory size to 0. |
| 214 | * <p> |
| 215 | * The remote cache manager uses this value to decide whether or not to register a listener. |
| 216 | * @return the receive value. |
| 217 | */ |
| 218 | @Override |
| 219 | public boolean isReceive() |
| 220 | { |
| 221 | return this.receive; |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * The number of elements the zombie queue will hold. This queue is used to store events if we |
| 226 | * loose our connection with the server. |
| 227 | * <p> |
| 228 | * @param zombieQueueMaxSize The zombieQueueMaxSize to set. |
| 229 | */ |
| 230 | @Override |
| 231 | public void setZombieQueueMaxSize( final int zombieQueueMaxSize ) |
| 232 | { |
| 233 | this.zombieQueueMaxSize = zombieQueueMaxSize; |
| 234 | } |
| 235 | |
| 236 | /** |
| 237 | * The number of elements the zombie queue will hold. This queue is used to store events if we |
| 238 | * loose our connection with the server. |
| 239 | * <p> |
| 240 | * @return Returns the zombieQueueMaxSize. |
| 241 | */ |
| 242 | @Override |
| 243 | public int getZombieQueueMaxSize() |
| 244 | { |
| 245 | return zombieQueueMaxSize; |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * @return String, all the important values that can be configured |
| 250 | */ |
| 251 | @Override |
| 252 | public String toString() |
| 253 | { |
| 254 | final StringBuilder buf = new StringBuilder(super.toString()); |
| 255 | buf.append( "\n receive = [" + isReceive() + "]" ); |
| 256 | buf.append( "\n getTimeoutMillis = [" + getGetTimeoutMillis() + "]" ); |
| 257 | buf.append( "\n threadPoolName = [" + getThreadPoolName() + "]" ); |
| 258 | buf.append( "\n localClusterConsistency = [" + isLocalClusterConsistency() + "]" ); |
| 259 | buf.append( "\n zombieQueueMaxSize = [" + getZombieQueueMaxSize() + "]" ); |
| 260 | return buf.toString(); |
| 261 | } |
| 262 | } |