View Javadoc
1   package org.apache.commons.jcs.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   * @author Aaron Smuts
28   */
29  public final class UDPDiscoveryAttributes
30      implements Cloneable
31  {
32      /** service name */
33      private String serviceName;
34  
35      /** service address */
36      private String serviceAddress;
37  
38      /** service port */
39      private int servicePort;
40  
41      /**
42       * false -> this service instance is not ready to receive requests. true -> ready for use
43       */
44      private boolean isDark;
45  
46      /** default udp discovery address */
47      private static final String DEFAULT_UDP_DISCOVERY_ADDRESS = "228.4.5.6";
48  
49      /** default udp discovery port */
50      private static final int DEFAULT_UDP_DISCOVERY_PORT = 5678;
51  
52      /** udp discovery address */
53      private String udpDiscoveryAddr = DEFAULT_UDP_DISCOVERY_ADDRESS;
54  
55      /** udp discovery port */
56      private int udpDiscoveryPort = DEFAULT_UDP_DISCOVERY_PORT;
57  
58      /** default delay between sending passive broadcasts */
59      private static final int DEFAULT_SEND_DELAY_SEC = 60;
60  
61      /** delay between sending passive broadcasts */
62      private int sendDelaySec = DEFAULT_SEND_DELAY_SEC;
63  
64      /** default amount of time before we remove services that we haven't heard from */
65      private static final int DEFAULT_MAX_IDLE_TIME_SEC = 180;
66  
67      /** amount of time before we remove services that we haven't heard from */
68      private int maxIdleTimeSec = DEFAULT_MAX_IDLE_TIME_SEC;
69  
70      /**
71       * @param serviceName The serviceName to set.
72       */
73      public void setServiceName( String serviceName )
74      {
75          this.serviceName = serviceName;
76      }
77  
78      /**
79       * @return Returns the serviceName.
80       */
81      public String getServiceName()
82      {
83          return serviceName;
84      }
85  
86      /**
87       * @param serviceAddress The serviceAddress to set.
88       */
89      public void setServiceAddress( String serviceAddress )
90      {
91          this.serviceAddress = serviceAddress;
92      }
93  
94      /**
95       * @return Returns the serviceAddress.
96       */
97      public String getServiceAddress()
98      {
99          return serviceAddress;
100     }
101 
102     /**
103      * @param servicePort The servicePort to set.
104      */
105     public void setServicePort( int servicePort )
106     {
107         this.servicePort = servicePort;
108     }
109 
110     /**
111      * @return Returns the servicePort.
112      */
113     public int getServicePort()
114     {
115         return servicePort;
116     }
117 
118     /**
119      * @param udpDiscoveryAddr The udpDiscoveryAddr to set.
120      */
121     public void setUdpDiscoveryAddr( String udpDiscoveryAddr )
122     {
123         this.udpDiscoveryAddr = udpDiscoveryAddr;
124     }
125 
126     /**
127      * @return Returns the udpDiscoveryAddr.
128      */
129     public String getUdpDiscoveryAddr()
130     {
131         return udpDiscoveryAddr;
132     }
133 
134     /**
135      * @param udpDiscoveryPort The udpDiscoveryPort to set.
136      */
137     public void setUdpDiscoveryPort( int udpDiscoveryPort )
138     {
139         this.udpDiscoveryPort = udpDiscoveryPort;
140     }
141 
142     /**
143      * @return Returns the udpDiscoveryPort.
144      */
145     public int getUdpDiscoveryPort()
146     {
147         return udpDiscoveryPort;
148     }
149 
150     /**
151      * @param sendDelaySec The sendDelaySec to set.
152      */
153     public void setSendDelaySec( int sendDelaySec )
154     {
155         this.sendDelaySec = sendDelaySec;
156     }
157 
158     /**
159      * @return Returns the sendDelaySec.
160      */
161     public int getSendDelaySec()
162     {
163         return sendDelaySec;
164     }
165 
166     /**
167      * @param maxIdleTimeSec The maxIdleTimeSec to set.
168      */
169     public void setMaxIdleTimeSec( int maxIdleTimeSec )
170     {
171         this.maxIdleTimeSec = maxIdleTimeSec;
172     }
173 
174     /**
175      * @return Returns the maxIdleTimeSec.
176      */
177     public int getMaxIdleTimeSec()
178     {
179         return maxIdleTimeSec;
180     }
181 
182     /**
183      * @return Returns the isDark.
184      */
185     public boolean isDark()
186     {
187         return isDark;
188     }
189 
190     /**
191      * @param isDark The isDark to set.
192      */
193     public void setDark( boolean isDark )
194     {
195         this.isDark = isDark;
196     }
197 
198     /** @return a clone of this object */
199     @Override
200     public UDPDiscoveryAttributes clone()
201     {
202         UDPDiscoveryAttributes attributes = new UDPDiscoveryAttributes();
203         attributes.setSendDelaySec( this.getSendDelaySec() );
204         attributes.setMaxIdleTimeSec( this.getMaxIdleTimeSec() );
205         attributes.setServiceName( this.getServiceName() );
206         attributes.setServicePort( this.getServicePort() );
207         attributes.setUdpDiscoveryAddr( this.getUdpDiscoveryAddr() );
208         attributes.setUdpDiscoveryPort( this.getUdpDiscoveryPort() );
209         attributes.setDark( this.isDark() );
210         return attributes;
211     }
212 
213     /**
214      * @return string for debugging purposes.
215      */
216     @Override
217     public String toString()
218     {
219         StringBuilder buf = new StringBuilder();
220         buf.append( "\n UDPDiscoveryAttributes" );
221         buf.append( "\n ServiceName = [" + getServiceName() + "]" );
222         buf.append( "\n ServiceAddress = [" + getServiceAddress() + "]" );
223         buf.append( "\n ServicePort = [" + getServicePort() + "]" );
224         buf.append( "\n UdpDiscoveryAddr = [" + getUdpDiscoveryAddr() + "]" );
225         buf.append( "\n UdpDiscoveryPort = [" + getUdpDiscoveryPort() + "]" );
226         buf.append( "\n SendDelaySec = [" + getSendDelaySec() + "]" );
227         buf.append( "\n MaxIdleTimeSec = [" + getMaxIdleTimeSec() + "]" );
228         buf.append( "\n IsDark = [" + isDark() + "]" );
229         return buf.toString();
230     }
231 }