KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > mx > notification > MBeanServerListenerRegistration


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.mx.notification;
23
24 import javax.management.ListenerNotFoundException JavaDoc;
25 import javax.management.NotificationBroadcaster JavaDoc;
26 import javax.management.NotificationEmitter JavaDoc;
27 import javax.management.NotificationFilter JavaDoc;
28 import javax.management.NotificationListener JavaDoc;
29 import javax.management.ObjectName JavaDoc;
30
31 /**
32  * The notification listener registration for a listener in
33  * the mbeanserver. The listener is proxied so we can
34  * replace the source of the notification with the object name.<p>
35  *
36  * We also handle the registration with the broadcaster.
37  *
38  * @see org.jboss.mx.notification.ListenerRegistry
39  * @see org.jboss.mx.notification.ListenerRegistrationFactory
40  *
41  * @author <a HREF="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>.
42  * @version $Revision: 37459 $
43  */

44 public class MBeanServerListenerRegistration
45    extends DefaultListenerRegistration
46 {
47    // Attributes ----------------------------------------------------
48

49    /**
50     * The notification listener proxy
51     */

52    private NotificationListener JavaDoc proxy;
53
54    private NotificationFilter JavaDoc filterProxy;
55
56    /**
57     * The notification broadcaster
58     */

59    private NotificationBroadcaster JavaDoc broadcaster;
60
61    // Constructor ---------------------------------------------------
62

63    /**
64     * Create a listener registration
65     *
66     * @param name the object name to use as the notifiation source
67     * @param broadcaster the notification broadcaster
68     * @param listener the notification listener
69     * @param filter the notification filter
70     * @param handback the handback object a
71     */

72    public MBeanServerListenerRegistration(ObjectName JavaDoc name,
73                                           NotificationBroadcaster JavaDoc broadcaster,
74                                           NotificationListener JavaDoc listener,
75                                           NotificationFilter JavaDoc filter,
76                                           Object JavaDoc handback)
77    {
78        super(listener, filter, handback);
79        proxy = (NotificationListener JavaDoc) NotificationListenerProxy.newInstance(name, listener);
80        this.broadcaster = broadcaster;
81        this.filterProxy = (filter==null) ? null : new NotificationFilterProxy(name,filter);
82        broadcaster.addNotificationListener(proxy, filterProxy, handback);
83    }
84
85    // Public --------------------------------------------------------
86

87    // ListenerRegistration Implementation ---------------------------
88

89    public NotificationListener JavaDoc getListener()
90    {
91       return proxy;
92    }
93
94     public NotificationFilter JavaDoc getFilter()
95     {
96         return filterProxy;
97     }
98
99    public void removed()
100    {
101       try
102       {
103          if (broadcaster instanceof NotificationEmitter JavaDoc)
104             ((NotificationEmitter JavaDoc) broadcaster).removeNotificationListener(getListener(), getFilter(), getHandback());
105          else
106             broadcaster.removeNotificationListener(getListener());
107       }
108       catch (ListenerNotFoundException JavaDoc ignored)
109       {
110       }
111    }
112 }
113
Popular Tags