001package org.apache.commons.jcs.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 * @author Aaron Smuts 028 */ 029public final class UDPDiscoveryAttributes 030 implements Cloneable 031{ 032 /** service name */ 033 private String serviceName; 034 035 /** service address */ 036 private String serviceAddress; 037 038 /** service port */ 039 private int servicePort; 040 041 /** 042 * false -> this service instance is not ready to receive requests. true -> ready for use 043 */ 044 private boolean isDark; 045 046 /** default udp discovery address */ 047 private static final String DEFAULT_UDP_DISCOVERY_ADDRESS = "228.4.5.6"; 048 049 /** default udp discovery port */ 050 private static final int DEFAULT_UDP_DISCOVERY_PORT = 5678; 051 052 /** udp discovery address */ 053 private String udpDiscoveryAddr = DEFAULT_UDP_DISCOVERY_ADDRESS; 054 055 /** udp discovery port */ 056 private int udpDiscoveryPort = DEFAULT_UDP_DISCOVERY_PORT; 057 058 /** default delay between sending passive broadcasts */ 059 private static final int DEFAULT_SEND_DELAY_SEC = 60; 060 061 /** delay between sending passive broadcasts */ 062 private int sendDelaySec = DEFAULT_SEND_DELAY_SEC; 063 064 /** default amount of time before we remove services that we haven't heard from */ 065 private static final int DEFAULT_MAX_IDLE_TIME_SEC = 180; 066 067 /** amount of time before we remove services that we haven't heard from */ 068 private int maxIdleTimeSec = DEFAULT_MAX_IDLE_TIME_SEC; 069 070 /** 071 * @param serviceName The serviceName to set. 072 */ 073 public void setServiceName( String serviceName ) 074 { 075 this.serviceName = serviceName; 076 } 077 078 /** 079 * @return Returns the serviceName. 080 */ 081 public String getServiceName() 082 { 083 return serviceName; 084 } 085 086 /** 087 * @param serviceAddress The serviceAddress to set. 088 */ 089 public void setServiceAddress( String serviceAddress ) 090 { 091 this.serviceAddress = serviceAddress; 092 } 093 094 /** 095 * @return Returns the serviceAddress. 096 */ 097 public String getServiceAddress() 098 { 099 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}