00001
00022 package org.objectweb.jonas.discovery;
00023
00024 import java.net.InetAddress;
00025 import java.net.UnknownHostException;
00026
00027 import javax.management.MBeanRegistration;
00028 import javax.management.MBeanServer;
00029 import javax.management.NotificationBroadcasterSupport;
00030 import javax.management.ObjectName;
00031
00032 import org.objectweb.jonas.common.Log;
00033 import org.objectweb.util.monolog.api.BasicLevel;
00034 import org.objectweb.util.monolog.api.Logger;
00035
00044 public class DiscoveryClient extends NotificationBroadcasterSupport implements
00045 DiscoveryClientMBean,
00046 MBeanRegistration {
00050 private int sourcePort;
00054 private String sourceIp;
00058 private MBeanServer mbeanServer;
00062 private ObjectName myOn;
00067 private DiscoveryClientListener dcl = null;
00071 private Thread discoveryClientListener = null;
00072 private int ttl = 1;
00076 private int timeout = 1000;
00077 private int listeningPort;
00078 private String listeningIp;
00079 private static Logger logger = Log.getLogger(Log.JONAS_DISCOVERY_PREFIX);
00080
00081 public DiscoveryClient(int listeningPort, String listeningIP, int sourcePort) {
00082 this.listeningIp = listeningIP;
00083 this.listeningPort = listeningPort;
00084 this.sourcePort =sourcePort;
00085 }
00086
00091 public int getTimeout() {
00092 return timeout;
00093 }
00094
00099 public void setTimeout(int timeout) {
00100 this.timeout = timeout;
00101 }
00102
00107 public int getListeningPort() {
00108 return listeningPort;
00109 }
00110
00115 public void setListeningPort(int listeningPort) {
00116 this.listeningPort = listeningPort;
00117
00118 }
00119
00123 public String getListeningIp() {
00124 return listeningIp;
00125 }
00126
00131 public void setListeningIp(String ipAddress) {
00132 this.listeningIp = ipAddress;
00133
00134 }
00135
00139 public int getSourcePort() {
00140 return sourcePort;
00141 }
00142
00146 public void setSourcePort(int sourcePort) {
00147 this.sourcePort = sourcePort;
00148
00149 }
00150
00154 public String getSourceIp(){
00155 return sourceIp;
00156 }
00157
00161 public int getTimeToLive() {
00162 return ttl;
00163 }
00164
00168 public void setSourceIp(String sourceIp) {
00169 this.sourceIp = sourceIp;
00170
00171 }
00172
00177 public void setTimeToLive(int ttl) {
00178 this.ttl = ttl;
00179
00180 }
00181
00186 public void start() {
00187
00188
00189
00190 try {
00191 this.setSourceIp(InetAddress.getLocalHost().getHostName());
00192 } catch (UnknownHostException e) {
00193 logger.log(BasicLevel.ERROR, "Unable to create a localhost.");
00194 e.printStackTrace();
00195 }
00196 dcl = new DiscoveryClientListener(this);
00197
00198 if (discoveryClientListener == null) {
00199 discoveryClientListener = new Thread(dcl, "discoveryClientListener");
00200 }
00201 discoveryClientListener.start();
00202
00203 }
00204
00205 public void stop() {
00206
00207 }
00208
00214 public ObjectName preRegister(MBeanServer mbeanServer, ObjectName on) {
00215
00216 this.mbeanServer = mbeanServer;
00217 this.myOn = on;
00218
00219 return myOn;
00220 }
00221
00226 public void postRegister(Boolean arg0) {
00227 start();
00228 }
00229
00234 public void preDeregister() throws Exception {
00235 dcl.stop();
00236
00237 }
00238
00243 public void postDeregister() {
00244 }
00245
00246 }