User: schaefera
Date: 01/09/14 20:06:49
Modified: src/main/org/jboss/jmx/connector ConnectorFactoryImpl.java
ConnectorFactoryService.java
ConnectorFactoryServiceMBean.java JMXConnector.java
Added: src/main/org/jboss/jmx/connector TestClient.java
Log:
Added some fixes, reorganized the packaging therefore that the Test Client
is outside of RMI/EJB Connector and utilize both Connectors.
NOTE that the Test Client as well as the Test Server (for RMI Connector)
is not there to replace JUnit test cases but to allow to test the components
outside of JBoss.
Revision Changes Path
1.2 +104 -20 jboss/src/main/org/jboss/jmx/connector/ConnectorFactoryImpl.java
Index: ConnectorFactoryImpl.java
===================================================================
RCS file:
/cvsroot/jboss/jboss/src/main/org/jboss/jmx/connector/ConnectorFactoryImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ConnectorFactoryImpl.java 2001/09/12 01:49:06 1.1
+++ ConnectorFactoryImpl.java 2001/09/15 03:06:49 1.2
@@ -19,11 +19,14 @@
import javax.management.ObjectInstance;
import javax.management.ObjectName;
+import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NameClassPair;
import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
import org.jboss.jmx.connector.JMXConnector;
+import org.jboss.jmx.connector.ejb.EJBConnector;
import org.jboss.jmx.connector.rmi.RMIClientConnectorImpl;
/**
@@ -31,9 +34,8 @@
* 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
+ * @author <A href="mailto:[EMAIL PROTECTED]">Andreas "Mad"
Schaefer</A>
+ * @created May 2, 2001
**/
public class ConnectorFactoryImpl {
@@ -44,14 +46,38 @@
// Attributes ----------------------------------------------------
private MBeanServer mServer;
+ private int mNotificationType = JMXConnector.NOTIFICATION_TYPE_RMI;
+ private String mJMSName;
+ private String mEJBAdaptorName = "ejb/jmx/ejb/Adaptor";
-
// Public --------------------------------------------------------
public ConnectorFactoryImpl(
MBeanServer pServer
) {
+ this( pServer, null, null );
+ }
+
+ public ConnectorFactoryImpl(
+ MBeanServer pServer,
+ String pJMSQueueName
+ ) {
+ this( pServer, pJMSQueueName, "ejb/jmx/ejb/adaptor" );
+ }
+
+ public ConnectorFactoryImpl(
+ MBeanServer pServer,
+ String pJMSName,
+ String pEJBAdaptorName
+ ) {
mServer = pServer;
+ if( pJMSName != null ) {
+ mNotificationType = JMXConnector.NOTIFICATION_TYPE_JMS;
+ mJMSName = pJMSName;
+ }
+ if( pEJBAdaptorName != null && pEJBAdaptorName.trim().length() > 0 ) {
+ mEJBAdaptorName = pEJBAdaptorName;
+ }
}
/**
@@ -67,11 +93,14 @@
Vector lConnectors = new Vector();
try {
InitialContext lNamingServer = new InitialContext( pProperties );
+ // AS Check if the lItem.getName() (below) is the right server name or if
the
+ // lJNDIServer should be used
+ String lJNDIServer = (String) lNamingServer.getEnvironment().get(
Context.PROVIDER_URL );
// Lookup the JNDI server
NamingEnumeration enum = lNamingServer.list( "" );
while( enum.hasMore() ) {
NameClassPair lItem = ( NameClassPair ) enum.next();
- ConnectorName lName = pTester.check( lItem.getName(), lItem.getClass()
);
+ ConnectorName lName = pTester.check( lNamingServer, lItem );
if( lName != null ) {
lConnectors.add( lName );
}
@@ -95,10 +124,12 @@
ConnectorName pConnector
) {
JMXConnector lConnector = null;
- // At the moment only RMI protocol is supported (on the client side)
+ // At the moment only RMI and EJB protocol is supported (on the client side)
if( pConnector.getProtocol().equals( "rmi" ) ) {
try {
lConnector = new RMIClientConnectorImpl(
+ mNotificationType,
+ new String[] { mJMSName },
pConnector.getServer()
);
mServer.registerMBean(
@@ -110,6 +141,23 @@
e.printStackTrace();
}
}
+ else if( pConnector.getProtocol().equals( "ejb" ) ) {
+ try {
+ lConnector = new EJBConnector(
+ mNotificationType,
+ new String[] { mJMSName },
+ pConnector.getJNDIName(),
+ pConnector.getServer()
+ );
+ mServer.registerMBean(
+ lConnector,
+ new ObjectName( "JBOSS-SYSTEM:name=EJBConnectorTo" +
pConnector.getServer() )
+ );
+ }
+ catch( Exception e ) {
+ e.printStackTrace();
+ }
+ }
return lConnector;
}
@@ -121,8 +169,8 @@
public void removeConnection(
ConnectorName pConnector
) {
- if( pConnector.getProtocol().equals( "rmi" ) ) {
- try {
+ try {
+ if( pConnector.getProtocol().equals( "rmi" ) ) {
Set lConnectors = mServer.queryMBeans(
new ObjectName( "JBOSS-SYSTEM:name=RMIConnectorTo" +
pConnector.getServer() ),
null
@@ -143,10 +191,31 @@
}
}
}
- catch( Exception e ) {
- e.printStackTrace();
+ else if( pConnector.getProtocol().equals( "ejb" ) ) {
+ Set lConnectors = mServer.queryMBeans(
+ new ObjectName( "JBOSS-SYSTEM:name=EJBConnectorTo" +
pConnector.getServer() ),
+ null
+ );
+ 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()
+ );
+ }
+ }
}
}
+ catch( Exception e ) {
+ e.printStackTrace();
+ }
}
/**
@@ -165,7 +234,7 @@
*
* @return Connector Name instance if valid otherwise null
**/
- public ConnectorName check( String pName, Class pClass );
+ public ConnectorName check( Context pContext, NameClassPair pPair );
}
@@ -178,17 +247,33 @@
implements IConnectorTester
{
- public ConnectorName check( String pName, Class pClass ) {
+ public ConnectorName check( Context pContext, NameClassPair pPair ) {
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 );
+ if( pPair != null ) {
+ String lName = pPair.getName();
+ if( lName.startsWith( "jmx:" ) ) {
+ // Server-side Connector registered as MBean
+ StringTokenizer lTokens = new StringTokenizer( lName, ":" );
+ if( lTokens.hasMoreTokens() && lTokens.nextToken().equals( "jmx" ) )
{
+ if( lTokens.hasMoreTokens() ) {
+ String lServer = lTokens.nextToken();
+ if( lTokens.hasMoreTokens() ) {
+ lConnector = new ConnectorName( lServer,
lTokens.nextToken(), lName );
+ }
+ }
+ }
+ }
+ if( lName.equals( "ejb" ) ) {
+ try {
+ Context lContext = (Context) pContext.lookup( "ejb" );
+ lContext = (Context) lContext.lookup( "jmx" );
+ lContext = (Context) lContext.lookup( "ejb" );
+ if( lContext.lookup( "Adaptor" ) != null ) {
+ lConnector = new ConnectorName( "" +
pContext.getEnvironment().get( Context.PROVIDER_URL ), "ejb", "ejb/jmx/ejb/Adaptor" );
}
}
+ catch( NamingException ne ) {
+ }
}
}
return lConnector;
@@ -252,4 +337,3 @@
}
}
-
1.2 +28 -16
jboss/src/main/org/jboss/jmx/connector/ConnectorFactoryService.java
Index: ConnectorFactoryService.java
===================================================================
RCS file:
/cvsroot/jboss/jboss/src/main/org/jboss/jmx/connector/ConnectorFactoryService.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ConnectorFactoryService.java 2001/09/12 01:49:06 1.1
+++ ConnectorFactoryService.java 2001/09/15 03:06:49 1.2
@@ -6,8 +6,6 @@
*/
package org.jboss.jmx.connector;
-// import java.util.Arrays;
-// import java.util.Collection;
import java.util.Iterator;
import java.util.Hashtable;
@@ -43,13 +41,34 @@
private MBeanServer mServer;
/** Connector Factory instance **/
private ConnectorFactoryImpl mFactory;
+ private String mJMSName;
+ private String mEJBAdaptorName;
// Public --------------------------------------------------------
- public ConnectorFactoryService(
- ) {
+ public ConnectorFactoryService() {
}
+ public String getJMSName() {
+ return mJMSName;
+ }
+
+ public void setJMSName( String pName ) {
+ mJMSName = pName;
+ }
+
+ public String getEJBAdaptorName() {
+ return mEJBAdaptorName;
+ }
+
+ public void setEJBAdaptorName( String pName ) {
+ if( pName == null ) {
+ mEJBAdaptorName = "ejb/jmx/ejb/adaptor";
+ } else {
+ mEJBAdaptorName = pName;
+ }
+ }
+
public Iterator getConnectors( Hashtable pProperties,
ConnectorFactoryImpl.IConnectorTester pTester ) {
return mFactory.getConnectors( pProperties, pTester );
}
@@ -71,9 +90,11 @@
ObjectName pName
) throws javax.management.MalformedObjectNameException {
mServer = pServer;
- System.out.println( "ConnectorFactoryService.getObjectName(), server:
" + mServer +
+ System.out.println(
+ "ConnectorFactoryService.getObjectName(), server: " + mServer +
", object name: " + OBJECT_NAME +
- ", instance: " + new ObjectName( OBJECT_NAME ) );
+ ", instance: " + new ObjectName( OBJECT_NAME )
+ );
return new ObjectName( OBJECT_NAME );
}
@@ -83,21 +104,12 @@
// Protected -----------------------------------------------------
protected void initService() throws Exception {
- mFactory = new ConnectorFactoryImpl( mServer );
+ mFactory = new ConnectorFactoryImpl( mServer, mJMSName, mEJBAdaptorName );
}
protected void startService() throws Exception {
-//AS new InitialContext().bind( JNDI_NAME, mFactory );
}
protected void stopService() {
-/* AS
- try {
- new InitialContext().unbind(JNDI_NAME);
- }
- catch( Exception e ) {
- log.exception( e );
- }
-*/
}
}
1.2 +46 -20
jboss/src/main/org/jboss/jmx/connector/ConnectorFactoryServiceMBean.java
Index: ConnectorFactoryServiceMBean.java
===================================================================
RCS file:
/cvsroot/jboss/jboss/src/main/org/jboss/jmx/connector/ConnectorFactoryServiceMBean.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ConnectorFactoryServiceMBean.java 2001/09/12 01:49:06 1.1
+++ ConnectorFactoryServiceMBean.java 2001/09/15 03:06:49 1.2
@@ -6,8 +6,6 @@
*/
package org.jboss.jmx.connector;
-// import java.util.Arrays;
-// import java.util.Collection;
import java.util.Iterator;
import java.util.Hashtable;
@@ -35,32 +33,60 @@
// Public --------------------------------------------------------
/**
- * 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
- **/
+ * @return JMS Queue Name and if not null then JMS will be used
+ **/
+ public String getJMSName();
+
+ /**
+ * Sets the JMS Queue Factory Name which allows the server to send
+ * the notifications asynchronous to the client
+ *
+ * @param pName If null the notification will be transferred
+ * by using RMI Callback objects otherwise it
+ * will use JMS
+ **/
+ public void setJMSName( String pName );
+
+ /**
+ * @return EJB Adaptor JNDI Name used by the EJB-Connector
+ **/
+ public String getEJBAdaptorName();
+
+ /**
+ * Sets the JNDI Name of the EJB-Adaptor
+ *
+ * @param pName If null the default JNDI name (ejb/jmx/ejb/adaptor) will
+ * be used for EJB-Connectors otherwise it will use this one
+ **/
+ public void setEJBAdaptorName( String pName );
+
+ /**
+ * 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
- **/
+ * 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
- **/
+ * 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
);
1.2 +14 -1 jboss/src/main/org/jboss/jmx/connector/JMXConnector.java
Index: JMXConnector.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/jmx/connector/JMXConnector.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JMXConnector.java 2001/09/12 01:49:06 1.1
+++ JMXConnector.java 2001/09/15 03:06:49 1.2
@@ -29,6 +29,7 @@
import javax.management.ListenerNotFoundException;
import javax.management.MBeanException;
import javax.management.MBeanRegistrationException;
+import javax.management.MBeanServer;
import javax.management.NotCompliantMBeanException;
import javax.management.OperationsException;
import javax.management.ReflectionException;
@@ -49,11 +50,23 @@
* @author <A href="mailto:[EMAIL PROTECTED]">Andreas "Mad"
Schaefer</A>
**/
public interface JMXConnector
-//AS extends MBeanServer
+ extends MBeanServer
{
// Constants -----------------------------------------------------
+ /**
+ * If this type is used and you specify a valid QueueConnectorFactory
+ * then this connector will use JMS to transfer the events asynchronous
+ * back from the server to the client.
+ **/
+ public static final int NOTIFICATION_TYPE_JMS = 0;
+ /**
+ * If this type is used the Connector will use RMI Callback Objects to
+ * transfer the events back from the server synchronously.
+ **/
+ public static final int NOTIFICATION_TYPE_RMI = 1;
+
// Public --------------------------------------------------------
/**
1.1 jboss/src/main/org/jboss/jmx/connector/TestClient.java
Index: TestClient.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.jmx.connector;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Collection;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Vector;
import javax.management.Attribute;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanException;
import javax.management.MBeanInfo;
import javax.management.MBeanOperationInfo;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.Notification;
import javax.management.NotificationFilter;
import javax.management.NotificationListener;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import javax.management.ReflectionException;
import javax.management.RuntimeErrorException;
import javax.management.RuntimeMBeanException;
import javax.management.RuntimeOperationsException;
import javax.naming.InitialContext;
/**
* Test Client for the JMX Client Connector. It cretes a local MBeanServer and
* adds the ConnectorFactory as first MBean. Then it will use the ConnectorFactory
* to local servers on the net and then to locate its offered protocols (Server
* side Connectors). After the user selected and server and a protocol its
* client-side connector will be loaded through the ConnectorFactory and a
* connection to the server will be established. Now the offered MBean on the
* remote server and its attributes and operations will be listed and at
* the end this test client will add a notification listener to all MBeans
* on the remote server. The user can now wait for a notification because
* the client will be up and running. If the user stops the client by
* <CTRL>-C it will stop and deregister the selected Connector (locally)
* and this will remove all the registered listeners.
*
* @see <related>
* @author Andreas Schaefer ([EMAIL PROTECTED])
**/
public class TestClient {
// Constants ----------------------------------------------------->
// Attributes ---------------------------------------------------->
// Static --------------------------------------------------------
public static void main(String[] args)
throws Exception
{
try {
System.out.println( );
getUserInput(
"Testing JMX Connectors\n" +
"======================\n\n" +
"1. Instantiate local MBeanServer and add connector " +
"factory as first MBean to search your net\n" +
"=> hit any key to proceed"
);
// First create a MBeanServer and let it start
final MBeanServer lLocalServer =
MBeanServerFactory.createMBeanServer();
// Then register the connector factory
final ObjectInstance lFactoryInstance =
lLocalServer.createMBean(
"org.jboss.jmx.connector.ConnectorFactoryService",
new ObjectName( lLocalServer.getDefaultDomain(),
"name", "ConnectorFactory" )
);
System.out.println( "Found Factory: " +
lFactoryInstance.getObjectName() );
lLocalServer.invoke(
lFactoryInstance.getObjectName(),
"init",
new Object[] {},
new String[] {}
);
lLocalServer.invoke(
lFactoryInstance.getObjectName(),
"start",
new Object[] {},
new String[] {}
);
int lType = -1;
while( lType != 1 && lType != 2 ) {
lType = getUserInput(
"\n" +
"2. Do you want to use RMI or JMS to transfer Notifications\n" +
"=> enter 1 from RMI or 2 for JMS and then hit enter"
);
System.out.println( "Type: " + lType );
}
switch( lType ) {
case 1:
lType = JMXConnector.NOTIFICATION_TYPE_RMI;
break;
case 2:
lType = JMXConnector.NOTIFICATION_TYPE_JMS;
}
String lJMSName = null;
if( lType == JMXConnector.NOTIFICATION_TYPE_JMS ) {
while( lJMSName == null || lJMSName.trim().length() == 0 ) {
lJMSName = getUserInputLine(
"\n" +
"2.a. Enter the JMS Queue Factory Name and hit enter\n"
);
}
}
lLocalServer.setAttribute(
lFactoryInstance.getObjectName(),
new Attribute( "JMSName", lJMSName )
);
String lEJBAdaptorName = getUserInputLine(
"\n" +
"3. When you are expecting EJB-Connectors and the EJB-Adaptor\n" +
" and the EJB-Adaptor does not have the default JNDI-Name then\n" +
" then specified it here and hit enter\n"
);
if( lEJBAdaptorName == null || lEJBAdaptorName.trim().length() == 0 ) {
lEJBAdaptorName = null;
}
lLocalServer.setAttribute(
lFactoryInstance.getObjectName(),
new Attribute( "EJBAdaptorName", lEJBAdaptorName )
);
getUserInput(
"\n" +
"4. Lookup for all available connectors with the JNDI
defined by jndi.properties\n" +
"=> hit any key to proceed"
);
// Now let's list the available JMX Connectors
InitialContext lContext = null;
try {
lContext = new InitialContext();
}
catch( Exception e ) {
e.printStackTrace();
}
Hashtable lProperties = lContext.getEnvironment();
ConnectorFactoryImpl.JBossConnectorTester lTester = new
ConnectorFactoryImpl.JBossConnectorTester();
Iterator lConnectors = (Iterator) lLocalServer.invoke(
lFactoryInstance.getObjectName(),
"getConnectors",
new Object[] {
lProperties,
lTester
},
new String[] {
Hashtable.class.getName(),
ConnectorFactoryImpl.IConnectorTester.class.getName()
}
);
int lCount = 0;
StringBuffer lMessage = new StringBuffer();
lMessage.append( "List of all available connectors on your
net\n" );
lMessage.append( "=========================================\n"
);
Vector lTemp = new Vector();
while( lConnectors.hasNext() ) {
ConnectorFactoryImpl.ConnectorName lName =
(ConnectorFactoryImpl.ConnectorName) lConnectors.next();
lTemp.addElement( lName );
lMessage.append( " - " + ( lCount++ ) + ". connector
is: " + lName + "\n" );
}
int lChoice = -1;
while( lChoice < 0 || lChoice > lTemp.size() ) {
lMessage.append( "\n" );
lMessage.append( "5. Select your connector by entering its number\n" );
lMessage.append( "=> hit any key to proceed" );
lChoice = getUserInput( lMessage.toString() );
}
final ConnectorFactoryImpl.ConnectorName lConnectorName =
(ConnectorFactoryImpl.ConnectorName) lTemp.get( lChoice );
lMessage.setLength( 0 );
lMessage.append(
"\n" +
"You selected connector: " + lConnectorName + "\n\n"
);
getUserInput(
lMessage.toString() + "\n" +
"6. Connect to the given connector\n" +
"=> hit any key to proceed"
);
lMessage.setLength( 0 );
// Take the first server and its first protoccol and create a
// connection to the remote MBeanServer
JMXConnector lConnector = (JMXConnector) lLocalServer.invoke(
lFactoryInstance.getObjectName(),
"createConnection",
new Object[] {
lConnectorName
},
new String[] {
lConnectorName.getClass().getName()
}
);
getUserInput(
"\n" +
"7. List all available MBeans and its attributes\n" +
"=> hit any key to proceed"
);
// List all services
listServices( lConnector );
getUserInput(
"\n" +
"8. Try to add a listener to all available MBeans.\n" +
"Please note that this will keep this test client up
and running waiting\n" +
"for an event from the server. If there is no event
comming then try\n" +
"to shutdown the JBoss server.\n" +
"To end this test client just hit <CTRL>-C\n"+
"=> hit any key to proceed"
);
// Try to register to all available, remote MBeans
registerListeners( lConnector );
// Add shutdown hook to remove the connection before shut down
try {
Runtime.getRuntime().addShutdownHook(
new Thread() {
public void run() {
System.err.println( "Shutdown"
);
try {
lLocalServer.invoke(
lFactoryInstance.getObjectName(),
"removeConnection",
new Object[] {
lConnectorName
},
new String[] {
lConnectorName.getClass().getName()
}
);
System.err.println("Shutting done");
}
catch( Throwable e ) {
e.printStackTrace();
}
}
}
);
System.out.println ("Shutdown hook added");
}
catch ( Throwable e ) {
System.out.println( "Could not add shutdown hook" );
// JDK 1.2.. ignore!
}
}
catch( RuntimeMBeanException rme ) {
System.err.println( "TestClient.main(), caught: " + rme +
", target: " + rme.getTargetException() );
rme.printStackTrace();
}
catch( MBeanException me ) {
System.err.println( "TestClient.main(), caught: " + me +
", target: " + me.getTargetException() );
me.printStackTrace();
}
catch( RuntimeErrorException rte ) {
System.err.println( "TestClient.main(), caught: " + rte +
", target: " + rte.getTargetError() );
rte.printStackTrace();
}
catch( ReflectionException re ) {
System.err.println( "TestClient.main(), caught: " + re +
", target: " + re.getTargetException() );
re.printStackTrace();
}
catch( Exception e ) {
System.err.println( "TestClient.main(), caught: " + e );
e.printStackTrace();
}
}
// Constructors -------------------------------------------------->
// Public --------------------------------------------------------
public static void listServices( JMXConnector pConnector )
throws Exception
{
try {
Iterator i = pConnector.queryMBeans( null, null ).iterator();
while( i.hasNext() ) {
MBeanInfo info = pConnector.getMBeanInfo( (
(ObjectInstance) i.next() ).getObjectName() );
System.out.println( "MBean: " + info.getClassName() );
MBeanAttributeInfo[] aInfos = info.getAttributes();
for( int k = 0; k < aInfos.length; k++ ) {
System.out.println( "\t" + k + ". Attribute: "
+
aInfos[ k ].getName() );
}
MBeanOperationInfo[] oInfos = info.getOperations();
for( int k = 0; k < oInfos.length; k++ ) {
System.out.println( "\t" + k + ". Operation: "
+
oInfos[ k ].getName() );
}
}
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void registerListeners( JMXConnector pConnector )
throws Exception
{
try {
// Add a listener to all of the available MBeans
Iterator i = pConnector.queryMBeans( null, null ).iterator();
int j = 0;
while( i.hasNext() ) {
ObjectInstance lBean = (ObjectInstance) i.next();
try {
pConnector.addNotificationListener(
lBean.getObjectName(),
(NotificationListener) new Listener(),
(NotificationFilter) null,
new NotSerializableHandback(
lBean.getObjectName() + "" +
j++
)
);
System.out.println( "Added notification
listener to: " + lBean.getObjectName() );
}
catch( RuntimeOperationsException roe ) {
System.out.println( "Could not add listener
to: " + lBean.getObjectName() +
", reason could be that it is not a
broadcaster" );
}
catch( Exception e ) {
e.printStackTrace();
}
}
}
catch (Exception e) {
e.printStackTrace();
}
}
// Protected -----------------------------------------------------
// Private -------------------------------------------------------
private static int getUserInput( String lMessage ) {
int lReturn = -1;
try {
String lInput = getUserInputLine( lMessage );
lReturn = new Integer( lInput ).intValue();
}
catch( NumberFormatException nfe ) {
}
catch( Exception e ) {
e.printStackTrace();
}
return lReturn;
}
private static String getUserInputLine( String lMessage ) {
String lReturn = "";
try {
System.out.println( lMessage );
lReturn = new BufferedReader( new InputStreamReader( System.in )
).readLine();
}
catch( Exception e ) {
e.printStackTrace();
}
return lReturn;
}
private static class Listener implements NotificationListener {
public void handleNotification(
Notification pNotification,
Object pHandback
) {
System.out.println( "Got notification: " + pNotification +
", from: " + pHandback );
}
}
private static class NotSerializableHandback {
private static int miCounter = 0;
private String mName;
public NotSerializableHandback( String pName ) {
mName = pName + "[ " + miCounter++ + " ]";
}
public String toString() {
return "NotSerializableHandback[ " + mName + " ]";
}
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development