User: andreas 
  Date: 00/08/31 10:43:00

  Added:       src/main/org/jboss/jmx/client ConnectorFactoryImpl.java
                        ConnectorFactoryService.java
                        ConnectorFactoryServiceMBean.java
                        RMIClientConnectorImpl.java
                        RMIClientConnectorImplMBean.java
  Log:
  Client-side Connector implementation and Connector
  Factory which is not complete but working
  
  Revision  Changes    Path
  1.1                  jboss/src/main/org/jboss/jmx/client/ConnectorFactoryImpl.java
  
  Index: ConnectorFactoryImpl.java
  ===================================================================
  /*
   * jBoss, the OpenSource EJB server
   *
   * Distributable under GPL license.
   * See terms of license at gnu.org.
   */
  
  package org.jboss.jmx.client;
  
  import java.util.Arrays;
  import java.util.Collection;
  import java.util.Iterator;
  import java.util.Set;
  
  import javax.management.DynamicMBean;
  import javax.management.MBeanServer;
  import javax.management.ObjectInstance;
  import javax.management.ObjectName;
  
  import org.jboss.jmx.interfaces.JMXConnector;
  
  /**
  * Factory delivering a list of servers and its available protocol connectors
  * and after selected to initiate the connection
  *
  * This is just the (incomplete) interface of it
  *
  * @author <A href="mailto:[EMAIL PROTECTED]">Andreas &quot;Mad&quot; 
Schaefer</A>
  **/
  public class ConnectorFactoryImpl {
  
        // Constants -----------------------------------------------------
        
        // Static --------------------------------------------------------
  
        // Attributes ----------------------------------------------------
        /** Server this factory is registered at **/
        private MBeanServer                             mServer;
  
        // Public --------------------------------------------------------
        
        public ConnectorFactoryImpl(
                MBeanServer pServer
        ) {
                mServer = pServer;
        }
        
        /**
        * Returns a list of available servers
        *
        * @param pServerQuery           Query instance to filter the list of servers
        *
        * @return                                       A collection of available 
servers
        *                                                       names/identifications 
(String)
        **/
        public Collection getServers(
  //AS          ServerQuery pServerQuery
        ) {
                return Arrays.asList(
                        new String[] {
                                "localhost"
                        }
                );
        }
        
        /**
        * Returns a list of available protocols (connectors)
        *
        * @param pServer                        Server name/identification to look up
        *
        * @return                                       A collection of available 
protocols (String)
        **/
        public Collection getProtocols(
                String pServer
        ) {
                return Arrays.asList(
                        new String[] {
                                "rmi"
                        }
                );
        }
  
        /**
        * Initiate a connection to the given server with the given
        * protocol
        *
        * @param pServer                        Server name/identification to connect 
to
        * @param pProtocol                      Protocol to use
        *
        * @return                                       JMX Connector or null if 
server or protocol is
        *                                                       not available
        **/
        public JMXConnector createConnection(
                String pServer,
                String pProtocol
        ) {
                JMXConnector lConnector = null;
                if( pServer.equals( "localhost" ) ) {
                        if( pProtocol.equals( "rmi" ) ) {
                                try {
                                        lConnector = new RMIClientConnectorImpl(
                                                pServer
                                        );
                                        mServer.registerMBean(
                                                lConnector,
                                                new ObjectName( 
"DefaultDomain:name=RMIConnectorTo" + pServer )
                                        );
                                }
                                catch( Exception e ) {
                                        e.printStackTrace();
                                }
                        }
                }
                System.out.println( "ConnectorFactoryImpl.createConnection(), got 
connector: " + lConnector );
                return lConnector;
        }
        
        /**
        * Removes the given connection and frees the resources
        *
        * @param pSever                         Server name/identification of the 
connectino
        * @param pProtocol                      Protocol used
        **/
        public void removeConnection(
                String pServer,
                String pProtocol
        ) {
                if( pServer.equals( "localhost" ) ) {
                        if( pProtocol.equals( "rmi" ) ) {
                                try {
                                        Set lConnectors = mServer.queryMBeans(
                                                new ObjectName( 
"DefaultDomain:name=RMIConnectorTo" + pServer ),
                                                null
                                        );
                                        System.out.println( 
"ConnectorFactoryImpl.removeConnection(), got connectors: " + lConnectors );
                                        if( !lConnectors.isEmpty() ) {
                                                Iterator i = lConnectors.iterator();
                                                while( i.hasNext() ) {
                                                        ObjectInstance lConnector = 
(ObjectInstance) i.next();
                                                        mServer.invoke(
                                                                
lConnector.getObjectName(),
                                                                "stop",
                                                                new Object[] {},
                                                                new String[] {}
                                                        );
                                                        mServer.unregisterMBean(
                                                                
lConnector.getObjectName()
                                                        );
                                                        System.out.println( 
"ConnectorFactoryImpl.removeConnection(), " +
                                                                "unregister MBean: " + 
lConnector.getObjectName()
                                                        );
                                                }
                                        }
                                }
                                catch( Exception e ) {
                                        e.printStackTrace();
                                }
                        }
                }
        }
  }
  
  
  
  1.1                  jboss/src/main/org/jboss/jmx/client/ConnectorFactoryService.java
  
  Index: ConnectorFactoryService.java
  ===================================================================
  /*
   * jBoss, the OpenSource EJB server
   *
   * Distributable under GPL license.
   * See terms of license at gnu.org.
   */
  
  package org.jboss.jmx.client;
  
  import java.util.Arrays;
  import java.util.Collection;
  
  import javax.management.DynamicMBean;
  import javax.management.ObjectName;
  import javax.management.MBeanServer;
  
  import javax.naming.InitialContext;
  
  import org.jboss.jmx.interfaces.JMXConnector;
  import org.jboss.util.ServiceMBeanSupport;
  
  /**
  * Factory delivering a list of servers and its available protocol connectors
  * and after selected to initiate the connection
  *
  * This is just the (incomplete) interface of it
  *
  * @author <A href="mailto:[EMAIL PROTECTED]">Andreas &quot;Mad&quot; 
Schaefer</A>
  **/
  public class ConnectorFactoryService
        extends ServiceMBeanSupport
        implements ConnectorFactoryServiceMBean
  {
  
        // Constants -----------------------------------------------------
        private static final String                             JNDI_NAME = 
"jxm:connector:factory";
        
        // Static --------------------------------------------------------
  
        // Attributes ----------------------------------------------------
        /** Local MBeanServer this service is registered to **/
        private MBeanServer                             mServer;
        /** Connector Factory instance **/
        private ConnectorFactoryImpl    mFactory;
  
        // Public --------------------------------------------------------
        
        public ConnectorFactoryService(
        ) {
        }
        
        /**
        * Returns a list of available servers
        *
        * @param pServerQuery           Query instance to filter the list of servers
        *
        * @return                                       A collection of available 
servers
        *                                                       names/identifications 
(String)
        */
        public Collection getServers(
  //AS          ServerQuery pServerQuery
        ) {
                return mFactory.getServers();
        }
        
        /**
        * Returns a list of available protocols (connectors)
        *
        * @param pServer                        Server name/identification to look up
        *
        * @return                                       A collection of available 
protocols (String)
        */
        public Collection getProtocols(
                String pServer
        ) {
                return mFactory.getProtocols( pServer );
        }
  
        /**
        * Initiate a connection to the given server with the given
        * protocol
        *
        * @param pServer                        Server name/identification to connect 
to
        * @param pProtocol                      Protocol to use
        */
        public JMXConnector createConnection(
                String pServer,
                String pProtocol
        ) {
                return mFactory.createConnection( pServer, pProtocol );
        }
        
        /**
        * Removes the given connection and frees the resources
        *
        * @param pSever                         Server name/identification of the 
connectino
        * @param pProtocol                      Protocol used
        */
        public void removeConnection(
                String pServer,
                String pProtocol
        ) {
                mFactory.removeConnection( pServer, pProtocol );
        }
  
        public ObjectName getObjectName(
                MBeanServer pServer, 
                ObjectName pName
        ) throws javax.management.MalformedObjectNameException {
                mServer = pServer;
                System.out.println( "ConnectorFactoryService.getObjectName(), server: 
" + mServer +
                        ", object name: " + OBJECT_NAME +
                        ", instance: " + new ObjectName( OBJECT_NAME ) );
                return new ObjectName( OBJECT_NAME );
        }
        
        public String getName() {
                return "JMX Client Connector Factory";
        }
        
        // Protected -----------------------------------------------------
        protected void initService() throws Exception {
                try {
                System.out.println( "ConnectorFactoryService.initService(), server: " 
+ mServer );
                mFactory = new ConnectorFactoryImpl( mServer );
                System.out.println( "ConnectorFactoryService.initService(), server: " 
+ mServer +
                        ", factory: " + mFactory );
                }
                catch( Exception e ) {
                        e.printStackTrace();
                }
        }
        
        protected void startService() throws Exception {
                new InitialContext().bind( JNDI_NAME, mFactory );
        }
        
        protected void stopService() {
                try {
                        new InitialContext().unbind(JNDI_NAME);
                }
                catch( Exception e )    {
                        log.exception( e );
                }
        }
  }
  
  
  
  1.1                  
jboss/src/main/org/jboss/jmx/client/ConnectorFactoryServiceMBean.java
  
  Index: ConnectorFactoryServiceMBean.java
  ===================================================================
  /*
   * jBoss, the OpenSource EJB server
   *
   * Distributable under GPL license.
   * See terms of license at gnu.org.
   */
  
  package org.jboss.jmx.client;
  
  import java.util.Arrays;
  import java.util.Collection;
  
  import javax.management.DynamicMBean;
  import javax.management.MBeanServer;
  
  import org.jboss.jmx.interfaces.JMXConnector;
  import org.jboss.util.ServiceMBean;
  
  /**
  * Factory delivering a list of servers and its available protocol connectors
  * and after selected to initiate the connection
  *
  * This is just the (incomplete) interface of it
  *
  * @author <A href="mailto:[EMAIL PROTECTED]">Andreas &quot;Mad&quot; 
Schaefer</A>
  **/
  public interface ConnectorFactoryServiceMBean
        extends ServiceMBean
  {
  
        // Constants -----------------------------------------------------
        public static final String OBJECT_NAME = "Factory:name=JMX";
        
        // Public --------------------------------------------------------
        /**
        * Returns a list of available servers
        *
        * @param pServerQuery           Query instance to filter the list of servers
        *
        * @return                                       A collection of available 
servers
        *                                                       names/identifications 
(String)
        */
        public Collection getServers(
  //AS          ServerQuery pServerQuery
        );
        
        /**
        * Returns a list of available protocols (connectors)
        *
        * @param pServer                        Server name/identification to look up
        *
        * @return                                       A collection of available 
protocols (String)
        */
        public Collection getProtocols(
                String pServer
        );
  
        /**
        * Initiate a connection to the given server with the given
        * protocol
        *
        * @param pServer                        Server name/identification to connect 
to
        * @param pProtocol                      Protocol to use
        */
        public JMXConnector createConnection(
                String pServer,
                String pProtocol
        );
        
        /**
        * Removes the given connection and frees the resources
        *
        * @param pSever                         Server name/identification of the 
connectino
        * @param pProtocol                      Protocol used
        */
        public void removeConnection(
                String pServer,
                String pProtocol
        );
  }
  
  
  
  1.1                  jboss/src/main/org/jboss/jmx/client/RMIClientConnectorImpl.java
  
  Index: RMIClientConnectorImpl.java
  ===================================================================
  /*
   * jBoss, the OpenSource EJB server
   *
   * Distributable under GPL license.
   * See terms of license at gnu.org.
   */
   
  package org.jboss.jmx.client;
  
  import java.io.ObjectInputStream;
  import java.rmi.server.UnicastRemoteObject;
  import java.rmi.RemoteException;
  import java.rmi.ServerException;
  import java.util.ArrayList;
  import java.util.Collection;
  import java.util.Hashtable;
  import java.util.Iterator;
  import java.util.Set;
  import java.util.Vector;
  
  import javax.management.Attribute;
  import javax.management.AttributeList;
  import javax.management.ObjectName;
  import javax.management.QueryExp;
  import javax.management.ObjectInstance;
  import javax.management.Notification;
  import javax.management.NotificationFilter;
  import javax.management.NotificationListener;
  import javax.management.MBeanServer;
  import javax.management.MBeanInfo;
  
  import javax.management.AttributeNotFoundException;
  import javax.management.InstanceAlreadyExistsException;
  import javax.management.InstanceNotFoundException;
  import javax.management.IntrospectionException;
  import javax.management.InvalidAttributeValueException;
  import javax.management.ListenerNotFoundException;
  import javax.management.MBeanException;
  import javax.management.MBeanRegistrationException;
  import javax.management.NotCompliantMBeanException;
  import javax.management.OperationsException;
  import javax.management.ReflectionException;
  
  import javax.naming.InitialContext;
  
  import org.jboss.logging.Log;
  import org.jboss.util.ServiceMBeanSupport;
  
  import org.jboss.jmx.interfaces.JMXConnectorMBean;
  import org.jboss.jmx.interfaces.RMIConnector;
  import org.jboss.jmx.interfaces.RMINotificationListener;
  import org.jboss.jmx.server.ObjectHandler;
  
  /**
  * Implementation of the JMX Connector over the RMI protocol 
  *      
  * @author Rickard �berg ([EMAIL PROTECTED])
  * @author <A href="mailto:[EMAIL PROTECTED]">Andreas &quot;Mad&quot; 
Schaefer</A>
  */
  public class RMIClientConnectorImpl
        implements JMXConnectorMBean, RMIClientConnectorImplMBean
  {
        // Constants -----------------------------------------------------
        
        // Attributes ----------------------------------------------------
        private RMIConnector            mRemoteConnector;
        private Object                          mServer = "";
        private Hashtable                       mHandbackPool = new Hashtable();
        private Vector                          mListeners = new Vector();
        
        // Static --------------------------------------------------------
        
        // Constructors --------------------------------------------------
        public RMIClientConnectorImpl(
                String pServerName
        ) {
                super();
                start( pServerName );
        }
        
        // JMXClientConnector implementation -------------------------------
        public void start(
                Object pServer
        ) throws IllegalArgumentException {
                if( pServer == null ) {
                        throw new IllegalArgumentException( "Server cannot be null. "
                                + "To close the connection use stop()" );
                }
                try {
                        InitialContext lNamingContext = new InitialContext();
                        System.out.println( "RMIClientConnectorImp.start(), got Naming 
Context: " +     lNamingContext +
                                ", environment: " + lNamingContext.getEnvironment() +
                                ", name in namespace: " + 
lNamingContext.getNameInNamespace()
                        );
                        // This has to be adjusted later on to reflect the given 
parameter
                        mRemoteConnector = (RMIConnector) new InitialContext().lookup( 
"jmx:rmi" );
                        System.err.println( "RMIClientConnectorImpl.start(), got 
remote connector: " + mRemoteConnector );
                        mServer = pServer;
                }
                catch( Exception e ) {
                        e.printStackTrace();
                }
        }
  
        public void stop() {
                System.out.println( "RMIClientConnectorImpl.stop(), start" );
                // First go through all the reistered listeners and remove them
                Iterator i = mListeners.iterator();
                while( i.hasNext() ) {
                        try {
                                Listener lRemoteListener = (Listener) i.next();
                                System.out.println( "RMIClientConnectorImpl.stop(), 
remove listener: " +
                                        lRemoteListener
                                );
                                removeNotificationListener(
                                        lRemoteListener.getObjectName(),
                                        lRemoteListener.getLocalListener()
                                );
                                i.remove();
                        }
                        catch( Exception e ) {
                                e.printStackTrace();
                        }
                }
                mRemoteConnector = null;
                mServer = "";
        }
        
        public boolean isAlive() {
                return mRemoteConnector != null;
        }
  
        public String getServerDescription() {
                return "" + mServer;
        }
  
        // JMXConnector implementation -------------------------------------
        public Object instantiate(
                String pClassName
        ) throws
                ReflectionException,
                MBeanException
        {
                try {
                        return mRemoteConnector.instantiate( pClassName );
                }
                catch( RemoteException re ) {
                        //AS Not a good style but for now
                        return null;
                }
        }
                
  
        public Object instantiate(
                String pClassName,
                ObjectName pLoaderName
        ) throws
                ReflectionException,
                MBeanException,
                InstanceNotFoundException
        {
                try {
                        return mRemoteConnector.instantiate( pClassName, pLoaderName );
                }
                catch( RemoteException re ) {
                        //AS Not a good style but for now
                        return null;
                }
        }
  
        public Object instantiate(
                String pClassName,
                String[] pParams,
                String[] pSignature
        ) throws
                ReflectionException,
                MBeanException
        {
                try {
                        return mRemoteConnector.instantiate( pClassName, pParams, 
pSignature );
                }
                catch( RemoteException re ) {
                        //AS Not a good style but for now
                        return null;
                }
        }
  
        public Object instantiate(
                String pClassName,
                ObjectName pLoaderName,
                String[] pParams,
                String[] pSignature
        ) throws
                ReflectionException,
                MBeanException,
                InstanceNotFoundException
        {
                try {
                        return mRemoteConnector.instantiate( pClassName, pLoaderName, 
pParams, pSignature );
                }
                catch( RemoteException re ) {
                        //AS Not a good style but for now
                        return null;
                }
        }
  
        public ObjectInstance createMBean(
                String pClassName,
                ObjectName pName
        ) throws
                ReflectionException,
                InstanceAlreadyExistsException,
                MBeanRegistrationException,
                MBeanException,
                NotCompliantMBeanException
        {
                try {
                        return mRemoteConnector.createMBean( pClassName, pName );
                }
                catch( RemoteException re ) {
                        //AS Not a good style but for now
                        return null;
                }
        }
  
        public ObjectInstance createMBean(
                String pClassName,
                ObjectName pName,
                ObjectName pLoaderName
        ) throws
                ReflectionException,
                InstanceAlreadyExistsException,
                MBeanRegistrationException,
                MBeanException,
                NotCompliantMBeanException,
                InstanceNotFoundException
        {
                try {
                        return mRemoteConnector.createMBean( pClassName, pName, 
pLoaderName );
                }
                catch( RemoteException re ) {
                        //AS Not a good style but for now
                        return null;
                }
        }
  
        public ObjectInstance createMBean(
                String pClassName,
                ObjectName pName,
                String[] pParams,
                String[] pSignature
        ) throws
                ReflectionException,
                InstanceAlreadyExistsException,
                MBeanRegistrationException,
                MBeanException,
                NotCompliantMBeanException
        {
                try {
                        return mRemoteConnector.createMBean( pClassName, pName, 
pParams, pSignature );
                }
                catch( RemoteException re ) {
                        //AS Not a good style but for now
                        return null;
                }
        }
  
        public ObjectInstance createMBean(
                String pClassName,
                ObjectName pName,
                ObjectName pLoaderName,
                String[] pParams,
                String[] pSignature
        ) throws
                ReflectionException,
                InstanceAlreadyExistsException,
                MBeanRegistrationException,
                MBeanException,
                NotCompliantMBeanException,
                InstanceNotFoundException
        {
                try {
                        return mRemoteConnector.createMBean( pClassName, pName, 
pLoaderName, pParams, pSignature );
                }
                catch( RemoteException re ) {
                        //AS Not a good style but for now
                        return null;
                }
        }
  
        public ObjectInstance registerMBean(
                Object pObject,
                ObjectName pName
        ) throws
                InstanceAlreadyExistsException,
                MBeanRegistrationException,
                NotCompliantMBeanException
        {
                try {
                        return mRemoteConnector.registerMBean( pObject, pName );
                }
                catch( RemoteException re ) {
                        //AS Not a good style but for now
                        return null;
                }
        }
  
        public void unregisterMBean(
                ObjectName pName
        ) throws
                InstanceNotFoundException,
                MBeanRegistrationException
        {
                try {
                        mRemoteConnector.unregisterMBean( pName );
                }
                catch( RemoteException re ) {
                }
        }
  
        public ObjectInstance getObjectInstance(
                ObjectName pName
        ) throws
                InstanceNotFoundException
        {
                try {
                        return mRemoteConnector.getObjectInstance( pName );
                }
                catch( RemoteException re ) {
                        //AS Not a good style but for now
                        return null;
                }
        }
  
        public Set queryMBeans(
                ObjectName pName,
                QueryExp pQuery
        ) {
                try {
                        return mRemoteConnector.queryMBeans( pName, pQuery );
                }
                catch( RemoteException re ) {
                        re.printStackTrace();
                        //AS Not a good style but for now
                        return null;
                }
        }
  
        public Set queryNames(
                ObjectName pName,
                QueryExp pQuery
        ) {
                try {
                        return mRemoteConnector.queryNames( pName, pQuery );
                }
                catch( RemoteException re ) {
                        //AS Not a good style but for now
                        return null;
                }
        }
  
        public boolean isRegistered(
                ObjectName pName
        ) {
                try {
                        return mRemoteConnector.isRegistered( pName );
                }
                catch( RemoteException re ) {
                        //AS Not a good style but for now
                        return false;
                }
        }
  
        public Integer getMBeanCount(
        ) {
                try {
                        return mRemoteConnector.getMBeanCount();
                }
                catch( RemoteException re ) {
                        //AS Not a good style but for now
                        return null;
                }
        }
  
        public Object getAttribute(
                ObjectName pName,
                String pAttribute
        ) throws
                MBeanException,
                AttributeNotFoundException,
                InstanceNotFoundException,
                ReflectionException
        {
                try {
                        return mRemoteConnector.getAttribute( pName, pAttribute );
                }
                catch( RemoteException re ) {
                        //AS Not a good style but for now
                        return null;
                }
        }
  
        public AttributeList getAttributes(
                ObjectName pName,
                String[] pAttributes
        ) throws
                InstanceNotFoundException,
                ReflectionException
        {
                try {
                        return mRemoteConnector.getAttributes( pName, pAttributes );
                }
                catch( RemoteException re ) {
                        //AS Not a good style but for now
                        return null;
                }
        }
  
        public void setAttribute(
                ObjectName pName,
                Attribute pAttribute
        ) throws
                InstanceNotFoundException,
                AttributeNotFoundException,
                InvalidAttributeValueException,
                MBeanException,
                ReflectionException
        {
                try {
                        mRemoteConnector.setAttribute( pName, pAttribute );
                }
                catch( RemoteException re ) {
                }
        }
  
        public void setAttributes(
                ObjectName pName,
                AttributeList pAttributes
        ) throws
                InstanceNotFoundException,
                ReflectionException
        {
                try {
                        mRemoteConnector.setAttributes( pName, pAttributes );
                }
                catch( RemoteException re ) {
                }
        }
  
        public Object invoke(
                ObjectName pName,
                String pActionName,
                Object[] pParams,
                String[] pSignature
        ) throws
                InstanceNotFoundException,
                MBeanException,
                ReflectionException
        {
                try {
                        return mRemoteConnector.invoke( pName, pActionName, pParams, 
pSignature );
                }
                catch( RemoteException re ) {
                        //AS Not a good style but for now
                        return null;
                }
        }
  
        public String getDefaultDomain(
        ) {
                try {
                        return mRemoteConnector.getDefaultDomain();
                }
                catch( RemoteException re ) {
                        //AS Not a good style but for now
                        return null;
                }
        }
  
        public void addNotificationListener(
                ObjectName pName,
                NotificationListener pListener,
                NotificationFilter pFilter,
                Object pHandback                
        ) throws
                InstanceNotFoundException
        {
                try {
                        Listener lRemoteListener = new Listener(
                                pListener,
                                pHandback,
                                pName
                        );
                        UnicastRemoteObject.exportObject( lRemoteListener );
                        mRemoteConnector.addNotificationListener(
                                pName,
                                lRemoteListener,
                                pFilter,
                                lRemoteListener.getHandback()
                        );
                        mListeners.addElement( lRemoteListener );
                }
                catch( RemoteException re ) {
                        re.printStackTrace();
                }
        }
  
        public void addNotificationListener(
                ObjectName pName,
                ObjectName pListener,
                NotificationFilter pFilter,
                Object pHandback                
        ) throws
                InstanceNotFoundException,
                UnsupportedOperationException
        {
                throw new UnsupportedOperationException(
                        "A connector cannot support this method"
                );
        }
  
        public void removeNotificationListener(
                ObjectName pName,
                NotificationListener pListener
        ) throws
                InstanceNotFoundException,
                ListenerNotFoundException
        {
                // Lookup if the given listener is registered
                int lIndex = mListeners.indexOf(
                        new Listener(
                                pListener,
                                null,
                                pName
                        )
                );
                // If found then get the remote listener and remove it from the
                // the Connector
                if( lIndex >= 0 ) {
                        try {
                                Listener lRemoteListener = (Listener) 
mListeners.elementAt( lIndex );
                                mRemoteConnector.removeNotificationListener(
                                        pName,
                                        lRemoteListener
                                );
                                mListeners.removeElementAt( lIndex );
                        }
                        catch( RemoteException re ) {
                        }
                }
        }
  
        public void removeNotificationListener(
                ObjectName pName,
                ObjectName pListener
        ) throws
                InstanceNotFoundException,
                ListenerNotFoundException,
                UnsupportedOperationException
        {
                throw new UnsupportedOperationException(
                        "A connector cannot support this method"
                );
        }
  
        public MBeanInfo getMBeanInfo(
                ObjectName pName
        ) throws
                InstanceNotFoundException,
                IntrospectionException,
                ReflectionException
        {
                try {
                        return mRemoteConnector.getMBeanInfo( pName );
                }
                catch( RemoteException re ) {
                        //AS Not a good style but for now
                        return null;
                }
        }
  
        public ObjectInputStream deserialize(
                ObjectName pName,
                byte[] pData
        ) throws
                InstanceNotFoundException,
                OperationsException,
                UnsupportedOperationException
        {
                throw new UnsupportedOperationException(
                        "Remotely this method cannot be supported"
                );
        }
  
        public ObjectInputStream deserialize(
                String pClassName,
                byte[] pData
        ) throws
                OperationsException,
                ReflectionException,
                UnsupportedOperationException
        {
                throw new UnsupportedOperationException(
                        "Remotely this method cannot be supported"
                );
        }
  
        public ObjectInputStream deserialize(
                String pClassName,
                ObjectName pLoaderName,
                byte[] pData
        ) throws
                InstanceNotFoundException,
                OperationsException,
                ReflectionException,
                UnsupportedOperationException
        {
                throw new UnsupportedOperationException(
                        "Remotely this method cannot be supported"
                );
        }
  
        // Protected -----------------------------------------------------
  
        /**
        * Listener wrapper around the remote RMI Notification Listener
        */
        public class Listener implements RMINotificationListener {
  
                private NotificationListener                    mLocalListener;
                private ObjectHandler                                   
mHandbackHandler;
                private Object                                                  
mHandback;
                //AS This is necessary becasue to remove all of the registered
                //AS listeners when the connection is going down.
                //AS But maybe this is the wrong place !!
                private ObjectName                                              
mObjectName;
                
                public Listener(
                        NotificationListener pLocalListener,
                        Object pHandback,
                        ObjectName pName
                ) {
                        mLocalListener = pLocalListener;
                        mHandback = pHandback;
                        mHandbackHandler = new ObjectHandler( this.toString() );
                        mObjectName = pName;
                }
  
                /**
                * 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
                ) throws
                        RemoteException
                {
                        Object lHandback;
                        // Take the given handback object (which should be the same 
object
                        // as the stored one. If yes then replace it by the stored 
object
                        if( mHandbackHandler.equals( pHandback ) ) {
                                lHandback = mHandback;
                        }
                        else {
                                lHandback = pHandback;
                        }
                        mLocalListener.handleNotification(
                                pNotification,
                                lHandback
                        );
                }
                
                /**
                * @return                                                       Object 
Handler of the given Handback
                *                                                                      
 object
                */
                public ObjectHandler getHandback() {
                        return mHandbackHandler;
                }
                /** Redesign it (AS) **/
                public ObjectName getObjectName() {
                        return mObjectName;
                }
                /** Redesign it (AS) **/
                public NotificationListener getLocalListener() {
                        return mLocalListener;
                }
                /**
                * 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 Listener ) {
                                return mLocalListener.equals(
                                        ( (Listener) pTest).mLocalListener
                                );
                        }
                        return false;
                }
                /**
                * @return                                                       
Hashcode of the local listener
                **/
                public int hashCode() {
                        return mLocalListener.hashCode();
                }
        }
  }     
  
  
  
  1.1                  
jboss/src/main/org/jboss/jmx/client/RMIClientConnectorImplMBean.java
  
  Index: RMIClientConnectorImplMBean.java
  ===================================================================
  /*
   * jBoss, the OpenSource EJB server
   *
   * Distributable under GPL license.
   * See terms of license at gnu.org.
   */
  
  package org.jboss.jmx.client;
  
  import org.jboss.jmx.interfaces.JMXConnector;
  
  /**
  *
  * @author <A href="mailto:[EMAIL PROTECTED]">Andreas &quot;Mad&quot; 
Schaefer</A>
  **/
  public interface RMIClientConnectorImplMBean
        extends JMXConnector
  {
        /**
        * Starts the connection to the given server
        *
        * @param pServer                                                Server the 
connector connects to
        *
        * @throw IllegalArgumentException               If the server is null
        **/
        public void start(
                Object pServer
        ) throws IllegalArgumentException;
        /**
        * Stops the connection to the given server and remove all the registered
        * listeners
        **/
        public void stop();
  }
  
  
  

Reply via email to