org/objectweb/proactive/jmx/listeners/ProActiveConnectionNotificationEmitter.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
00028  * 
00029  * ################################################################
00030  */ 
00031 package org.objectweb.proactive.jmx.listeners;
00032 
00033 import java.io.IOException;
00034 
00035 import javax.management.NotificationBroadcasterSupport;
00036 import javax.management.remote.JMXConnectionNotification;
00037 
00038 import org.objectweb.proactive.jmx.server.ProActiveConnector;
00039 
00040 
00047 public class ProActiveConnectionNotificationEmitter
00048     extends NotificationBroadcasterSupport {
00049     private static long sequenceNumber;
00050     private ProActiveConnector connector;
00051 
00056     public ProActiveConnectionNotificationEmitter(ProActiveConnector connector) {
00057         this.connector = connector;
00058         addNotificationListener(connector, null, null);
00059     }
00060 
00064     public void sendConnectionNotificationOpened() {
00065         JMXConnectionNotification notification = new JMXConnectionNotification(JMXConnectionNotification.OPENED,
00066                 connector, getConnectionId(), getNextNotificationNumber(),
00067                 "Connection opened", null);
00068         sendNotification(notification);
00069     }
00070 
00074     public void sendConnectionNotificationClosed() {
00075         JMXConnectionNotification notification = new JMXConnectionNotification(JMXConnectionNotification.CLOSED,
00076                 connector, getConnectionId(), getNextNotificationNumber(),
00077                 "Connection closed", null);
00078         sendNotification(notification);
00079     }
00080 
00084     public void sendConnectionNotificationFailed() {
00085         JMXConnectionNotification notification = new JMXConnectionNotification(JMXConnectionNotification.FAILED,
00086                 connector, getConnectionId(), getNextNotificationNumber(),
00087                 "Connection failed", null);
00088         sendNotification(notification);
00089     }
00090 
00091     private long getNextNotificationNumber() {
00092         synchronized (ProActiveConnectionNotificationEmitter.class) {
00093             return sequenceNumber++;
00094         }
00095     }
00096 
00097     private String getConnectionId() {
00098         try {
00099             return connector.getConnectionId();
00100         } catch (IOException x) {
00101             return null;
00102         }
00103     }
00104 }

Generated on Mon Jan 22 15:16:11 2007 for ProActive by  doxygen 1.5.1