001package org.apache.commons.jcs3.utils.discovery;
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/**
023 * Configuration properties for UDP discover service.
024 * <p>
025 * The service will allow out applications to find each other.
026 * </p>
027 */
028public final class UDPDiscoveryAttributes
029    implements Cloneable
030{
031    /** service name */
032    private String serviceName;
033
034    /** service address */
035    private String serviceAddress;
036
037    /** service port */
038    private int servicePort;
039
040    /**
041     * false -> this service instance is not ready to receive requests. true -> ready for use
042     */
043    private boolean isDark;
044
045    /** default udp discovery address */
046    private static final String DEFAULT_UDP_DISCOVERY_ADDRESS = "228.4.5.6";
047
048    /** default udp discovery port */
049    private static final int DEFAULT_UDP_DISCOVERY_PORT = 5678;
050
051    /** udp discovery address */
052    private String udpDiscoveryAddr = DEFAULT_UDP_DISCOVERY_ADDRESS;
053
054    /** udp discovery network interface */
055    private String udpDiscoveryInterface;
056
057    /** udp discovery port */
058    private int udpDiscoveryPort = DEFAULT_UDP_DISCOVERY_PORT;
059
060    /** udp datagram TTL */
061    private int udpTTL;
062
063    /** default delay between sending passive broadcasts */
064    private static final int DEFAULT_SEND_DELAY_SEC = 60;
065
066    /** delay between sending passive broadcasts */
067    private int sendDelaySec = DEFAULT_SEND_DELAY_SEC;
068
069    /** default amount of time before we remove services that we haven't heard from */
070    private static final int DEFAULT_MAX_IDLE_TIME_SEC = 180;
071
072    /** amount of time before we remove services that we haven't heard from */
073    private int maxIdleTimeSec = DEFAULT_MAX_IDLE_TIME_SEC;
074
075    /**
076     * @param serviceName The serviceName to set.
077     */
078    public void setServiceName( final String serviceName )
079    {
080        this.serviceName = serviceName;
081    }
082
083    /**
084     * @return Returns the serviceName.
085     */
086    public String getServiceName()
087    {
088        return serviceName;
089    }
090
091    /**
092     * @param serviceAddress The serviceAddress to set.
093     */
094    public void setServiceAddress( final String serviceAddress )
095    {
096        this.serviceAddress = serviceAddress;
097    }
098
099    /**
100     * @return Returns the serviceAddress.
101     */
102    public String getServiceAddress()
103    {
104        return serviceAddress;
105    }
106
107    /**
108     * @param servicePort The servicePort to set.
109     */
110    public void setServicePort( final int servicePort )
111    {
112        this.servicePort = servicePort;
113    }
114
115    /**
116     * @return Returns the servicePort.
117     */
118    public int getServicePort()
119    {
120        return servicePort;
121    }
122
123    /**
124     * @param udpDiscoveryAddr The udpDiscoveryAddr to set.
125     */
126    public void setUdpDiscoveryAddr( final String udpDiscoveryAddr )
127    {
128        this.udpDiscoveryAddr = udpDiscoveryAddr;
129    }
130
131    /**
132     * @return Returns the udpDiscoveryAddr.
133     */
134    public String getUdpDiscoveryAddr()
135    {
136        return udpDiscoveryAddr;
137    }
138
139    /**
140     * @param udpDiscoveryInterface The udpDiscoveryInterface to set.
141     */
142    public void setUdpDiscoveryInterface( final String udpDiscoveryInterface )
143    {
144        this.udpDiscoveryInterface = udpDiscoveryInterface;
145    }
146
147    /**
148     * @return Returns the udpDiscoveryInterface.
149     */
150    public String getUdpDiscoveryInterface()
151    {
152        return udpDiscoveryInterface;
153    }
154
155    /**
156     * @param udpDiscoveryPort The udpDiscoveryPort to set.
157     */
158    public void setUdpDiscoveryPort( final int udpDiscoveryPort )
159    {
160        this.udpDiscoveryPort = udpDiscoveryPort;
161    }
162
163    /**
164     * @return Returns the udpTTL.
165     */
166    public int getUdpTTL()
167    {
168        return udpTTL;
169    }
170
171    /**
172     * @param udpTTL The udpTTL to set.
173     */
174    public void setUdpTTL( final int udpTTL )
175    {
176        this.udpTTL = udpTTL;
177    }
178
179    /**
180     * @return Returns the udpDiscoveryPort.
181     */
182    public int getUdpDiscoveryPort()
183    {
184        return udpDiscoveryPort;
185    }
186
187    /**
188     * @param sendDelaySec The sendDelaySec to set.
189     */
190    public void setSendDelaySec( final int sendDelaySec )
191    {
192        this.sendDelaySec = sendDelaySec;
193    }
194
195    /**
196     * @return Returns the sendDelaySec.
197     */
198    public int getSendDelaySec()
199    {
200        return sendDelaySec;
201    }
202
203    /**
204     * @param maxIdleTimeSec The maxIdleTimeSec to set.
205     */
206    public void setMaxIdleTimeSec( final int maxIdleTimeSec )
207    {
208        this.maxIdleTimeSec = maxIdleTimeSec;
209    }
210
211    /**
212     * @return Returns the maxIdleTimeSec.
213     */
214    public int getMaxIdleTimeSec()
215    {
216        return maxIdleTimeSec;
217    }
218
219    /**
220     * @return Returns the isDark.
221     */
222    public boolean isDark()
223    {
224        return isDark;
225    }
226
227    /**
228     * @param isDark The isDark to set.
229     */
230    public void setDark( final boolean isDark )
231    {
232        this.isDark = isDark;
233    }
234
235    /** @return a clone of this object */
236    @Override
237    public UDPDiscoveryAttributes clone()
238    {
239        final UDPDiscoveryAttributes attributes = new UDPDiscoveryAttributes();
240        attributes.setSendDelaySec( this.getSendDelaySec() );
241        attributes.setMaxIdleTimeSec( this.getMaxIdleTimeSec() );
242        attributes.setServiceName( this.getServiceName() );
243        attributes.setServicePort( this.getServicePort() );
244        attributes.setUdpDiscoveryAddr( this.getUdpDiscoveryAddr() );
245        attributes.setUdpDiscoveryPort( this.getUdpDiscoveryPort() );
246        attributes.setDark( this.isDark() );
247        return attributes;
248    }
249
250    /**
251     * @return string for debugging purposes.
252     */
253    @Override
254    public String toString()
255    {
256        final StringBuilder buf = new StringBuilder();
257        buf.append( "\n UDPDiscoveryAttributes" );
258        buf.append( "\n ServiceName = [" + getServiceName() + "]" );
259        buf.append( "\n ServiceAddress = [" + getServiceAddress() + "]" );
260        buf.append( "\n ServicePort = [" + getServicePort() + "]" );
261        buf.append( "\n UdpDiscoveryAddr = [" + getUdpDiscoveryAddr() + "]" );
262        buf.append( "\n UdpDiscoveryPort = [" + getUdpDiscoveryPort() + "]" );
263        buf.append( "\n SendDelaySec = [" + getSendDelaySec() + "]" );
264        buf.append( "\n MaxIdleTimeSec = [" + getMaxIdleTimeSec() + "]" );
265        buf.append( "\n IsDark = [" + isDark() + "]" );
266        return buf.toString();
267    }
268}