KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > management > mejb > RMINotificationListener


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.management.mejb;
23
24 import org.jboss.logging.Logger;
25
26 import javax.management.Notification JavaDoc;
27 import java.rmi.RemoteException JavaDoc;
28
29 /**
30  * Notification Listener Implementation registered as
31  * MBean on the remote JMX Server and the added as
32  * Notification Listener on the remote JMX Server.
33  * Each notification received will be transfered to
34  * the remote client using RMI Callback Objects.
35  *
36  * @author <A HREF="mailto:andreas@jboss.org">Andreas Schaefer</A>
37  * @version $Revision: 37459 $
38  * @jmx:mbean extends="org.jboss.management.mejb.ListenerMBean"
39  */

40 public class RMINotificationListener
41         implements RMINotificationListenerMBean
42 {
43    private static final Logger log = Logger.getLogger(RMINotificationListener.class);
44
45    // -------------------------------------------------------------------------
46
// Members
47
// -------------------------------------------------------------------------
48

49    private RMIClientNotificationListenerInterface mClientListener;
50
51    // -------------------------------------------------------------------------
52
// Constructor
53
// -------------------------------------------------------------------------
54

55    /**
56     * Creates the RMI Notification Listener MBean implemenation which
57     * will be registered at the remote JMX Server as notificatin listener
58     * and then send the notification over the provided RMI Notification
59     * sender to the client
60     *
61     * @param pClientListener RMI-Stub used to transfer the Notification over
62     * the wire.
63     */

64    public RMINotificationListener(RMIClientNotificationListenerInterface pClientListener)
65    {
66       log.debug("RMINotificationListener(), client listener: " + pClientListener);
67       mClientListener = pClientListener;
68    }
69
70    // -------------------------------------------------------------------------
71
// Public Methods
72
// -------------------------------------------------------------------------
73

74    /**
75     * Handles the given notifcation event and passed it to the registered
76     * RMI Notification Sender
77     *
78     * @param pNotification NotificationEvent
79     * @param pHandback Handback object
80     */

81    public void handleNotification(Notification JavaDoc pNotification,
82                                   Object JavaDoc pHandback)
83    {
84       try
85       {
86          log.debug("RMINotificationListener.handleNotification() " +
87                  ", notification: " + pNotification +
88                  ", handback: " + pHandback +
89                  ", client listener: " + mClientListener);
90          mClientListener.handleNotification(pNotification, pHandback);
91       }
92       catch (RemoteException JavaDoc e)
93       {
94          throw new org.jboss.util.NestedRuntimeException(e);
95       }
96    }
97
98    /**
99     * Test if this and the given Object are equal. This is true if the given
100     * object both refer to the same local listener
101     *
102     * @param pTest Other object to test if equal
103     * @return True if both are of same type and
104     * refer to the same local listener
105     */

106    public boolean equals(Object JavaDoc pTest)
107    {
108       if (pTest instanceof RMINotificationListener)
109       {
110          return mClientListener.equals(((RMINotificationListener) pTest).mClientListener);
111       }
112       return false;
113    }
114
115    /**
116     * @return Hashcode of the remote listener
117     */

118    public int hashCode()
119    {
120       return mClientListener.hashCode();
121    }
122 }
123
Popular Tags