001package org.apache.commons.jcs3.auxiliary.lateral;
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.lateral.behavior.ILateralCacheAttributes;
024
025/**
026 * This class stores attributes for all of the available lateral cache auxiliaries.
027 */
028public class LateralCacheAttributes
029    extends AbstractAuxiliaryCacheAttributes
030    implements ILateralCacheAttributes
031{
032    /** Don't change */
033    private static final long serialVersionUID = -3408449508837393660L;
034
035    /** Default receive setting */
036    private static final boolean DEFAULT_RECEIVE = true;
037
038    /** indicates the lateral type, this needs to change */
039    private Type transmissionType = Type.UDP;
040
041    /** The http servers */
042    private String httpServers;
043
044    /** used to identify the service that this manager will be operating on */
045    private String httpServer = "";
046
047    /** this needs to change */
048    private String udpMulticastAddr = "228.5.6.7";
049
050    /** this needs to change */
051    private int udpMulticastPort = 6789;
052
053    /** this needs to change */
054    private int httpListenerPort = 8080;
055
056    /** disables gets from laterals */
057    private boolean putOnlyMode = true;
058
059    /**
060     * do we receive and broadcast or only broadcast this is useful when you don't want to get any
061     * notifications
062     */
063    private boolean receive = DEFAULT_RECEIVE;
064
065    /** If the primary fails, we will queue items before reconnect.  This limits the number of items that can be queued. */
066    private int zombieQueueMaxSize = DEFAULT_ZOMBIE_QUEUE_MAX_SIZE;
067
068    /**
069     * Sets the httpServer attribute of the LateralCacheAttributes object
070     * <P>
071     * @param val The new httpServer value
072     */
073    @Override
074    public void setHttpServer( final String val )
075    {
076        httpServer = val;
077    }
078
079    /**
080     * Gets the httpServer attribute of the LateralCacheAttributes object
081     * @return The httpServer value
082     */
083    @Override
084    public String getHttpServer()
085    {
086        return httpServer;
087    }
088
089    /**
090     * Sets the httpServers attribute of the LateralCacheAttributes object
091     * @param val The new httpServers value
092     */
093    @Override
094    public void setHttpServers( final String val )
095    {
096        httpServers = val;
097    }
098
099    /**
100     * Gets the httpSrvers attribute of the LateralCacheAttributes object
101     * @return The httpServers value
102     */
103    @Override
104    public String getHttpServers()
105    {
106        return httpServers;
107    }
108
109    /**
110     * Sets the httpListenerPort attribute of the ILateralCacheAttributes object
111     * @param val The new tcpListenerPort value
112     */
113    @Override
114    public void setHttpListenerPort( final int val )
115    {
116        this.httpListenerPort = val;
117    }
118
119    /**
120     * Gets the httpListenerPort attribute of the ILateralCacheAttributes object
121     * @return The httpListenerPort value
122     */
123    @Override
124    public int getHttpListenerPort()
125    {
126        return this.httpListenerPort;
127    }
128
129    /**
130     * Sets the udpMulticastAddr attribute of the LateralCacheAttributes object
131     * @param val The new udpMulticastAddr value
132     */
133    @Override
134    public void setUdpMulticastAddr( final String val )
135    {
136        udpMulticastAddr = val;
137    }
138
139    /**
140     * Gets the udpMulticastAddr attribute of the LateralCacheAttributes object
141     * @return The udpMulticastAddr value
142     */
143    @Override
144    public String getUdpMulticastAddr()
145    {
146        return udpMulticastAddr;
147    }
148
149    /**
150     * Sets the udpMulticastPort attribute of the LateralCacheAttributes object
151     * @param val The new udpMulticastPort value
152     */
153    @Override
154    public void setUdpMulticastPort( final int val )
155    {
156        udpMulticastPort = val;
157    }
158
159    /**
160     * Gets the udpMulticastPort attribute of the LateralCacheAttributes object
161     * @return The udpMulticastPort value
162     */
163    @Override
164    public int getUdpMulticastPort()
165    {
166        return udpMulticastPort;
167    }
168
169    /**
170     * Sets the transmissionType attribute of the LateralCacheAttributes object
171     * @param val The new transmissionType value
172     */
173    @Override
174    public void setTransmissionType( final Type val )
175    {
176        this.transmissionType = val;
177    }
178
179    /**
180     * Gets the transmissionType attribute of the LateralCacheAttributes object
181     * @return The transmissionType value
182     */
183    @Override
184    public Type getTransmissionType()
185    {
186        return this.transmissionType;
187    }
188
189    /**
190     * Sets the transmissionTypeName attribute of the LateralCacheAttributes object
191     * @param val The new transmissionTypeName value
192     * @deprecated
193     */
194    @Override
195    @Deprecated
196    public void setTransmissionTypeName( final String val )
197    {
198        this.transmissionType = Type.valueOf(val);
199    }
200
201    /**
202     * Gets the transmissionTypeName attribute of the LateralCacheAttributes object
203     * @return The transmissionTypeName value
204     * @deprecated
205     */
206    @Override
207    @Deprecated
208    public String getTransmissionTypeName()
209    {
210        return this.transmissionType.toString();
211    }
212
213    /**
214     * Sets the outgoingOnlyMode attribute of the ILateralCacheAttributes. When this is true the
215     * lateral cache will only issue put and remove order and will not try to retrieve elements from
216     * other lateral caches.
217     * @param val The new transmissionTypeName value
218     */
219    @Override
220    public void setPutOnlyMode( final boolean val )
221    {
222        this.putOnlyMode = val;
223    }
224
225    /**
226     * @return The outgoingOnlyMode value. Stops gets from going remote.
227     */
228    @Override
229    public boolean getPutOnlyMode()
230    {
231        return putOnlyMode;
232    }
233
234    /**
235     * @param receive The receive to set.
236     */
237    @Override
238    public void setReceive( final boolean receive )
239    {
240        this.receive = receive;
241    }
242
243    /**
244     * @return Returns the receive.
245     */
246    @Override
247    public boolean isReceive()
248    {
249        return receive;
250    }
251
252    /**
253     * The number of elements the zombie queue will hold. This queue is used to store events if we
254     * loose our connection with the server.
255     * <p>
256     * @param zombieQueueMaxSize The zombieQueueMaxSize to set.
257     */
258    @Override
259    public void setZombieQueueMaxSize( final int zombieQueueMaxSize )
260    {
261        this.zombieQueueMaxSize = zombieQueueMaxSize;
262    }
263
264    /**
265     * The number of elements the zombie queue will hold. This queue is used to store events if we
266     * loose our connection with the server.
267     * <p>
268     * @return Returns the zombieQueueMaxSize.
269     */
270    @Override
271    public int getZombieQueueMaxSize()
272    {
273        return zombieQueueMaxSize;
274    }
275
276    /**
277     * @return debug string.
278     */
279    @Override
280    public String toString()
281    {
282        final StringBuilder buf = new StringBuilder();
283        //buf.append( "cacheName=" + cacheName + "\n" );
284        //buf.append( "putOnlyMode=" + putOnlyMode + "\n" );
285        //buf.append( "transmissionTypeName=" + transmissionTypeName + "\n" );
286        //buf.append( "transmissionType=" + transmissionType + "\n" );
287        //buf.append( "tcpServer=" + tcpServer + "\n" );
288        buf.append( transmissionType.toString() + httpServer + udpMulticastAddr + String.valueOf( udpMulticastPort ) );
289        return buf.toString();
290    }
291}