User: schaefera
Date: 01/09/11 18:49:06
Added: src/main/org/jboss/jmx/connector ConnectorFactoryImpl.java
ConnectorFactoryService.java
ConnectorFactoryServiceMBean.java JMXConnector.java
JMXConnectorMBean.java
Log:
Repackaged the JMX Connector and Adaptor for JBoss. I also added
a new EJB-Adaptor and EJB-Connector. The adaptor allows a secured
access to a local/remote JMX Server and the EJB-Connector makes
this transparent for any Java client.
Revision Changes Path
1.1 jboss/src/main/org/jboss/jmx/connector/ConnectorFactoryImpl.java
Index: ConnectorFactoryImpl.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.jmx.connector;
import java.util.Arrays;
import java.util.Collection;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.Vector;
import javax.management.DynamicMBean;
import javax.management.MBeanServer;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import javax.naming.InitialContext;
import javax.naming.NameClassPair;
import javax.naming.NamingEnumeration;
import org.jboss.jmx.connector.JMXConnector;
import org.jboss.jmx.connector.rmi.RMIClientConnectorImpl;
/**
* 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 ----------------------------------------------------
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();
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( "JBOSS-SYSTEM:name=RMIConnectorTo" +
pConnector.getServer() )
);
}
catch( Exception e ) {
e.printStackTrace();
}
}
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( "JBOSS-SYSTEM:name=RMIConnectorTo" +
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();
}
}
}
/**
* Interface defined a Connector Tester to verify JMX Connectors
* based on the information delivered by a JNDI server
*
* @author Andreas 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 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 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.1
jboss/src/main/org/jboss/jmx/connector/ConnectorFactoryService.java
Index: ConnectorFactoryService.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.jmx.connector;
// import java.util.Arrays;
// import java.util.Collection;
import java.util.Iterator;
import java.util.Hashtable;
import javax.management.DynamicMBean;
import javax.management.ObjectName;
import javax.management.MBeanServer;
import javax.naming.InitialContext;
import org.jboss.jmx.connector.JMXConnector;
import org.jboss.system.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 "Mad"
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(
) {
}
public Iterator getConnectors( Hashtable pProperties,
ConnectorFactoryImpl.IConnectorTester pTester ) {
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,
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 {
mFactory = new ConnectorFactoryImpl( mServer );
}
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.1
jboss/src/main/org/jboss/jmx/connector/ConnectorFactoryServiceMBean.java
Index: ConnectorFactoryServiceMBean.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.jmx.connector;
// import java.util.Arrays;
// import java.util.Collection;
import java.util.Iterator;
import java.util.Hashtable;
import javax.management.DynamicMBean;
import javax.management.MBeanServer;
import org.jboss.jmx.connector.JMXConnector;
import org.jboss.system.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 "Mad"
Schaefer</A>
**/
public interface ConnectorFactoryServiceMBean
extends ServiceMBean
{
// Constants -----------------------------------------------------
public static final String OBJECT_NAME = "Factory:name=JMX";
// 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
**/
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
);
}
1.1 jboss/src/main/org/jboss/jmx/connector/JMXConnector.java
Index: JMXConnector.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.ObjectInputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
import javax.management.Attribute;
import javax.management.AttributeList;
import javax.management.ObjectName;
import javax.management.QueryExp;
import javax.management.ObjectInstance;
import javax.management.NotificationFilter;
import javax.management.NotificationListener;
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;
/**
* Client-Side JMX Connector Interface.
* <BR>
* <B>Attention:<B>
* <BR>
* Please note that this interface has two purposes. First it
* adds additional runtime exception to the methods because
* of the nature of the remote connection. It also declares
* the unusable methods throwing the UnsupportedOperationException
* which is thrown always by the Connector implementation.
* The second purpose is to have interface to discuss it.
*
* @author <A href="mailto:[EMAIL PROTECTED]">Andreas "Mad"
Schaefer</A>
**/
public interface JMXConnector
//AS extends MBeanServer
{
// Constants -----------------------------------------------------
// Public --------------------------------------------------------
/**
* Instantiate the given class on the remote MBeanServer and returns a Object
* Handler you can use to register it as a MBean with {@link #registerMBean
* registerMBean()} or as a parameter to createMBean() or instantiate()
* method which takes it as a parameter.
*
* @param pClassName Class name of
the class to be loaded
*
and instantiated
*
* @return Object
handler. Please use this handler
*
to register it as MBean or as a parameter
*
in the other methods as a parameter. The
*
server-side connector will look up for
*
an object handler parameter and then
*
replace the object handler by the
*
effective object.
**/
public Object instantiate(
String pClassName
) throws
ReflectionException,
MBeanException;
public Object instantiate(
String pClassName,
ObjectName pLoaderName
) throws
ReflectionException,
MBeanException,
InstanceNotFoundException;
/**
* Instantiate the given class on the remote MBeanServer and
* returns a Object Handler you can use to register it as a
* MBean with {@link #registerMBean registerMBean()}
*
* @param pClassName Class name of
the class to be loaded
*
and instantiated
* @param pParams Array of
parameter passed to the creator
*
of the class. If one is of data type
*
Object handler it will be replaced on
*
the server-side by its effective
*
object.
* @param pSignature Array of Class
Names (full qualified)
*
to find the right parameter. When there
*
is an ObjectHandler as a parameter type
*
then it will be replaced on the server-
*
side by the class name of the effective
*
object) otherwise it will be kept.
*
* @return Object
handler. Please use this handler
*
to register it as MBean or as a parameter
*
in the other methods as a parameter. The
*
server-side connector will look up for
*
an object handler parameter and then
*
replace the object handler by the
*
effective object.
**/
public Object instantiate(
String pClassName,
Object[] pParams,
String[] pSignature
) throws
ReflectionException,
MBeanException;
public Object instantiate(
String pClassName,
ObjectName pLoaderName,
Object[] pParams,
String[] pSignature
) throws
ReflectionException,
MBeanException,
InstanceNotFoundException;
public ObjectInstance createMBean(
String pClassName,
ObjectName pName
) throws
ReflectionException,
InstanceAlreadyExistsException,
MBeanRegistrationException,
MBeanException,
NotCompliantMBeanException;
public ObjectInstance createMBean(
String pClassName,
ObjectName pName,
ObjectName pLoaderName
) throws
ReflectionException,
InstanceAlreadyExistsException,
MBeanRegistrationException,
MBeanException,
NotCompliantMBeanException,
InstanceNotFoundException;
/**
* Instantiates the given class and registers it on the remote MBeanServer and
* returns an Object Instance of the MBean.
*
* @param pClassName Class name of
the class to be loaded
*
and instantiated
* @param pNameToAssign Object Name the new
MBean should be
*
assigned to
* @param pParams Array of
parameter passed to the creator
*
of the class. If one is of data type
*
Object handler it will be replaced on
*
the server-side by its effective
*
object.
* @param pSignature Array of Class
Names (full qualified)
*
to find the right parameter. When there
*
is an ObjectHandler as a parameter type
*
then it will be replaced on the server-
*
side by the class name of the effective
*
object) otherwise it will be kept.
*
* @return Object
Instance of the new MBean
**/
public ObjectInstance createMBean(
String pClassName,
ObjectName pNameToAssign,
Object[] pParams,
String[] pSignature
) throws
ReflectionException,
InstanceAlreadyExistsException,
MBeanRegistrationException,
MBeanException,
NotCompliantMBeanException;
public ObjectInstance createMBean(
String pClassName,
ObjectName pName,
ObjectName pLoaderName,
Object[] pParams,
String[] pSignature
) throws
ReflectionException,
InstanceAlreadyExistsException,
MBeanRegistrationException,
MBeanException,
NotCompliantMBeanException,
InstanceNotFoundException;
/**
* Register the given Object (already instantiated) as a MBean on the
* remote MBeanServer
*
* @param pObjectHandler Object Handler of th
given object
*
to register as MBean
* @param pNaemToAssign Object Name to MBean
is assigned to
*
* @return Object
Instance of the new MBean
**/
public ObjectInstance registerMBean(
Object pObjectHandler,
ObjectName pNaemToAssign
) throws
InstanceAlreadyExistsException,
MBeanRegistrationException,
NotCompliantMBeanException;
public void unregisterMBean(
ObjectName pName
) throws
InstanceNotFoundException,
MBeanRegistrationException;
public ObjectInstance getObjectInstance(
ObjectName pName
) throws
InstanceNotFoundException;
public Set queryMBeans(
ObjectName pName,
QueryExp pQuery
);
public Set queryNames(
ObjectName pName,
QueryExp pQuery
);
public boolean isRegistered(
ObjectName pName
);
public boolean isInstanceOf(
ObjectName pName,
String pClassName
) throws
InstanceNotFoundException;
public Integer getMBeanCount(
);
public Object getAttribute(
ObjectName pName,
String pAttribute
) throws
MBeanException,
AttributeNotFoundException,
InstanceNotFoundException,
ReflectionException;
public AttributeList getAttributes(
ObjectName pName,
String[] pAttributes
) throws
InstanceNotFoundException,
ReflectionException;
public void setAttribute(
ObjectName pName,
Attribute pAttribute
) throws
InstanceNotFoundException,
AttributeNotFoundException,
InvalidAttributeValueException,
MBeanException,
ReflectionException;
public AttributeList setAttributes(
ObjectName pName,
AttributeList pAttributes
) throws
InstanceNotFoundException,
ReflectionException;
public Object invoke(
ObjectName pName,
String pActionName,
Object[] pParams,
String[] pSignature
) throws
InstanceNotFoundException,
MBeanException,
ReflectionException;
public String getDefaultDomain(
);
/**
* Adds the given Notification Listener in a way that
* the Notification Events are send back to the listener
* <BR>
* Please asume that the listening is terminated when
* the instance of these interface goes down.
*
* @param pBroadcasterName Name of the Broadcaster MBean on
* the remote side
* @param pListener Local notification listener
* @param pFilter In general there are three
ways this
* could work:
* 1) A copy of the filter is
send to the
* server but then the Filter
cannot interact
* with the client. This is
default.
* 2) Wrapper around the filter
therefore
* the server sends the filter
call to the
* client to be performed. This
filter must be
* a subclass of
RemoteNotificationListener.
* 3) All Notification events are
sent to the
* client and the client performs
the filtering.
* This filter must be a subclass
of
* LocalNotificationListener.
* @param pHandback Object to be send back to the
listener. To
* make it complete transparent
to the client
* an Object Handler is sent to
the Server and
* and when a Notification comes
back it will
* be looked up and send to the
client. Therefore
* it must not be serializable.
**/
public void addNotificationListener(
ObjectName pName,
NotificationListener pListener,
NotificationFilter pFilter,
Object pHandback
) throws
InstanceNotFoundException;
/**
* Remoes the given Notification Listener in a way that
* all involved instances are removed and the remote
* listener is removed from the broadcaster.
* <BR>
* Please asume that the listening is terminated when
* the instance of these interface goes down.
*
* @param pBroadcasterName Name of the Broadcaster MBean on
* the remote side
* @param pListener Local notification listener
**/
public void removeNotificationListener(
ObjectName pName,
NotificationListener pListener
) throws
InstanceNotFoundException,
ListenerNotFoundException;
public MBeanInfo getMBeanInfo(
ObjectName pName
) throws
InstanceNotFoundException,
IntrospectionException,
ReflectionException;
// Unsupported Operations ----------------------------------------------
/**
* @throws UnsupportedOperationException
* The MBean related to
the given object
* cannot be wrapped by
the transport
* layer implementation
and therefore it
* makes no sense (no
callback could be
* instantiated) and
therefore this exception
* is always thrown
*/
public void addNotificationListener(
ObjectName pName,
ObjectName pListener,
NotificationFilter pFilter,
Object pHandback
) throws
InstanceNotFoundException,
UnsupportedOperationException;
/**
* @throws UnsupportedOperationException
* The MBean related to
the given object
* cannot be wrapped by
the transport
* layer which prevents
the remove of the
* the wrapper and
therefore it
* makes no sense (no
callback could be
* instantiated) and
therefore this exception
* is always thrown
*/
public void removeNotificationListener(
ObjectName pName,
ObjectName pListener
) throws
InstanceNotFoundException,
ListenerNotFoundException,
UnsupportedOperationException;
/**
* @throws UnsupportedOperationException
* Return value is not
serializable and
* the operation makes
really no sense
* on a connector
therefore this exception
* is always thrown
*/
public ObjectInputStream deserialize(
ObjectName pName,
byte[] pData
) throws
InstanceNotFoundException,
OperationsException,
UnsupportedOperationException;
/**
* @throws UnsupportedOperationException
* Return value is not
serializable and
* the operation makes
really no sense
* on a connector
therefore this exception
* is always thrown
*/
public ObjectInputStream deserialize(
String pClassName,
byte[] pData
) throws
OperationsException,
ReflectionException,
UnsupportedOperationException;
/**
* @throws UnsupportedOperationException
* Return value is not
serializable and
* the operation makes
really no sense
* on a connector
therefore this exception
* is always thrown
*/
public ObjectInputStream deserialize(
String pClassName,
ObjectName pLoaderName,
byte[] pData
) throws
InstanceNotFoundException,
OperationsException,
ReflectionException,
UnsupportedOperationException;
}
1.1 jboss/src/main/org/jboss/jmx/connector/JMXConnectorMBean.java
Index: JMXConnectorMBean.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.jmx.connector;
/**
* Client Side JMX Connector to be used in conjunction with
* a {@link JMXConnector server/protocol selector}. It contains the additional
* methods the client connector has to offer to open a connection to the server
* and at the end to close it.
*
* @author <A href="mailto:[EMAIL PROTECTED]">Andreas "Mad"
Schaefer</A>
**/
public interface JMXConnectorMBean
extends JMXConnector
{
// Constants -----------------------------------------------------
// Static --------------------------------------------------------
// Public --------------------------------------------------------
/**
* Initialize the client connector to a given server side JMX
* Connector
*
* @param pServer Server indentification
(because
* I do
not know the necessary type
* for a
general server ident. I
* choose
Object)
*
* @throws IllegalArgumentException If the given server is not valid
* or not
recognized by the connector
*
implementation
*/
public void start(
Object pServer
) throws IllegalArgumentException;
/**
* Stops the client connector, remove the remote connection and frees
* the resources.
*/
public void stop();
/**
* Indicates if the connection is alive and ready to serve
*
* @return True if the
connection is alive
*/
public boolean isAlive();
/**
* Delivers the actual server description to which the client is
* connected to
*
* @return Description of
the server the client
* is
connected to or null if there is
* no
connection
*/
public String getServerDescription();
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development