User: schaefera
  Date: 01/09/11 18:49:07

  Added:       src/main/org/jboss/jmx/connector/notification
                        JMSNotificationListener.java
                        RMINotificationListener.java
                        RMINotificationListenerMBean.java
                        RMINotificationSender.java
  Log:
  Repackaged the JMX Connector and Adaptor for JBoss. I also added
  a new EJB-Adaptor and EJB-Connector. The adaptor allows a secured
  access to a local/remote JMX Server and the EJB-Connector makes
  this transparent for any Java client.
  
  Revision  Changes    Path
  1.1                  
jboss/src/main/org/jboss/jmx/connector/notification/JMSNotificationListener.java
  
  Index: JMSNotificationListener.java
  ===================================================================
  /*
  * JBoss, the OpenSource J2EE webOS
  *
  * Distributable under LGPL license.
  * See terms of license at gnu.org.
  */
  package org.jboss.jmx.connector.notification;
  
  import java.io.Serializable;
  
  import javax.jms.JMSException;
  import javax.jms.Message;
  import javax.jms.MessageListener;
  import javax.jms.ObjectMessage;
  import javax.jms.Queue;
  import javax.jms.QueueConnection;
  import javax.jms.QueueConnectionFactory;
  import javax.jms.QueueReceiver;
  import javax.jms.QueueSender;
  import javax.jms.QueueSession;
  import javax.jms.Session;
  
  import javax.management.Notification;
  import javax.management.NotificationListener;
  
  import javax.naming.Context;
  import javax.naming.InitialContext;
  import javax.naming.NamingException;
  import javax.rmi.PortableRemoteObject;
  
  /**
  * Remote Listener using JMS to send the event
  **/
  public class JMSNotificationListener
     implements NotificationListener, Serializable
  {
  
     private transient QueueSender mSender;
     private transient QueueSession mSession;
     private String mJNDIName;
     private Queue mQueue;
     
     public JMSNotificationListener(
        String pJNDIName,
        Queue pQueue
     ) throws JMSException
     {
        mJNDIName = pJNDIName;
        mQueue = pQueue;
     }
  
     /**
     * Handles the given notification by sending this to the remote
     * client listener
     *
     * @param pNotification                             Notification to be send
     * @param pHandback                                 Handback object
     */
     public void handleNotification(
        Notification pNotification,
        Object pHandback
     ) {
        try {
           if( mSender == null ) {
              // Get QueueConnectionFactory, create Connection, Session and then Sender
              QueueConnection lConnection = getQueueConnection( mJNDIName );
              mSession = lConnection.createQueueSession( false, 
Session.AUTO_ACKNOWLEDGE );
              mSender = ( (QueueSession) mSession).createSender( mQueue );
           }
           // Create a message and send to the Queue
           Message lMessage = mSession.createObjectMessage( pNotification );
           mSender.send( lMessage );
        }
        catch( Exception e ) {
           e.printStackTrace();
        }
     }
  
     /**
     * Test if this and the given Object are equal. This is true if the given
     * object both refer to the same local listener
     *
     * @param pTest                                             Other object to test 
if equal
     *
     * @return                                                  True if both are of 
same type and
     *                                                                  refer to the 
same local listener
     **/
     public boolean equals( Object pTest ) {
        if( pTest instanceof JMSNotificationListener ) {
           try {
              return mQueue.getQueueName().equals(
                 ( (JMSNotificationListener) pTest).mQueue.getQueueName()
              );
           }
           catch( JMSException je ) {
              je.printStackTrace();
           }
        }
        return false;
     }
  
     /**
     * @return                                                  Hashcode of the local 
listener
     **/
     public int hashCode() {
        return mQueue.hashCode();
     }
  
     /**
     * Creates a SurveyManagement bean.
     *
     * @return Returns a SurveyManagement bean for use by the Survey handler.
     **/
     private QueueConnection getQueueConnection( String pJNDIName )
        throws NamingException, JMSException
     {
        Context aJNDIContext = new InitialContext();
        Object aRef = aJNDIContext.lookup( pJNDIName );
        QueueConnectionFactory aFactory = (QueueConnectionFactory) 
           PortableRemoteObject.narrow( aRef, QueueConnectionFactory.class );
        QueueConnection lConnection = aFactory.createQueueConnection();
        lConnection.start();
        return lConnection;
     }
  }
  
  
  
  1.1                  
jboss/src/main/org/jboss/jmx/connector/notification/RMINotificationListener.java
  
  Index: RMINotificationListener.java
  ===================================================================
  /*
  * JBoss, the OpenSource J2EE webOS
  *
  * Distributable under LGPL license.
  * See terms of license at gnu.org.
  */
  package org.jboss.jmx.connector.notification;
  
  import java.io.Serializable;
  import java.rmi.Remote;
  import java.rmi.RemoteException;
  
  import javax.management.Notification;
  
  /**
  * Notification Listener Implementation registered as
  * MBean on the remote JMX Server and the added as
  * Notification Listener on the remote JMX Server.
  * Each notification received will be transfered to
  * the remote client using RMI Callback Objects.
  *
  * @author <A href="mailto:[EMAIL PROTECTED]";>Andreas &quot;Mad&quot; Schaefer</A>
  **/
  public class RMINotificationListener
     implements RMINotificationListenerMBean
  {
     // -------------------------------------------------------------------------
     // Members 
     // -------------------------------------------------------------------------  
  
     private RMINotificationSender mRemoteSender;
  
     // -------------------------------------------------------------------------
     // Constructor
     // -------------------------------------------------------------------------
      
     /**
      * Creates the RMI Notification Listener MBean implemenation which
      * will be registered at the remote JMX Server as notificatin listener
      * and then send the notification over the provided RMI Notification
      * sender to the client
      *
      * @param pNotificationSender The Notification Sender using RMI to
      *                            transport
      *
      * @
      **/
     public RMINotificationListener( RMINotificationSender pNotificationSender ) {
        mRemoteSender = pNotificationSender;
     }
  
     // -------------------------------------------------------------------------
     // Public Methods
     // -------------------------------------------------------------------------
      
        /**
        * Handles the given notifcation event and passed it to the registered
        * RMI Notification Sender
        *
        * @param pNotification                          NotificationEvent
        * @param pHandback                                      Handback object
        *
        * @throws RemoteException                       If a Remote Exception occurred
        */
        public void handleNotification(
                Notification pNotification,
                Object pHandback
        ) {
        try {
           mRemoteSender.handleNotification( pNotification, pHandback );
        }
        catch( RemoteException re ) {
           re.printStackTrace();
        }
     }
  }
  
  
  
  1.1                  
jboss/src/main/org/jboss/jmx/connector/notification/RMINotificationListenerMBean.java
  
  Index: RMINotificationListenerMBean.java
  ===================================================================
  /*
  * JBoss, the OpenSource J2EE webOS
  *
  * Distributable under LGPL license.
  * See terms of license at gnu.org.
  */
  package org.jboss.jmx.connector.notification;
  
  import javax.management.Notification;
  import javax.management.NotificationListener;
  
  /**
  * MBean Interface of a Notification Listener MBean
  * using RMI Callback Objects to send the notifications
  * back to the client.
  * <br>
  * This interface is only necessary because of the naming
  * conventions for standard MBeans.
  *
  * @author <A href="mailto:[EMAIL PROTECTED]";>Andreas &quot;Mad&quot; Schaefer</A>
  **/
  public interface RMINotificationListenerMBean
     extends NotificationListener
  {
  
        // Constants -----------------------------------------------------
  
        // Static --------------------------------------------------------
  
        // Public --------------------------------------------------------
        /**
        * Handles the given notifcation event and passed it to the registered
        * listener
        *
        * @param pNotification                          NotificationEvent
        * @param pHandback                                      Handback object
        *
        * @throws RemoteException                       If a Remote Exception occurred
        */
        public void handleNotification(
                Notification pNotification,
                Object pHandback
        );
  }
  
  
  
  1.1                  
jboss/src/main/org/jboss/jmx/connector/notification/RMINotificationSender.java
  
  Index: RMINotificationSender.java
  ===================================================================
  /*
  * JBoss, the OpenSource J2EE webOS
  *
  * Distributable under LGPL license.
  * See terms of license at gnu.org.
  */
  package org.jboss.jmx.connector.notification;
  
  import java.io.Serializable;
  import java.rmi.Remote;
  import java.rmi.RemoteException;
  
  import javax.management.Notification;
  
  /**
  * Remote interface of the RMI Notification Sender using
  * RMI to transport the notifications over the wire.
  *
  * @author <A href="mailto:[EMAIL PROTECTED]";>Andreas &quot;Mad&quot; Schaefer</A>
  **/
  public interface RMINotificationSender
        extends Remote, Serializable
  {
  
        // Constants -----------------------------------------------------
  
        // Static --------------------------------------------------------
  
        // Public --------------------------------------------------------
        /**
        * Handles the given notifcation event and passed it to the registered
        * listener
        *
        * @param pNotification                          NotificationEvent
        * @param pHandback                                      Handback object
        *
        * @throws RemoteException                       If a Remote Exception occurred
        */
        public void handleNotification(
                Notification pNotification,
                Object pHandback
        ) throws 
                RemoteException;
  }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to