View Javadoc
1   package org.apache.commons.jcs3.utils.discovery;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  /**
23   * Configuration properties for UDP discover service.
24   * <p>
25   * The service will allow out applications to find each other.
26   * </p>
27   */
28  public final class UDPDiscoveryAttributes
29      implements Cloneable
30  {
31      /** service name */
32      private String serviceName;
33  
34      /** service address */
35      private String serviceAddress;
36  
37      /** service port */
38      private int servicePort;
39  
40      /**
41       * false -> this service instance is not ready to receive requests. true -> ready for use
42       */
43      private boolean isDark;
44  
45      /** default udp discovery address */
46      private static final String DEFAULT_UDP_DISCOVERY_ADDRESS = "228.4.5.6";
47  
48      /** default udp discovery port */
49      private static final int DEFAULT_UDP_DISCOVERY_PORT = 5678;
50  
51      /** udp discovery address */
52      private String udpDiscoveryAddr = DEFAULT_UDP_DISCOVERY_ADDRESS;
53  
54      /** udp discovery network interface */
55      private String udpDiscoveryInterface;
56  
57      /** udp discovery port */
58      private int udpDiscoveryPort = DEFAULT_UDP_DISCOVERY_PORT;
59  
60      /** udp datagram TTL */
61      private int udpTTL;
62  
63      /** default delay between sending passive broadcasts */
64      private static final int DEFAULT_SEND_DELAY_SEC = 60;
65  
66      /** delay between sending passive broadcasts */
67      private int sendDelaySec = DEFAULT_SEND_DELAY_SEC;
68  
69      /** default amount of time before we remove services that we haven't heard from */
70      private static final int DEFAULT_MAX_IDLE_TIME_SEC = 180;
71  
72      /** amount of time before we remove services that we haven't heard from */
73      private int maxIdleTimeSec = DEFAULT_MAX_IDLE_TIME_SEC;
74  
75      /**
76       * @param serviceName The serviceName to set.
77       */
78      public void setServiceName( final String serviceName )
79      {
80          this.serviceName = serviceName;
81      }
82  
83      /**
84       * @return Returns the serviceName.
85       */
86      public String getServiceName()
87      {
88          return serviceName;
89      }
90  
91      /**
92       * @param serviceAddress The serviceAddress to set.
93       */
94      public void setServiceAddress( final String serviceAddress )
95      {
96          this.serviceAddress = serviceAddress;
97      }
98  
99      /**
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 }