KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mx4j > tools > remote > http > HTTPServerInvoker


1 /*
2  * Copyright (C) The MX4J Contributors.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the MX4J License version 1.0.
6  * See the terms of the MX4J License in the documentation provided with this software.
7  */

8
9 package mx4j.tools.remote.http;
10
11 import java.io.IOException JavaDoc;
12 import javax.management.InstanceNotFoundException JavaDoc;
13 import javax.management.ListenerNotFoundException JavaDoc;
14 import javax.management.MBeanServerConnection JavaDoc;
15 import javax.management.NotificationListener JavaDoc;
16 import javax.management.ObjectName JavaDoc;
17 import javax.management.remote.NotificationResult JavaDoc;
18 import javax.security.auth.Subject JavaDoc;
19
20 import mx4j.remote.NotificationTuple;
21 import mx4j.remote.RemoteNotificationServerHandler;
22 import mx4j.tools.remote.AbstractServerInvoker;
23
24 /**
25  * Implementation of the HTTPConnector interface that forwards the calls
26  * to an MBeanServerConnection object.
27  * It handles remote notifications, but it does not handle unmarshalling of
28  * arguments (and all related classloading problems).
29  *
30  * @version $Revision: 1.3 $
31  */

32 public class HTTPServerInvoker extends AbstractServerInvoker implements HTTPConnection
33 {
34    private final RemoteNotificationServerHandler notificationHandler;
35
36    public HTTPServerInvoker(MBeanServerConnection JavaDoc server, RemoteNotificationServerHandler handler)
37    {
38       super(server);
39       this.notificationHandler = handler;
40    }
41
42    public String JavaDoc connect(Object JavaDoc credentials) throws IOException JavaDoc, SecurityException JavaDoc
43    {
44       return null;
45    }
46
47    public void close() throws IOException JavaDoc
48    {
49       NotificationTuple[] tuples = notificationHandler.close();
50       for (int i = 0; i < tuples.length; ++i)
51       {
52          NotificationTuple tuple = tuples[i];
53          try
54          {
55             getServer().removeNotificationListener(tuple.getObjectName(), tuple.getNotificationListener(), tuple.getNotificationFilter(), tuple.getHandback());
56          }
57          catch (InstanceNotFoundException JavaDoc ignored)
58          {
59          }
60          catch (ListenerNotFoundException JavaDoc ignored)
61          {
62          }
63       }
64    }
65
66    public Integer JavaDoc addNotificationListener(ObjectName JavaDoc name, Object JavaDoc filter, Subject JavaDoc delegate) throws InstanceNotFoundException JavaDoc, IOException JavaDoc
67    {
68       Integer JavaDoc id = notificationHandler.generateListenerID(name, null);
69       NotificationListener JavaDoc listener = notificationHandler.getServerNotificationListener();
70       getServer().addNotificationListener(name, listener, null, id);
71       notificationHandler.addNotificationListener(id, new NotificationTuple(name, listener, null, id));
72       return id;
73    }
74
75    public void removeNotificationListeners(ObjectName JavaDoc name, Integer JavaDoc[] listenerIDs, Subject JavaDoc delegate) throws InstanceNotFoundException JavaDoc, ListenerNotFoundException JavaDoc, IOException JavaDoc
76    {
77       for (int i = 0; i < listenerIDs.length; ++i)
78       {
79          Integer JavaDoc id = listenerIDs[i];
80          NotificationTuple tuple = notificationHandler.removeNotificationListener(id);
81          getServer().removeNotificationListener(name, tuple.getNotificationListener(), tuple.getNotificationFilter(), tuple.getHandback());
82       }
83    }
84
85    public NotificationResult JavaDoc fetchNotifications(long clientSequenceNumber, int maxNotifications, long timeout) throws IOException JavaDoc
86    {
87       return notificationHandler.fetchNotifications(clientSequenceNumber, maxNotifications, timeout);
88    }
89 }
90
Popular Tags