001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2004 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or modify it
007: * under the terms of the GNU Lesser General Public License as published by the
008: * Free Software Foundation; either version 2.1 of the License, or any later
009: * version.
010: *
011: * This library is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
014: * for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public License
017: * along with this library; if not, write to the Free Software Foundation,
018: * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
019: *
020: */package org.objectweb.jonas.discovery;
021:
022: import javax.management.MBeanRegistration;
023: import javax.management.MBeanServer;
024: import javax.management.ObjectName;
025:
026: /**
027: * In charge of waiting for starting or stopping notifications and notifies the
028: * appropriate listeners.
029: *
030: * @author <a href="mailto:Takoua.Abdellatif@inria.fr">Takoua Abdellatif </a>
031: * @version 1.0
032: */
033: public class Enroller implements MBeanRegistration, EnrollerMBean {
034:
035: /**
036: * <code>listeningPort</code> for multicast socket creation
037: */
038: private int listeningPort;
039: /**
040: * <code>listeningIp</code> for multicast socket creation
041: */
042: private String listeningIp = null;
043: private ObjectName myOn;
044: /**
045: * Thread associated to dl
046: */
047: private Thread discoveryListener = null;
048: /**
049: * Runnable object that listens on multicast address notifications sent
050: * by the servers in the management domain
051: */
052: private DiscoveryListener dl = null;
053: private int ttl = 1;
054:
055: public Enroller(int listeningPort, String listeningIp) {
056: this .listeningIp = listeningIp;
057: this .listeningPort = listeningPort;
058: }
059:
060: /**
061: * @see javax.management.MBeanRegistration#preRegister(javax.management.MBeanServer,
062: * javax.management.ObjectName)
063: */
064: public ObjectName preRegister(MBeanServer mbeanServer, ObjectName on)
065: throws Exception {
066: this .myOn = on;
067: return myOn;
068: }
069:
070: /**
071: * @see javax.management.MBeanRegistration#postRegister(java.lang.Boolean)
072: */
073: public void postRegister(Boolean arg0) {
074: start();
075: }
076:
077: /**
078: *
079: * @see javax.management.MBeanRegistration#preDeregister()
080: */
081: public void preDeregister() throws Exception {
082: // stop the listening thread
083: dl.stopListener();
084: discoveryListener.interrupt();
085: discoveryListener = null;
086: }
087:
088: /**
089: *
090: * @see javax.management.MBeanRegistration#postDeregister()
091: */
092: public void postDeregister() {
093:
094: }
095:
096: /**
097: *
098: * @see org.objectweb.jonas.server.discovery.EnrollerMBean#getListeningPort()
099: */
100: public int getListeningPort() {
101: return listeningPort;
102: }
103:
104: /**
105: *
106: * @see org.objectweb.jonas.server.discovery.EnrollerMBean#setListeningPort(int)
107: */
108: public void setListeningPort(int listeningPort) {
109: this .listeningPort = listeningPort;
110:
111: }
112:
113: /**
114: *
115: * @see org.objectweb.jonas.server.discovery.EnrollerMBean#getListeningIp()
116: */
117: public String getListeningIp() {
118: return listeningIp;
119: }
120:
121: /**
122: *
123: * @see org.objectweb.jonas.server.discovery.EnrollerMBean#setListeningIP(java.lang.String)
124: */
125: public void setListeningIp(String listeningIp) {
126: this .listeningIp = listeningIp;
127:
128: }
129:
130: /**
131: *
132: * @see org.objectweb.jonas.server.discovery.EnrollerMBean#setTimeToLive(int)
133: */
134: public void setTimeToLive(int ttl) {
135: this .ttl = ttl;
136:
137: }
138:
139: /**
140: *
141: * @see org.objectweb.jonas.server.discovery.EnrollerMBean#getTimeToLive()
142: */
143: public int getTimeToLive() {
144: return ttl;
145: }
146:
147: /**
148: *
149: * @see org.objectweb.jonas.server.discovery.EnrollerMBean#start()
150: */
151: public void start() {
152: // creates an instance of the Discovery communication class
153: dl = new DiscoveryListener(this );
154:
155: if (discoveryListener == null)
156: discoveryListener = new Thread(dl, "discoveryListener");
157: discoveryListener.start();
158:
159: }
160:
161: /**
162: *
163: * @see org.objectweb.jonas.server.discovery.EnrollerMBean#start()
164: */
165: public void stop() {
166: dl.stopListener();
167: }
168:
169: }
|