KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.management.JMException JavaDoc;
25 import javax.management.Notification JavaDoc;
26 import javax.management.NotificationFilter JavaDoc;
27 import javax.management.NotificationListener JavaDoc;
28 import javax.management.ObjectName JavaDoc;
29 import java.rmi.Remote JavaDoc;
30 import java.rmi.RemoteException JavaDoc;
31 import java.rmi.server.UnicastRemoteObject JavaDoc;
32
33 /**
34  * Client-side RMI Listener to receive the message and send to the
35  * clients listener. Its stub is used on the server-side to hand
36  * the Notifications over to this class.
37  *
38  * @author <A HREF="mailto:andreas@jboss.org">Andreas &quot;Mad&quot; Schaefer</A>
39  */

40 public class RMIClientNotificationListener
41         extends ClientNotificationListener
42         implements RMIClientNotificationListenerInterface
43 {
44
45    public RMIClientNotificationListener(ObjectName JavaDoc pSender,
46                                         NotificationListener JavaDoc pClientListener,
47                                         Object JavaDoc pHandback,
48                                         NotificationFilter JavaDoc pFilter,
49                                         MEJB pConnector)
50            throws RemoteException JavaDoc,
51            JMException JavaDoc
52    {
53       super(pSender, pClientListener, pHandback);
54       // Export the RMI object to become a callback object
55
Remote JavaDoc lStub = UnicastRemoteObject.exportObject(this);
56       // Register the listener as MBean on the remote JMX server
57
createListener(pConnector,
58               "org.jboss.management.mejb.RMINotificationListener",
59               new Object JavaDoc[]{lStub},
60               new String JavaDoc[]{RMIClientNotificationListenerInterface.class.getName()});
61       addNotificationListener(pConnector, pFilter);
62    }
63
64    /**
65     * Handles the given notification by sending this to the remote
66     * client listener
67     *
68     * @param pNotification Notification to be send
69     * @param pHandback Handback object
70     */

71    public void handleNotification(Notification JavaDoc pNotification,
72                                   Object JavaDoc pHandback)
73            throws RemoteException JavaDoc
74    {
75       try
76       {
77          mClientListener.handleNotification(pNotification,
78                  mHandback);
79       }
80       catch (RuntimeException JavaDoc re)
81       {
82          throw new RemoteException JavaDoc("Exceptions returned by the client listener", re);
83       }
84       catch (Error JavaDoc e)
85       {
86          throw new RemoteException JavaDoc("Error returned by the client listener", e);
87       }
88    }
89 }
90
Popular Tags