KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > discovery > Enroller


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2004 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published by the
8  * Free Software Foundation; either version 2.1 of the License, or any later
9  * version.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14  * for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19  *
20  */

21
22 package org.objectweb.jonas.discovery;
23
24 import javax.management.MBeanRegistration JavaDoc;
25 import javax.management.MBeanServer JavaDoc;
26 import javax.management.NotificationBroadcasterSupport JavaDoc;
27 import javax.management.ObjectName JavaDoc;
28
29 /**
30  * In charge of waiting for starting or stopping notifications and notifies the
31  * appropriate listeners.
32  *
33  * @author <a HREF="mailto:Takoua.Abdellatif@inria.fr">Takoua Abdellatif </a>
34  * @version 1.0
35  */

36 public class Enroller extends NotificationBroadcasterSupport JavaDoc
37     implements MBeanRegistration JavaDoc, EnrollerMBean {
38
39     /**
40      * <code>listeningPort</code> for multicast socket creation
41      */

42     private int listeningPort;
43     /**
44      * <code>listeningIp</code> for multicast socket creation
45      */

46     private String JavaDoc listeningIp = null;
47     /**
48      * Current MBean Server
49      */

50     private MBeanServer JavaDoc mbeanServer;
51     private ObjectName JavaDoc myOn;
52     /**
53      * Thread associated to dl
54      */

55     private Thread JavaDoc discoveryListener = null;
56     /**
57      * Runnable object that listens on multicast address notifications sent
58      * by the servers in the management domain
59      */

60     private DiscoveryListener dl = null;
61     private int ttl =1;
62
63     public Enroller (int listeningPort, String JavaDoc listeningIp) {
64       this.listeningIp = listeningIp;
65       this.listeningPort = listeningPort;
66     }
67
68     /**
69      * @see javax.management.MBeanRegistration#preRegister(javax.management.MBeanServer,
70      * javax.management.ObjectName)
71      */

72     public ObjectName JavaDoc preRegister(MBeanServer JavaDoc mbeanServer, ObjectName JavaDoc on)
73     throws Exception JavaDoc {
74         this.mbeanServer = mbeanServer;
75         this.myOn = on;
76         return myOn;
77     }
78
79     /**
80      * @see javax.management.MBeanRegistration#postRegister(java.lang.Boolean)
81      */

82     public void postRegister(Boolean JavaDoc arg0) {
83         start();
84     }
85
86     /**
87      *
88      * @see javax.management.MBeanRegistration#preDeregister()
89      */

90     public void preDeregister() throws Exception JavaDoc {
91         // stop the listening thread
92
dl.stopListener();
93         discoveryListener.interrupt();
94         discoveryListener= null;
95     }
96
97     /**
98      *
99      * @see javax.management.MBeanRegistration#postDeregister()
100      */

101     public void postDeregister() {
102
103     }
104
105     /**
106      *
107      * @see org.objectweb.jonas.server.discovery.EnrollerMBean#getListeningPort()
108      */

109     public int getListeningPort() {
110         return listeningPort;
111     }
112
113     /**
114      *
115      * @see org.objectweb.jonas.server.discovery.EnrollerMBean#setListeningPort(int)
116      */

117     public void setListeningPort(int listeningPort) {
118         this.listeningPort = listeningPort;
119
120     }
121
122     /**
123      *
124      * @see org.objectweb.jonas.server.discovery.EnrollerMBean#getListeningIp()
125      */

126     public String JavaDoc getListeningIp() {
127         return listeningIp;
128     }
129
130     /**
131      *
132      * @see org.objectweb.jonas.server.discovery.EnrollerMBean#setListeningIP(java.lang.String)
133      */

134     public void setListeningIp(String JavaDoc listeningIp) {
135         this.listeningIp = listeningIp;
136
137     }
138
139     /**
140      *
141      * @see org.objectweb.jonas.server.discovery.EnrollerMBean#setTimeToLive(int)
142      */

143     public void setTimeToLive(int ttl) {
144         this.ttl = ttl;
145
146     }
147
148     /**
149      *
150      * @see org.objectweb.jonas.server.discovery.EnrollerMBean#getTimeToLive()
151      */

152     public int getTimeToLive() {
153         return ttl;
154     }
155
156     /**
157      *
158      * @see org.objectweb.jonas.server.discovery.EnrollerMBean#start()
159      */

160     public void start() {
161         // creates an instance of the Discovery communication class
162
dl = new DiscoveryListener(this);
163
164         if (discoveryListener == null)
165             discoveryListener = new Thread JavaDoc(dl, "discoveryListener");
166         discoveryListener.start();
167
168     }
169     /**
170     *
171     * @see org.objectweb.jonas.server.discovery.EnrollerMBean#start()
172     */

173    public void stop() {
174        dl.stopListener();
175    }
176 }
Popular Tags