User: schaefera
Date: 01/05/04 14:18:06
Modified: src/main/org/jboss/jmx/client ConnectorFactoryImpl.java
ConnectorFactoryService.java
ConnectorFactoryServiceMBean.java
Log:
Revamp the Connector Factory allowing the client to look for JMX Connectors
in a more general way. The getServers() and getProtocols() is replaced by
getConnectors() returning a list of Connectors delivered from the specified
JNDI server (found by the specified Connector Tester instance).
Revision Changes Path
1.6 +230 -210 jboss/src/main/org/jboss/jmx/client/ConnectorFactoryImpl.java
Index: ConnectorFactoryImpl.java
===================================================================
RCS file:
/cvsroot/jboss/jboss/src/main/org/jboss/jmx/client/ConnectorFactoryImpl.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ConnectorFactoryImpl.java 2000/12/07 18:16:11 1.5
+++ ConnectorFactoryImpl.java 2001/05/04 21:18:05 1.6
@@ -9,6 +9,7 @@
import java.util.Arrays;
import java.util.Collection;
+import java.util.Hashtable;
import java.util.Iterator;
import java.util.Set;
import java.util.StringTokenizer;
@@ -26,216 +27,235 @@
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 "Mad"
Schaefer</A>
-**/
+ * 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
+ * "Mad" Schaefer</A>
+ *@created May 2, 2001
+ **/
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 pProtocol Servers supporting this protocol if
not null
- * or empty otherwise it
will be ignored
- * @param pServerQuery Query instance to filter the list of servers
- *
- * @return A collection of available
servers
- * names/identifications
(String)
- **/
- public Collection getServers(
- String pProtocol
-//AS ServerQuery pServerQuery
- ) {
- System.out.println( "ConnectorFactoryImpl.getServers(), protocol: " +
pProtocol );
- // Check if there is a protocol given to query for
- boolean lProtocolQuery = pProtocol != null && pProtocol.length() > 0;
- // Get all available connectors from the JNDI server
- Iterator lConnectors = getConnectorList();
- Vector lServers = new Vector();
- // Go through the connectors list and check if part of the list
- while( lConnectors.hasNext() ) {
- ConnectorObject lConnector = (ConnectorObject)
lConnectors.next();
- if( !lProtocolQuery ||
lConnector.getProtocol().equalsIgnoreCase( pProtocol ) ) {
- lServers.add( lConnector.getServer() );
- }
- }
- return lServers;
- }
-
- /**
- * Returns a list of available protocols (connectors)
- *
- * @param pServer Server name/identification to look up
if not
- * null or empty
otherwise it will be ignored
- *
- * @return A collection of available
protocols (String)
- **/
- public Collection getProtocols(
- String pServer
- ) {
- // Check if there is a protocol given to query for
- boolean lServerQuery = pServer != null && pServer.length() > 0;
- // Get all available connectors from the JNDI server
- Iterator lConnectors = getConnectorList();
- Vector lProtocols = new Vector();
- // Go through the connectors list and check if part of the list
- while( lConnectors.hasNext() ) {
- ConnectorObject lConnector = (ConnectorObject)
lConnectors.next();
- if( !lServerQuery || lConnector.getServer().equalsIgnoreCase(
pServer ) ) {
- lProtocols.add( lConnector.getProtocol() );
- }
- }
- return lProtocols;
- }
-
- /**
- * 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;
- // At the moment only RMI protocol is supported (on the client side)
- 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( 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();
- }
- }
- }
-
- private Iterator getConnectorList() {
- Vector lServers = new Vector();
- try {
- InitialContext lNamingServer = new InitialContext();
- // Lookup the JNDI server
- NamingEnumeration enum = lNamingServer.list( "" );
- while( enum.hasMore() ) {
- NameClassPair lItem = (NameClassPair) enum.next();
- System.out.println( "Naming Server item: " + lItem );
- ConnectorObject lConnector = new ConnectorObject(
lItem.getName() );
- if( lConnector.isValid() ) {
- lServers.add( lConnector );
- }
- }
- }
- catch( Exception e ) {
- e.printStackTrace();
- }
-
- return lServers.iterator();
- }
- /**
- * If valid then it will containg the informations about a
- * remote JMX Connector
- **/
- private class ConnectorObject {
- private String mServerName = "";
- private String mProtocolName = "";
- private boolean mIsValid = false;
-
- public ConnectorObject( String pName ) {
- if( pName != null || pName.length() > 0 ) {
- StringTokenizer lName = new StringTokenizer( pName,
":" );
- if( lName.countTokens() == 3 ) {
- // Ignore "jmx"
- lName.nextToken();
- mServerName = lName.nextToken();
- mProtocolName = lName.nextToken();
- mIsValid = true;
- }
- }
- }
-
- public boolean isValid() {
- return mIsValid;
- }
-
- public String getProtocol() {
- return mProtocolName;
- }
-
- public String getServer() {
- return mServerName;
- }
- }
+ // Constants -----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ private MBeanServer mServer;
+
+
+ // Public --------------------------------------------------------
+
+ public ConnectorFactoryImpl(
+ MBeanServer pServer
+ ) {
+ mServer = pServer;
+ }
+
+ /**
+ * Look up for all registered JMX Connector at a given JNDI server
+ *
+ * @param pProperties List of properties defining the JNDI server
+ * @param pTester Connector Tester implementation to be used
+ *
+ * @return An iterator on the list of ConnectorNames representing
+ * the found JMX Connectors
+ **/
+ public Iterator getConnectors( Hashtable pProperties, IConnectorTester pTester )
{
+ Vector lConnectors = new Vector();
+ try {
+ InitialContext lNamingServer = new InitialContext( pProperties );
+ // Lookup the JNDI server
+ NamingEnumeration enum = lNamingServer.list( "" );
+ while( enum.hasMore() ) {
+ NameClassPair lItem = ( NameClassPair ) enum.next();
+ System.out.println( "Naming Server item: " + lItem );
+ ConnectorName lName = pTester.check( lItem.getName(), lItem.getClass()
);
+ if( lName != null ) {
+ lConnectors.add( lName );
+ }
+ }
+ }
+ catch( Exception e ) {
+ e.printStackTrace();
+ }
+
+ return lConnectors.iterator();
+ }
+
+ /**
+ * Initiate a connection to the given server with the given protocol
+ *
+ * @param pConnector Connector Name used to identify the remote JMX Connector
+ *
+ * @return JMX Connector or null if server or protocol is not supported
+ **/
+ public JMXConnector createConnection(
+ ConnectorName pConnector
+ ) {
+ JMXConnector lConnector = null;
+ // At the moment only RMI protocol is supported (on the client side)
+ if( pConnector.getProtocol().equals( "rmi" ) ) {
+ try {
+ lConnector = new RMIClientConnectorImpl(
+ pConnector.getServer()
+ );
+ mServer.registerMBean(
+ lConnector,
+ new ObjectName( "DefaultDomain:name=RMIConnectorTo" +
pConnector.getServer() )
+ );
+ }
+ catch( Exception e ) {
+ e.printStackTrace();
+ }
+ }
+ System.out.println( "ConnectorFactoryImpl.createConnection(), got connector:
" + lConnector );
+ return lConnector;
+ }
+
+ /**
+ * Removes the given connection and frees the resources
+ *
+ * @param pConnector Connector Name used to identify the remote JMX Connector
+ **/
+ public void removeConnection(
+ ConnectorName pConnector
+ ) {
+ if( pConnector.getProtocol().equals( "rmi" ) ) {
+ try {
+ Set lConnectors = mServer.queryMBeans(
+ new ObjectName( "DefaultDomain:name=RMIConnectorTo" +
pConnector.getServer() ),
+ 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();
+ }
+ }
+ }
+
+ /**
+ * Interface defined a Connector Tester to verify JMX Connectors
+ * based on the information delivered by a JNDI server
+ *
+ * @author Andreas "Mad" Schaefer ([EMAIL PROTECTED])
+ **/
+ public static interface IConnectorTester {
+
+ /**
+ * Checks a given JNDI entry if it is a valid JMX Connector
+ *
+ * @param pName JNDI Name of the entry to test for
+ * @param pClass Class of the entry
+ *
+ * @return Connector Name instance if valid otherwise null
+ **/
+ public ConnectorName check( String pName, Class pClass );
+
+ }
+
+ /**
+ * Default implementation of the jBoss JMX Connector tester
+ *
+ * @author Andreas "Mad" Schaefer ([EMAIL PROTECTED])
+ **/
+ public static class JBossConnectorTester
+ implements IConnectorTester
+ {
+
+ public ConnectorName check( String pName, Class pClass ) {
+ ConnectorName lConnector = null;
+ if( pName != null || pName.length() > 0 ) {
+ StringTokenizer lName = new StringTokenizer( pName, ":" );
+ if( lName.hasMoreTokens() && lName.nextToken().equals( "jmx" ) ) {
+ if( lName.hasMoreTokens() ) {
+ String lServer = lName.nextToken();
+ if( lName.hasMoreTokens() ) {
+ lConnector = new ConnectorName( lServer, lName.nextToken(),
pName );
+ }
+ }
+ }
+ }
+ return lConnector;
+ }
+
+ }
+
+ /**
+ * Container for a JMX Connector representation
+ *
+ * @author Andreas "Mad" Schaefer ([EMAIL PROTECTED])
+ **/
+ public static class ConnectorName {
+
+ private String mServer;
+ private String mProtocol;
+ private String mJNDIName;
+
+ /**
+ * Creates a Connector Name instance
+ *
+ * @param pServer Name of the Server the JMX Connector is registered at
+ * @param pProtocol Name of the Protocol the JMX Connector supports
+ * @param pJNDIName JNDI Name the JMX Connector can be found
+ **/
+ public ConnectorName( String pServer, String pProtocol, String pJNDIName ) {
+ mServer = pServer;
+ mProtocol = pProtocol;
+ mJNDIName = pJNDIName;
+ }
+
+ /**
+ * @return Name of the Server the JMX Connector is registered at
+ **/
+ public String getServer() {
+ return mServer;
+ }
+
+ /**
+ * @return Name of the Protocol the JMX Connector supports
+ **/
+ public String getProtocol() {
+ return mProtocol;
+ }
+
+ /**
+ * @return JNDI Name the JMX Connector can be found
+ **/
+ public String getJNDIName() {
+ return mJNDIName;
+ }
+
+ /**
+ * @return Debug information about this instance
+ **/
+ public String toString() {
+ return "ConnectorName [ server: " + mServer +
+ ", protocol: " + mProtocol +
+ ", JNDI name: " + mJNDIName + " ]";
+ }
+ }
+
}
+
1.5 +20 -59 jboss/src/main/org/jboss/jmx/client/ConnectorFactoryService.java
Index: ConnectorFactoryService.java
===================================================================
RCS file:
/cvsroot/jboss/jboss/src/main/org/jboss/jmx/client/ConnectorFactoryService.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ConnectorFactoryService.java 2000/12/07 18:16:11 1.4
+++ ConnectorFactoryService.java 2001/05/04 21:18:06 1.5
@@ -7,8 +7,10 @@
package org.jboss.jmx.client;
-import java.util.Arrays;
-import java.util.Collection;
+// import java.util.Arrays;
+// import java.util.Collection;
+import java.util.Iterator;
+import java.util.Hashtable;
import javax.management.DynamicMBean;
import javax.management.ObjectName;
@@ -49,63 +51,22 @@
) {
}
- /**
- * Returns a list of available servers
- *
- * @param pProtocol Servers supporting this protocol if
not null
- * or empty otherwise it
will be ignored
- * @param pServerQuery Query instance to filter the list of servers
- *
- * @return A collection of available
servers
- * names/identifications
(String)
- **/
- public Collection getServers(
- String pProtocol
-//AS ServerQuery pServerQuery
- ) {
- System.out.println( "ConnectorFactoryService.getServers(), protocol: "
+ pProtocol );
- return mFactory.getServers( pProtocol );
- }
-
- /**
- * 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 Iterator getConnectors( Hashtable pProperties,
ConnectorFactoryImpl.IConnectorTester pTester ) {
+ System.out.println( "ConnectorFactoryService.getConnectors(),
properties: " + pProperties );
+ return mFactory.getConnectors( pProperties, pTester );
+ }
+
+ public JMXConnector createConnection(
+ ConnectorFactoryImpl.ConnectorName pConnector
+ ) {
+ return mFactory.createConnection( pConnector );
+ }
+
+ public void removeConnection(
+ ConnectorFactoryImpl.ConnectorName pConnector
+ ) {
+ mFactory.removeConnection( pConnector );
+ }
public ObjectName getObjectName(
MBeanServer pServer,
1.4 +35 -50
jboss/src/main/org/jboss/jmx/client/ConnectorFactoryServiceMBean.java
Index: ConnectorFactoryServiceMBean.java
===================================================================
RCS file:
/cvsroot/jboss/jboss/src/main/org/jboss/jmx/client/ConnectorFactoryServiceMBean.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ConnectorFactoryServiceMBean.java 2000/12/07 15:44:53 1.3
+++ ConnectorFactoryServiceMBean.java 2001/05/04 21:18:06 1.4
@@ -7,8 +7,10 @@
package org.jboss.jmx.client;
-import java.util.Arrays;
-import java.util.Collection;
+// import java.util.Arrays;
+// import java.util.Collection;
+import java.util.Iterator;
+import java.util.Hashtable;
import javax.management.DynamicMBean;
import javax.management.MBeanServer;
@@ -32,52 +34,35 @@
public static final String OBJECT_NAME = "Factory:name=JMX";
// Public --------------------------------------------------------
- /**
- * Returns a list of available servers
- *
- * @param pProtocol Servers supporting this protocol if
not null
- * or empty otherwise it
will be ignored
- * @param pServerQuery Query instance to filter the list of servers
- *
- * @return A collection of available
servers
- * names/identifications
(String)
- **/
- public Collection getServers(
- String pProtocol
-//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
- );
+
+ /**
+ * Look up for all registered JMX Connector at a given JNDI server
+ *
+ * @param pProperties List of properties defining the JNDI server
+ * @param pTester Connector Tester implementation to be used
+ *
+ * @return An iterator on the list of ConnectorNames representing
+ * the found JMX Connectors
+ **/
+ public Iterator getConnectors( Hashtable pProperties,
ConnectorFactoryImpl.IConnectorTester pTester );
+
+ /**
+ * Initiate a connection to the given server with the given protocol
+ *
+ * @param pConnector Connector Name used to identify the remote JMX Connector
+ *
+ * @return JMX Connector or null if server or protocol is not supported
+ **/
+ public JMXConnector createConnection(
+ ConnectorFactoryImpl.ConnectorName pConnector
+ );
+
+ /**
+ * Removes the given connection and frees the resources
+ *
+ * @param pConnector Connector Name used to identify the remote JMX Connector
+ **/
+ public void removeConnection(
+ ConnectorFactoryImpl.ConnectorName pConnector
+ );
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development