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