1 21 22 package org.objectweb.jonas.discovery; 23 24 import java.net.InetAddress ; 25 import java.net.UnknownHostException ; 26 27 import javax.management.MBeanRegistration ; 28 import javax.management.MBeanServer ; 29 import javax.management.NotificationBroadcasterSupport ; 30 import javax.management.ObjectName ; 31 32 import org.objectweb.jonas.common.Log; 33 import org.objectweb.jonas.common.NetUtils; 34 import org.objectweb.util.monolog.api.BasicLevel; 35 import org.objectweb.util.monolog.api.Logger; 36 37 45 public class DiscoveryClient extends NotificationBroadcasterSupport implements 46 DiscoveryClientMBean, 47 MBeanRegistration { 48 51 private int sourcePort; 52 55 private String sourceIp; 56 59 private MBeanServer mbeanServer; 60 63 private ObjectName myOn; 64 68 private DiscoveryClientListener dcl = null; 69 72 private Thread discoveryClientListener = null; 73 private int ttl = 1; 74 77 private int timeout = 1000; 78 private int listeningPort; 79 private String listeningIp; 80 private static Logger logger = Log.getLogger(Log.JONAS_DISCOVERY_PREFIX); 81 82 public DiscoveryClient(int listeningPort, String listeningIP, int sourcePort) { 83 this.listeningIp = listeningIP; 84 this.listeningPort = listeningPort; 85 this.sourcePort =sourcePort; 86 } 87 88 92 public int getTimeout() { 93 return timeout; 94 } 95 96 100 public void setTimeout(int timeout) { 101 this.timeout = timeout; 102 } 103 104 108 public int getListeningPort() { 109 return listeningPort; 110 } 111 112 116 public void setListeningPort(int listeningPort) { 117 this.listeningPort = listeningPort; 118 119 } 120 121 124 public String getListeningIp() { 125 return listeningIp; 126 } 127 128 132 public void setListeningIp(String ipAddress) { 133 this.listeningIp = ipAddress; 134 135 } 136 137 140 public int getSourcePort() { 141 return sourcePort; 142 } 143 144 147 public void setSourcePort(int sourcePort) { 148 this.sourcePort = sourcePort; 149 150 } 151 152 155 public String getSourceIp(){ 156 return sourceIp; 157 } 158 159 162 public int getTimeToLive() { 163 return ttl; 164 } 165 166 169 public void setSourceIp(String sourceIp) { 170 this.sourceIp = sourceIp; 171 172 } 173 174 178 public void setTimeToLive(int ttl) { 179 this.ttl = ttl; 180 181 } 182 183 187 public void start() { 188 try { 192 this.setSourceIp(NetUtils.getLocalAddress()); 193 } catch (UnknownHostException e) { 194 logger.log(BasicLevel.ERROR, "Unable to create a localhost.", e); 195 } 196 dcl = new DiscoveryClientListener(this); 197 198 if (discoveryClientListener == null) { 199 discoveryClientListener = new Thread (dcl, "discoveryClientListener"); 200 } 201 discoveryClientListener.start(); 202 203 } 204 205 public void stop() { 206 207 } 208 209 214 public ObjectName preRegister(MBeanServer mbeanServer, ObjectName on) { 215 this.mbeanServer = mbeanServer; 217 this.myOn = on; 218 219 return myOn; 220 } 221 222 226 public void postRegister(Boolean arg0) { 227 start(); 228 } 229 230 234 public void preDeregister() throws Exception { 235 dcl.stop(); 236 237 } 238 239 243 public void postDeregister() { 244 } 245 246 } | Popular Tags |