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