01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * 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;
25: import javax.management.Notification;
26: import javax.management.NotificationFilter;
27: import javax.management.NotificationListener;
28: import javax.management.ObjectName;
29: import java.rmi.RemoteException;
30: import java.util.Iterator;
31: import java.util.List;
32:
33: /**
34: * Local Polling Listener to receive the message and send to the listener
35: *
36: * @author Andreas Schaefer
37: * @version $Revision: 57197 $
38: */
39: public class PollingClientNotificationListener extends
40: ClientNotificationListener implements Runnable {
41:
42: private MEJB mConnector;
43: private int mSleepingPeriod = 2000;
44:
45: public PollingClientNotificationListener(ObjectName pSender,
46: NotificationListener pClientListener, Object pHandback,
47: NotificationFilter pFilter, int pSleepingPeriod,
48: int pMaximumListSize, MEJB pConnector) throws JMException,
49: RemoteException {
50: super (pSender, pClientListener, pHandback);
51: if (pSleepingPeriod > 0) {
52: mSleepingPeriod = pSleepingPeriod;
53: }
54: mConnector = pConnector;
55: // Register the listener as MBean on the remote JMX server
56: createListener(
57: pConnector,
58: "org.jboss.management.mejb.PollingNotificationListener",
59: new Object[] { new Integer(pMaximumListSize),
60: new Integer(pMaximumListSize) },
61: new String[] { Integer.TYPE.getName(),
62: Integer.TYPE.getName() });
63: addNotificationListener(pConnector, pFilter);
64: new Thread(this ).start();
65: }
66:
67: public void run() {
68: while (true) {
69: try {
70: try {
71: List lNotifications = (List) mConnector.invoke(
72: getRemoteListenerName(),
73: "getNotifications", new Object[] {},
74: new String[] {});
75: Iterator i = lNotifications.iterator();
76: while (i.hasNext()) {
77: Notification lNotification = (Notification) i
78: .next();
79: mClientListener.handleNotification(
80: lNotification, mHandback);
81: }
82: } catch (Exception e) {
83: log
84: .error(
85: "PollingClientNotificationListener.getNotifications() failed",
86: e);
87: }
88: Thread.sleep(mSleepingPeriod);
89: } catch (InterruptedException e) {
90: }
91: }
92: }
93: }
|