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 java.util.List;
023
024import org.apache.commons.jcs3.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;
045
046    /** what failover server we are connected to. */
047    private int failoverIndex;
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    }
071
072    /**
073     * Gets the failoverIndex attribute of the RemoteCacheAttributes object.
074     * <p>
075     * @return The failoverIndex value
076     */
077    @Override
078    public int getFailoverIndex()
079    {
080        return failoverIndex;
081    }
082
083    /**
084     * Sets the failoverIndex attribute of the RemoteCacheAttributes object.
085     * <p>
086     * @param p The new failoverIndex value
087     */
088    @Override
089    public void setFailoverIndex( final int p )
090    {
091        this.failoverIndex = p;
092    }
093
094    /**
095     * Gets the failovers attribute of the RemoteCacheAttributes object.
096     * <p>
097     * @return The failovers value
098     */
099    @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}