1 21 22 package org.objectweb.jonas.discovery; 23 24 import javax.management.MBeanRegistration ; 25 import javax.management.MBeanServer ; 26 import javax.management.NotificationBroadcasterSupport ; 27 import javax.management.ObjectName ; 28 29 36 public class Enroller extends NotificationBroadcasterSupport 37 implements MBeanRegistration , EnrollerMBean { 38 39 42 private int listeningPort; 43 46 private String listeningIp = null; 47 50 private MBeanServer mbeanServer; 51 private ObjectName myOn; 52 55 private Thread discoveryListener = null; 56 60 private DiscoveryListener dl = null; 61 private int ttl =1; 62 63 public Enroller (int listeningPort, String listeningIp) { 64 this.listeningIp = listeningIp; 65 this.listeningPort = listeningPort; 66 } 67 68 72 public ObjectName preRegister(MBeanServer mbeanServer, ObjectName on) 73 throws Exception { 74 this.mbeanServer = mbeanServer; 75 this.myOn = on; 76 return myOn; 77 } 78 79 82 public void postRegister(Boolean arg0) { 83 start(); 84 } 85 86 90 public void preDeregister() throws Exception { 91 dl.stopListener(); 93 discoveryListener.interrupt(); 94 discoveryListener= null; 95 } 96 97 101 public void postDeregister() { 102 103 } 104 105 109 public int getListeningPort() { 110 return listeningPort; 111 } 112 113 117 public void setListeningPort(int listeningPort) { 118 this.listeningPort = listeningPort; 119 120 } 121 122 126 public String getListeningIp() { 127 return listeningIp; 128 } 129 130 134 public void setListeningIp(String listeningIp) { 135 this.listeningIp = listeningIp; 136 137 } 138 139 143 public void setTimeToLive(int ttl) { 144 this.ttl = ttl; 145 146 } 147 148 152 public int getTimeToLive() { 153 return ttl; 154 } 155 156 160 public void start() { 161 dl = new DiscoveryListener(this); 163 164 if (discoveryListener == null) 165 discoveryListener = new Thread (dl, "discoveryListener"); 166 discoveryListener.start(); 167 168 } 169 173 public void stop() { 174 dl.stopListener(); 175 } 176 } | Popular Tags |