[Ejtools-cvs] applications/jmx.browser/src/main/org/ejtools/jmx/browser/model/connector AbstractConn
Brought to you by:
letiemble
Update of /cvsroot/ejtools/applications/jmx.browser/src/main/org/ejtools/jmx/browser/model/connector In directory sc8-pr-cvs1:/tmp/cvs-serv11709/jmx.browser/src/main/org/ejtools/jmx/browser/model/connector Modified Files: AbstractConnectionService.java JBoss30EJBConnectionService.java JBoss30RMIConnectionService.java Log Message: Add more javadocs. Adjust some things. Index: AbstractConnectionService.java =================================================================== RCS file: /cvsroot/ejtools/applications/jmx.browser/src/main/org/ejtools/jmx/browser/model/connector/AbstractConnectionService.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** AbstractConnectionService.java 27 Nov 2003 01:13:07 -0000 1.4 --- AbstractConnectionService.java 13 Dec 2003 22:15:07 -0000 1.5 *************** *** 1,119 **** ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.jmx.browser.model.connector; ! ! import javax.management.MBeanServer; ! ! import org.ejtools.jmx.browser.model.service.ConnectionService; ! import org.ejtools.util.service.Profile; ! ! /** ! * Abstract connection that holds some common behaviour for the connectors ! * ! * @author letiembl ! * @created 4 septembre 2002 ! * @version $Revision$ ! */ ! public abstract class AbstractConnectionService implements ConnectionService ! { ! /** Connected state */ ! protected boolean connected = false; ! /** The connection profile */ ! protected Profile profile = null; ! /** The proxied MBean server */ ! protected MBeanServer server = null; ! ! ! /**Constructor for the AbstractConnectionService object */ ! protected AbstractConnectionService() { } ! ! ! /** ! * Connect to the MBean server with this profile ! * ! * @param profile Connection profile ! */ ! public void connect(Profile profile) ! { ! this.profile = profile; ! try ! { ! this.createMBeanServer(); ! this.setConnected(true); ! } ! catch (Exception e) ! { ! e.printStackTrace(); ! this.setConnected(false); ! } ! } ! ! ! /** Disconnect from the MBean server */ ! public void disconnect() { } ! ! ! /** ! * Gets the proxied MBean server ! * ! * @return The MBeanServer proxy ! */ ! public MBeanServer getMBeanServer() ! { ! if (!this.connected) ! { ! throw new IllegalStateException("The service is not connected. Call 'connect' method before."); ! } ! if (this.server == null) ! { ! throw new IllegalStateException("The server is null. Call 'connect' method before."); ! } ! return this.server; ! } ! ! ! /** ! * Return whether the connector is connector ! * ! * @return true if connected ! */ ! public boolean isConnected() ! { ! return this.connected; ! } ! ! ! /** ! * Sets the connection state value ! * ! * @param connected The connection state ! */ ! public void setConnected(boolean connected) ! { ! this.connected = connected; ! } ! ! ! /** ! * Create the proxy to the MBean server. This method must set the MBean server after a successful creation. ! * ! * @exception Exception Description of the Exception ! */ ! protected abstract void createMBeanServer() ! throws Exception; ! ! ! /** ! * Sets the MBeanServer proxy for this connector ! * ! * @param server The MBeanServer proxy ! */ ! protected void setMBeanServer(MBeanServer server) ! { ! this.server = server; ! } ! } --- 1,119 ---- ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.jmx.browser.model.connector; ! ! import javax.management.MBeanServer; ! ! import org.ejtools.jmx.browser.model.service.ConnectionService; ! import org.ejtools.util.service.Profile; ! ! /** ! * Abstract connection that holds some common behaviour for the connectors ! * ! * @author letiembl ! * @created 4 septembre 2002 ! * @version $Revision$ ! */ ! public abstract class AbstractConnectionService implements ConnectionService ! { ! /** Connected state */ ! protected boolean connected = false; ! /** The connection profile */ ! protected Profile profile = null; ! /** The proxied MBean server */ ! protected MBeanServer server = null; ! ! ! /**Constructor for the AbstractConnectionService object */ ! protected AbstractConnectionService() { } ! ! ! /** ! * Connect to the MBean server with this profile ! * ! * @param profile Connection profile ! */ ! public void connect(Profile profile) ! { ! this.profile = profile; ! try ! { ! this.createMBeanServer(); ! this.setConnected(true); ! } ! catch (Exception e) ! { ! e.printStackTrace(); ! this.setConnected(false); ! } ! } ! ! ! /** Disconnect from the MBean server */ ! public void disconnect() { } ! ! ! /** ! * Gets the proxied MBean server ! * ! * @return The MBeanServer proxy ! */ ! public MBeanServer getMBeanServer() ! { ! if (!this.connected) ! { ! throw new IllegalStateException("The service is not connected. Call 'connect' method before."); ! } ! if (this.server == null) ! { ! throw new IllegalStateException("The server is null. Call 'connect' method before."); ! } ! return this.server; ! } ! ! ! /** ! * Return whether the connector is connector ! * ! * @return true if connected ! */ ! public boolean isConnected() ! { ! return this.connected; ! } ! ! ! /** ! * Sets the connection state value ! * ! * @param connected The connection state ! */ ! public void setConnected(boolean connected) ! { ! this.connected = connected; ! } ! ! ! /** ! * Create the proxy to the MBean server. This method must set the MBean server after a successful creation. ! * ! * @exception Exception Description of the Exception ! */ ! protected abstract void createMBeanServer() ! throws Exception; ! ! ! /** ! * Sets the MBeanServer proxy for this connector ! * ! * @param server The MBeanServer proxy ! */ ! protected void setMBeanServer(MBeanServer server) ! { ! this.server = server; ! } ! } Index: JBoss30EJBConnectionService.java =================================================================== RCS file: /cvsroot/ejtools/applications/jmx.browser/src/main/org/ejtools/jmx/browser/model/connector/JBoss30EJBConnectionService.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** JBoss30EJBConnectionService.java 27 Nov 2003 01:13:07 -0000 1.4 --- JBoss30EJBConnectionService.java 13 Dec 2003 22:15:07 -0000 1.5 *************** *** 1,81 **** ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.jmx.browser.model.connector; ! ! import java.lang.reflect.Method; ! import java.util.Hashtable; ! ! import javax.management.MBeanServer; ! import javax.naming.Context; ! import javax.naming.InitialContext; ! import javax.rmi.PortableRemoteObject; ! ! import org.ejtools.jmx.MBeanServerProxy; ! import org.ejtools.jmx.browser.model.service.ConnectionMetaData; ! ! ! /** ! * EJB Connector for JBoss 3.x series. Look up an EJB Home into the JNDI space and create ! * an instance of an EJB, which is proxied to hide the remote aspects. ! * ! * @author letiembl ! * @created 4 septembre 2002 ! * @version $Revision$ ! */ ! public class JBoss30EJBConnectionService extends AbstractConnectionService ! { ! /** Instace of the RMI adaptor */ ! protected Object adaptor = null; ! ! ! /** Disconnection by removing the EJB instance. */ ! public void disconnect() ! { ! super.disconnect(); ! try ! { ! // Search for the stop method of the EJB Adaptor ! Method m = this.adaptor.getClass().getMethod("remove", new Class[0]); ! m.invoke(this.adaptor, new Object[0]); ! } ! catch (Exception e) ! { ! // Do nothing ! } ! this.setConnected(false); ! } ! ! ! /** ! * Creation of the local proxy to access the remote MBean server. ! * ! * @exception Exception Description of the Exception ! */ ! protected void createMBeanServer() ! throws Exception ! { ! System.setProperty("jmx.serial.form", "1.1"); ! ! Hashtable props = new Hashtable(); ! props.put(Context.INITIAL_CONTEXT_FACTORY, this.profile.getProperty(ConnectionMetaData.FACTORY)); ! props.put(Context.URL_PKG_PREFIXES, this.profile.getProperty(ConnectionMetaData.PACKAGES)); ! props.put(Context.PROVIDER_URL, this.profile.getProperty(ConnectionMetaData.URL)); ! props.put(Context.SECURITY_PRINCIPAL, this.profile.getProperty(ConnectionMetaData.PRINCIPAL)); ! props.put(Context.SECURITY_CREDENTIALS, this.profile.getProperty(ConnectionMetaData.CREDENTIALS)); ! ! InitialContext context = new InitialContext(props); ! Object ref = context.lookup(this.profile.getProperty(ConnectionMetaData.CONTEXT)); ! ! Class clazzAdaptorHome = Thread.currentThread().getContextClassLoader().loadClass("org.jboss.jmx.adaptor.interfaces.AdaptorHome"); ! Object home = PortableRemoteObject.narrow(ref, clazzAdaptorHome); ! Method createMethod = clazzAdaptorHome.getMethod("create", new Class[0]); ! this.adaptor = createMethod.invoke(home, new Object[0]); ! ! MBeanServer server = MBeanServerProxy.createMBeanProxy(this.adaptor); ! this.setMBeanServer(server); ! } ! } --- 1,81 ---- ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.jmx.browser.model.connector; ! ! import java.lang.reflect.Method; ! import java.util.Hashtable; ! ! import javax.management.MBeanServer; ! import javax.naming.Context; ! import javax.naming.InitialContext; ! import javax.rmi.PortableRemoteObject; ! ! import org.ejtools.jmx.MBeanServerProxy; ! import org.ejtools.jmx.browser.model.service.ConnectionMetaData; ! ! ! /** ! * EJB Connector for JBoss 3.x series. Look up an EJB Home into the JNDI space and create ! * an instance of an EJB, which is proxied to hide the remote aspects. ! * ! * @author letiembl ! * @created 4 septembre 2002 ! * @version $Revision$ ! */ ! public class JBoss30EJBConnectionService extends AbstractConnectionService ! { ! /** Instace of the RMI adaptor */ ! protected Object adaptor = null; ! ! ! /** Disconnection by removing the EJB instance. */ ! public void disconnect() ! { ! super.disconnect(); ! try ! { ! // Search for the stop method of the EJB Adaptor ! Method m = this.adaptor.getClass().getMethod("remove", new Class[0]); ! m.invoke(this.adaptor, new Object[0]); ! } ! catch (Exception e) ! { ! // Do nothing ! } ! this.setConnected(false); ! } ! ! ! /** ! * Creation of the local proxy to access the remote MBean server. ! * ! * @exception Exception Description of the Exception ! */ ! protected void createMBeanServer() ! throws Exception ! { ! System.setProperty("jmx.serial.form", "1.1"); ! ! Hashtable props = new Hashtable(); ! props.put(Context.INITIAL_CONTEXT_FACTORY, this.profile.getProperty(ConnectionMetaData.FACTORY)); ! props.put(Context.URL_PKG_PREFIXES, this.profile.getProperty(ConnectionMetaData.PACKAGES)); ! props.put(Context.PROVIDER_URL, this.profile.getProperty(ConnectionMetaData.URL)); ! props.put(Context.SECURITY_PRINCIPAL, this.profile.getProperty(ConnectionMetaData.PRINCIPAL)); ! props.put(Context.SECURITY_CREDENTIALS, this.profile.getProperty(ConnectionMetaData.CREDENTIALS)); ! ! InitialContext context = new InitialContext(props); ! Object ref = context.lookup(this.profile.getProperty(ConnectionMetaData.CONTEXT)); ! ! Class clazzAdaptorHome = Thread.currentThread().getContextClassLoader().loadClass("org.jboss.jmx.adaptor.interfaces.AdaptorHome"); ! Object home = PortableRemoteObject.narrow(ref, clazzAdaptorHome); ! Method createMethod = clazzAdaptorHome.getMethod("create", new Class[0]); ! this.adaptor = createMethod.invoke(home, new Object[0]); ! ! MBeanServer server = MBeanServerProxy.createMBeanProxy(this.adaptor); ! this.setMBeanServer(server); ! } ! } Index: JBoss30RMIConnectionService.java =================================================================== RCS file: /cvsroot/ejtools/applications/jmx.browser/src/main/org/ejtools/jmx/browser/model/connector/JBoss30RMIConnectionService.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** JBoss30RMIConnectionService.java 27 Nov 2003 01:13:07 -0000 1.3 --- JBoss30RMIConnectionService.java 13 Dec 2003 22:15:07 -0000 1.4 *************** *** 1,83 **** ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.jmx.browser.model.connector; ! ! import java.lang.reflect.Constructor; ! import java.lang.reflect.Method; ! import java.util.Hashtable; ! ! import javax.naming.Context; ! import javax.naming.InitialContext; ! import javax.rmi.PortableRemoteObject; ! ! import org.ejtools.jmx.MBeanServerProxy; ! import org.ejtools.jmx.browser.model.service.ConnectionMetaData; ! ! ! /** ! * @author letiembl ! * @created 4 septembre 2002 ! * @version $Revision$ ! */ ! public class JBoss30RMIConnectionService extends AbstractConnectionService ! { ! /** Description of the Field */ ! protected Object connector = null; ! ! ! /**Constructor for the JBoss30RMIConnectionService object */ ! public JBoss30RMIConnectionService() ! { ! } ! ! ! /** */ ! public void disconnect() ! { ! super.disconnect(); ! try ! { ! // Search for the stop method of the RMIConnector ! Method m = this.connector.getClass().getMethod("stop", new Class[0]); ! m.invoke(this.connector, new Object[0]); ! } ! catch (Exception e) ! { ! // Do nothing ! } ! this.setConnected(false); ! } ! ! ! ! /** ! * @exception Exception Description of the Exception ! */ ! protected void createMBeanServer() ! throws Exception ! { ! System.setProperty("jmx.serial.form", "1.1"); ! ! Hashtable props = new Hashtable(); ! props.put(Context.INITIAL_CONTEXT_FACTORY, this.profile.getProperty(ConnectionMetaData.FACTORY)); ! props.put(Context.URL_PKG_PREFIXES, this.profile.getProperty(ConnectionMetaData.PACKAGES)); ! props.put(Context.PROVIDER_URL, this.profile.getProperty(ConnectionMetaData.URL)); ! props.put(Context.SECURITY_PRINCIPAL, this.profile.getProperty(ConnectionMetaData.PRINCIPAL)); ! props.put(Context.SECURITY_CREDENTIALS, this.profile.getProperty(ConnectionMetaData.CREDENTIALS)); ! ! InitialContext context = new InitialContext(props); ! Object ref = context.lookup(this.profile.getProperty(ConnectionMetaData.CONTEXT)); ! ! Class clazzAdaptor = Thread.currentThread().getContextClassLoader().loadClass("org.jboss.jmx.adaptor.rmi.RMIAdaptor"); ! Object adaptor = PortableRemoteObject.narrow(ref, clazzAdaptor); ! Class clazzConnector = Thread.currentThread().getContextClassLoader().loadClass("org.jboss.jmx.connector.rmi.RMIConnectorImpl"); ! Constructor constructor = clazzConnector.getConstructor(new Class[]{clazzAdaptor}); ! this.connector = constructor.newInstance(new Object[]{adaptor}); ! ! this.setMBeanServer(MBeanServerProxy.createMBeanProxy(this.connector)); ! } ! } --- 1,83 ---- ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.jmx.browser.model.connector; ! ! import java.lang.reflect.Constructor; ! import java.lang.reflect.Method; ! import java.util.Hashtable; ! ! import javax.naming.Context; ! import javax.naming.InitialContext; ! import javax.rmi.PortableRemoteObject; ! ! import org.ejtools.jmx.MBeanServerProxy; ! import org.ejtools.jmx.browser.model.service.ConnectionMetaData; ! ! ! /** ! * @author letiembl ! * @created 4 septembre 2002 ! * @version $Revision$ ! */ ! public class JBoss30RMIConnectionService extends AbstractConnectionService ! { ! /** Description of the Field */ ! protected Object connector = null; ! ! ! /**Constructor for the JBoss30RMIConnectionService object */ ! public JBoss30RMIConnectionService() ! { ! } ! ! ! /** */ ! public void disconnect() ! { ! super.disconnect(); ! try ! { ! // Search for the stop method of the RMIConnector ! Method m = this.connector.getClass().getMethod("stop", new Class[0]); ! m.invoke(this.connector, new Object[0]); ! } ! catch (Exception e) ! { ! // Do nothing ! } ! this.setConnected(false); ! } ! ! ! ! /** ! * @exception Exception Description of the Exception ! */ ! protected void createMBeanServer() ! throws Exception ! { ! System.setProperty("jmx.serial.form", "1.1"); ! ! Hashtable props = new Hashtable(); ! props.put(Context.INITIAL_CONTEXT_FACTORY, this.profile.getProperty(ConnectionMetaData.FACTORY)); ! props.put(Context.URL_PKG_PREFIXES, this.profile.getProperty(ConnectionMetaData.PACKAGES)); ! props.put(Context.PROVIDER_URL, this.profile.getProperty(ConnectionMetaData.URL)); ! props.put(Context.SECURITY_PRINCIPAL, this.profile.getProperty(ConnectionMetaData.PRINCIPAL)); ! props.put(Context.SECURITY_CREDENTIALS, this.profile.getProperty(ConnectionMetaData.CREDENTIALS)); ! ! InitialContext context = new InitialContext(props); ! Object ref = context.lookup(this.profile.getProperty(ConnectionMetaData.CONTEXT)); ! ! Class clazzAdaptor = Thread.currentThread().getContextClassLoader().loadClass("org.jboss.jmx.adaptor.rmi.RMIAdaptor"); ! Object adaptor = PortableRemoteObject.narrow(ref, clazzAdaptor); ! Class clazzConnector = Thread.currentThread().getContextClassLoader().loadClass("org.jboss.jmx.connector.rmi.RMIConnectorImpl"); ! Constructor constructor = clazzConnector.getConstructor(new Class[]{clazzAdaptor}); ! this.connector = constructor.newInstance(new Object[]{adaptor}); ! ! this.setMBeanServer(MBeanServerProxy.createMBeanProxy(this.connector)); ! } ! } |