KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmanage > testapp > jsr160 > NotificationListenerTest


1 /**
2  * Copyright 2004-2005 jManage.org
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.jmanage.testapp.jsr160;
17
18 import javax.management.NotificationListener JavaDoc;
19 import javax.management.Notification JavaDoc;
20 import javax.management.MBeanServerConnection JavaDoc;
21 import javax.management.ObjectName JavaDoc;
22 import javax.management.remote.JMXConnectorFactory JavaDoc;
23 import javax.management.remote.JMXConnector JavaDoc;
24 import javax.management.remote.JMXServiceURL JavaDoc;
25
26 /**
27  *
28  * date: Feb 22, 2005
29  * @author Rakesh Kalra
30  */

31 public class NotificationListenerTest {
32
33     public static void main(String JavaDoc[] args)
34         throws Exception JavaDoc {
35
36         JMXServiceURL JavaDoc url = new JMXServiceURL JavaDoc("service:jmx:rmi:///jndi/rmi://localhost:9999/testApp");
37         JMXConnector JavaDoc jmxc = JMXConnectorFactory.connect(url, null);
38         MBeanServerConnection JavaDoc mbsc = jmxc.getMBeanServerConnection();
39         mbsc.addNotificationListener(
40                 new ObjectName JavaDoc("jmanage:name=TimeNotificationBroadcaster"),
41                 new MyNotificationListener(), null, null);
42
43         while(true){
44             try {
45                 Thread.sleep(100000);
46             } catch (InterruptedException JavaDoc e) {
47             }
48         }
49     }
50
51     public static class MyNotificationListener implements NotificationListener JavaDoc{
52
53         public void handleNotification(Notification JavaDoc notification,
54                                        Object JavaDoc bindVariables) {
55             System.out.println("Notification: type=" + notification.getType()
56                     + ", seq# " + notification.getSequenceNumber());
57         }
58     }
59 }
60
Popular Tags