mx4j/src/tools/mx4j/tools/remote AbstractServerInvoker.java,NONE,1.1 JMXConnection.java,NONE,1.1 JMXConnectionHandler.java,NONE,1.1 JMXConnectionMBeanServerConnection.java,NONE,1.1 SubjectInvoker.java,NONE,1.1 AbstractConnectionManager.java,1.4,1.5 AbstractJMXConnector.java,1.5,1.6

Simone Bordet <[email protected]>
Newsgroups gmane.comp.java.mx4j.cvs
Message-ID <[email protected]>
Update of /cvsroot/mx4j/mx4j/src/tools/mx4j/tools/remote
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28562/src/tools/mx4j/tools/remote

Modified Files:
	AbstractConnectionManager.java AbstractJMXConnector.java 
Added Files:
	AbstractServerInvoker.java JMXConnection.java 
	JMXConnectionHandler.java 
	JMXConnectionMBeanServerConnection.java SubjectInvoker.java 
Log Message:
Refactored into common classes basic JSR 160 functionalities

Index: AbstractJMXConnector.java
===================================================================
RCS file: /cvsroot/mx4j/mx4j/src/tools/mx4j/tools/remote/AbstractJMXConnector.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** AbstractJMXConnector.java	3 Nov 2003 23:36:23 -0000	1.5
--- AbstractJMXConnector.java	10 Aug 2004 09:03:54 -0000	1.6
***************
*** 12,16 ****
  import java.io.Serializable;
  import java.util.Map;
- 
  import javax.management.ListenerNotFoundException;
  import javax.management.MBeanServerConnection;
--- 12,15 ----
***************
*** 27,30 ****
--- 26,30 ----
   * It gives support for emitting connection notifications and implements JMXConnector methods
   * using the template method pattern.
+  *
   * @author <a href="mailto:[email protected]">Simone Bordet</a>
   * @version $Revision$
***************
*** 32,36 ****
  public abstract class AbstractJMXConnector implements JMXConnector, Serializable
  {
!    /** @serial */
     private final JMXServiceURL address;
     private transient boolean connected;
--- 32,38 ----
  public abstract class AbstractJMXConnector implements JMXConnector, Serializable
  {
!    /**
!     * @serial
!     */
     private final JMXServiceURL address;
     private transient boolean connected;
***************
*** 110,113 ****
--- 112,121 ----
      * Template method to be implemented by subclasses to return an MBeanServerConnection
      * for the given delegate subject.
+     * This method should return an MBeanServerConnection that delegates method calls to a
+     * {@link JMXConnection} (or an equivalent client side connection object).
+     * The JMXConnection object to which calls are delegated can in turn be a chain of
+     * objects that decorate the call performing some other operation; the final object in
+     * the chain is the one that really communicates with the server side, and it is normally
+     * called <protocol>ClientInvoker.
      */
     protected abstract MBeanServerConnection doGetMBeanServerConnection(Subject delegate) throws IOException;

--- NEW FILE: AbstractServerInvoker.java ---
/*
 * Copyright (C) MX4J.
 * All rights reserved.
 *
 * This software is distributed under the terms of the MX4J License version 1.0.
 * See the terms of the MX4J License in the documentation provided with this software.
 */

package mx4j.tools.remote;

import java.io.IOException;
import java.util.Set;
import javax.management.Attribute;
import javax.management.AttributeList;
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.MBeanInfo;
import javax.management.MBeanRegistrationException;
import javax.management.MBeanServerConnection;
import javax.management.NotCompliantMBeanException;
import javax.management.NotificationFilter;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import javax.management.QueryExp;
import javax.management.ReflectionException;
import javax.security.auth.Subject;

/**
 * This class implements partially the JMXConnection interface to forward the calls
 * to an MBeanServerConnection object (hence the name 'invoker').
 * It does not handle nor unmarshalling of arguments (and all related classloading
 * problems), nor remote notification mechanisms of any sort, which are left
 * to subclasses, which will implement them in a protocol specific way.
 * This class is the server-side counterpart of {@link JMXConnectionMBeanServerConnection}
 *
 * @author <a href="mailto:[email protected]">Simone Bordet</a>
 * @version $Revision: 1.1 $
 */
public abstract class AbstractServerInvoker implements JMXConnection
{
   private final MBeanServerConnection server;

   protected AbstractServerInvoker(MBeanServerConnection server)
   {
      this.server = server;
   }

   public MBeanServerConnection getServer()
   {
      return server;
   }

   public ObjectInstance createMBean(String className, ObjectName name, Object params, String[] signature, Subject delegate) throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException, IOException
   {
      return getServer().createMBean(className, name, (Object[])params, signature);
   }

   public ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName, Object params, String[] signature, Subject delegate) throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException, InstanceNotFoundException, IOException
   {
      return getServer().createMBean(className, name, loaderName, (Object[])params, signature);
   }

   public void unregisterMBean(ObjectName name, Subject delegate) throws InstanceNotFoundException, MBeanRegistrationException, IOException
   {
      getServer().unregisterMBean(name);
   }

   public ObjectInstance getObjectInstance(ObjectName name, Subject delegate) throws InstanceNotFoundException, IOException
   {
      return getServer().getObjectInstance(name);
   }

   public Set queryMBeans(ObjectName name, Object query, Subject delegate) throws IOException
   {
      return getServer().queryMBeans(name, (QueryExp)query);
   }

   public Set queryNames(ObjectName name, Object query, Subject delegate) throws IOException
   {
      return getServer().queryNames(name, (QueryExp)query);
   }

   public boolean isRegistered(ObjectName name, Subject delegate) throws IOException
   {
      return getServer().isRegistered(name);
   }

   public Integer getMBeanCount(Subject delegate) throws IOException
   {
      return getServer().getMBeanCount();
   }

   public Object getAttribute(ObjectName name, String attribute, Subject delegate) throws MBeanException, AttributeNotFoundException, InstanceNotFoundException, ReflectionException, IOException
   {
      return getServer().getAttribute(name, attribute);
   }

   public AttributeList getAttributes(ObjectName name, String[] attributes, Subject delegate) throws InstanceNotFoundException, ReflectionException, IOException
   {
      return getServer().getAttributes(name, attributes);
   }

   public void setAttribute(ObjectName name, Object attribute, Subject delegate) throws InstanceNotFoundException, AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException, IOException
   {
      getServer().setAttribute(name, (Attribute)attribute);
   }

   public AttributeList setAttributes(ObjectName name, Object attributes, Subject delegate) throws InstanceNotFoundException, ReflectionException, IOException
   {
      return getServer().setAttributes(name, (AttributeList)attributes);
   }

   public Object invoke(ObjectName name, String operationName, Object params, String[] signature, Subject delegate) throws InstanceNotFoundException, MBeanException, ReflectionException, IOException
   {
      return getServer().invoke(name, operationName, (Object[])params, signature);
   }

   public String getDefaultDomain(Subject delegate) throws IOException
   {
      return getServer().getDefaultDomain();
   }

   public String[] getDomains(Subject delegate) throws IOException
   {
      return getServer().getDomains();
   }

   public MBeanInfo getMBeanInfo(ObjectName name, Subject delegate) throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException
   {
      return getServer().getMBeanInfo(name);
   }

   public boolean isInstanceOf(ObjectName name, String className, Subject delegate) throws InstanceNotFoundException, IOException
   {
      return getServer().isInstanceOf(name, className);
   }

   public void addNotificationListener(ObjectName name, ObjectName listener, Object filter, Object handback, Subject delegate) throws InstanceNotFoundException, IOException
   {
      getServer().addNotificationListener(name, listener, (NotificationFilter)filter, handback);
   }

   public void removeNotificationListener(ObjectName name, ObjectName listener, Subject delegate) throws InstanceNotFoundException, ListenerNotFoundException, IOException
   {
      getServer().removeNotificationListener(name, listener);
   }

   public void removeNotificationListener(ObjectName name, ObjectName listener, Object filter, Object handback, Subject delegate) throws InstanceNotFoundException, ListenerNotFoundException, IOException
   {
      getServer().removeNotificationListener(name, listener, (NotificationFilter)filter, handback);
   }
}

--- NEW FILE: SubjectInvoker.java ---
/*
 * Copyright (C) MX4J.
 * All rights reserved.
 *
 * This software is distributed under the terms of the MX4J License version 1.0.
 * See the terms of the MX4J License in the documentation provided with this software.
 */

package mx4j.tools.remote;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.AccessControlContext;
import java.security.PrivilegedExceptionAction;
import javax.management.remote.JMXServerErrorException;
import javax.security.auth.Subject;

import mx4j.remote.MX4JRemoteUtils;

/**
 * @author <a href="mailto:[email protected]">Simone Bordet</a>
 * @version $Revision: 1.1 $
 */
public abstract class SubjectInvoker implements InvocationHandler
{
   private final Object target;
   private final Subject subject;
   private final AccessControlContext context;

   protected SubjectInvoker(Object target, Subject subject, AccessControlContext context)
   {
      this.target = target;
      this.subject = subject;
      this.context = context;
   }

   protected boolean isPlainInvoke(Method method)
   {
      String methodName = method.getName();
      // java.lang.Object methods
      if ("toString".equals(methodName)) return true;
      if ("hashCode".equals(methodName)) return true;
      if ("equals".equals(methodName)) return true;
      return false;
   }

   protected Object handleSpecialInvoke(Object target, Method method, Object[] args) throws Exception
   {
      throw new NoSuchMethodException(method.toString());
   }

   public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
   {
      if (isPlainInvoke(method)) return chain(target, method, args);
      if (method.getParameterTypes()[args.length - 1] == Subject.class)
      {
         Subject delegate = (Subject)args[args.length - 1];
         return subjectInvoke(target, method, args, delegate);
      }
      else
      {
         return handleSpecialInvoke(target, method, args);
      }
   }

   protected Object subjectInvoke(final Object proxy, final Method method, final Object[] args, Subject delegate) throws Exception
   {
      return MX4JRemoteUtils.subjectInvoke(subject, delegate, context, new PrivilegedExceptionAction()
      {
         public Object run() throws Exception
         {
            return chain(proxy, method, args);
         }
      });
   }

   protected Object chain(Object proxy, Method method, Object[] args) throws Exception
   {
      try
      {
         return method.invoke(proxy, args);
      }
      catch (InvocationTargetException x)
      {
         Throwable t = x.getTargetException();
         if (t instanceof Exception) throw (Exception)t;
         throw new JMXServerErrorException("Error thrown during invocation", (Error)t);
      }
   }
}

Index: AbstractConnectionManager.java
===================================================================
RCS file: /cvsroot/mx4j/mx4j/src/tools/mx4j/tools/remote/AbstractConnectionManager.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** AbstractConnectionManager.java	22 Sep 2003 17:38:35 -0000	1.4
--- AbstractConnectionManager.java	10 Aug 2004 09:03:54 -0000	1.5
***************
*** 16,20 ****
  import java.util.Iterator;
  import java.util.Map;
- 
  import javax.management.remote.JMXAuthenticator;
  import javax.management.remote.JMXConnectorServer;
--- 16,19 ----
***************
*** 26,29 ****
--- 25,29 ----
   * Implementation of the ConnectionManager interface that implements emission of connection notifications,
   * authentication, and proper closing of connections.
+  *
   * @author <a href="mailto:[email protected]">Simone Bordet</a>
   * @version $Revision$
***************
*** 39,43 ****
     /**
      * Called by subclasses.
!     * @param server The JMXConnectorServer that will emit connection notifications
      * @param environment The environment passed when the JMXConnectorServer is created.
      */
--- 39,44 ----
     /**
      * Called by subclasses.
!     *
!     * @param server      The JMXConnectorServer that will emit connection notifications
      * @param environment The environment passed when the JMXConnectorServer is created.
      */
***************
*** 52,55 ****
--- 53,57 ----
      * Implemented using the template method pattern, it handles authentication, creation of the connection ID,
      * emission of connection notification of type "opened".
+     *
      * @see #doConnect
      * @see #authenticate
***************
*** 78,81 ****
--- 80,84 ----
     /**
      * Returns a connection ID as specified by JSR 160.
+     *
      * @param subject The authenticated Subject
      */
***************
*** 86,93 ****
  
     /**
!     * Template method to be implemented by subclasses.
      * @param connectionId The connection ID for connection that is returned
!     * @param subject The authenticated Subject
!     * @return A client-specific Connection (with the given connection ID)
      * @throws IOException If the connection cannot be created
      */
--- 89,101 ----
  
     /**
!     * Template method to be implemented by subclasses; must return the server-side part of
!     * a connection.
!     * When an remote invocation arrives, it will lookup the corrispondent server-side part
!     * of the connection and delegate the call to it. The server-side part of the connection
!     * must then (eventually) call the MBeanServer to satisfy the request.
!     *
      * @param connectionId The connection ID for connection that is returned
!     * @param subject      The authenticated Subject
!     * @return The server-side part of a connection (with the given connection ID)
      * @throws IOException If the connection cannot be created
      */
***************
*** 96,99 ****
--- 104,108 ----
     /**
      * Implemented using the template method pattern
+     *
      * @see #doClose
      * @see #closeConnection
***************
*** 109,112 ****
--- 118,122 ----
     /**
      * Closes this ConnectionManager but not the connections it manages
+     *
      * @throws IOException If this ConnectionManager cannot be closed
      */
***************
*** 120,124 ****
           while (!connections.isEmpty())
           {
!             // Create the iterator every time, since closeConnection() modifies the Map
              Iterator entries = connections.entrySet().iterator();
              Map.Entry entry = (Map.Entry)entries.next();
--- 130,134 ----
           while (!connections.isEmpty())
           {
!             // Create the iterator every time, since closeConnection() may modify the Map
              Iterator entries = connections.entrySet().iterator();
              Map.Entry entry = (Map.Entry)entries.next();
***************
*** 151,154 ****
--- 161,165 ----
      * of type "closed".
      * This method is called both when closing the connector server and when closing a connector.
+     *
      * @see #doCloseConnection
      */
***************
*** 165,173 ****
  
        Connection client = (Connection)weak.get();
!       if (connection != client) throw new IOException("Could not find active connection " + connection);
  
        doCloseConnection(connection);
  
!       server.connectionClosed(connection.getConnectionId(), "Closed connection " + connection, null);
     }
  
--- 176,184 ----
  
        Connection client = (Connection)weak.get();
!       if (connection != client) throw new IOException("Could not find active connection " + connection + ", expecting " + client);
  
        doCloseConnection(connection);
  
!       server.connectionClosed(connectionID, "Closed connection " + connection, null);
     }
  

--- NEW FILE: JMXConnectionHandler.java ---
/*
 * Copyright (C) MX4J.
 * All rights reserved.
 *
 * This software is distributed under the terms of the MX4J License version 1.0.
 * See the terms of the MX4J License in the documentation provided with this software.
 */

package mx4j.tools.remote;

import java.io.IOException;
import java.util.Set;
import javax.management.AttributeList;
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.MBeanInfo;
import javax.management.MBeanRegistrationException;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import javax.management.ReflectionException;
import javax.security.auth.Subject;

/**
 * This handler manages the operations related to the connection itself, such as
 * {@link #close}, {@link #getConnectionId}.
 * <p/>
 * It is important that this object is the outermost wrapper of the Connection objects
 * returned by {@link mx4j.tools.remote.ConnectionManager#connect}
 *
 * @author <a href="mailto:[email protected]">Simone Bordet</a>
 * @version $Revision: 1.1 $
 */
public abstract class JMXConnectionHandler extends AbstractConnection implements JMXConnection
{
   private final JMXConnection connection;
   private volatile boolean closed;

   public JMXConnectionHandler(JMXConnection connection, ConnectionManager manager, String connectionId)
   {
      super(connectionId, manager);
      this.connection = connection;
   }

   /**
    * Overridden to allow nested connections to close and release their resources and, afterwards,
    * to close this connection with the JSR 160 semantic provided by the superclass.
    */
   public void close() throws IOException
   {
      if (isClosed()) return;
      closed = true;
      getConnection().close();
      super.close();
   }

   protected boolean isClosed()
   {
      return closed;
   }

   protected JMXConnection getConnection()
   {
      return connection;
   }

   public ObjectInstance createMBean(String className, ObjectName name, Object params, String[] signature, Subject delegate) throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException, IOException
   {
      if (isClosed()) throw new IOException("Connection has been closed");
      return getConnection().createMBean(className, name, params, signature, delegate);
   }

   public ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName, Object params, String[] signature, Subject delegate) throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException, InstanceNotFoundException, IOException
   {
      if (isClosed()) throw new IOException("Connection has been closed");
      return getConnection().createMBean(className, name, loaderName, params, signature, delegate);
   }

   public void unregisterMBean(ObjectName name, Subject delegate) throws InstanceNotFoundException, MBeanRegistrationException, IOException
   {
      if (isClosed()) throw new IOException("Connection has been closed");
      getConnection().unregisterMBean(name, delegate);
   }

   public ObjectInstance getObjectInstance(ObjectName name, Subject delegate) throws InstanceNotFoundException, IOException
   {
      if (isClosed()) throw new IOException("Connection has been closed");
      return getConnection().getObjectInstance(name, delegate);
   }

   public Set queryMBeans(ObjectName name, Object query, Subject delegate) throws IOException
   {
      if (isClosed()) throw new IOException("Connection has been closed");
      return getConnection().queryMBeans(name, query, delegate);
   }

   public Set queryNames(ObjectName name, Object query, Subject delegate) throws IOException
   {
      if (isClosed()) throw new IOException("Connection has been closed");
      return getConnection().queryNames(name, query, delegate);
   }

   public boolean isRegistered(ObjectName name, Subject delegate) throws IOException
   {
      if (isClosed()) throw new IOException("Connection has been closed");
      return getConnection().isRegistered(name, delegate);
   }

   public Integer getMBeanCount(Subject delegate) throws IOException
   {
      if (isClosed()) throw new IOException("Connection has been closed");
      return getConnection().getMBeanCount(delegate);
   }

   public Object getAttribute(ObjectName name, String attribute, Subject delegate) throws MBeanException, AttributeNotFoundException, InstanceNotFoundException, ReflectionException, IOException
   {
      if (isClosed()) throw new IOException("Connection has been closed");
      return getConnection().getAttribute(name, attribute, delegate);
   }

   public AttributeList getAttributes(ObjectName name, String[] attributes, Subject delegate) throws InstanceNotFoundException, ReflectionException, IOException
   {
      if (isClosed()) throw new IOException("Connection has been closed");
      return getConnection().getAttributes(name, attributes, delegate);
   }

   public void setAttribute(ObjectName name, Object attribute, Subject delegate) throws InstanceNotFoundException, AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException, IOException
   {
      if (isClosed()) throw new IOException("Connection has been closed");
      getConnection().setAttribute(name, attribute, delegate);
   }

   public AttributeList setAttributes(ObjectName name, Object attributes, Subject delegate) throws InstanceNotFoundException, ReflectionException, IOException
   {
      if (isClosed()) throw new IOException("Connection has been closed");
      return getConnection().setAttributes(name, attributes, delegate);
   }

   public Object invoke(ObjectName name, String operationName, Object params, String[] signature, Subject delegate) throws InstanceNotFoundException, MBeanException, ReflectionException, IOException
   {
      if (isClosed()) throw new IOException("Connection has been closed");
      return getConnection().invoke(name, operationName, params, signature, delegate);
   }

   public String getDefaultDomain(Subject delegate) throws IOException
   {
      if (isClosed()) throw new IOException("Connection has been closed");
      return getConnection().getDefaultDomain(delegate);
   }

   public String[] getDomains(Subject delegate) throws IOException
   {
      if (isClosed()) throw new IOException("Connection has been closed");
      return getConnection().getDomains(delegate);
   }

   public MBeanInfo getMBeanInfo(ObjectName name, Subject delegate) throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException
   {
      if (isClosed()) throw new IOException("Connection has been closed");
      return getConnection().getMBeanInfo(name, delegate);
   }

   public boolean isInstanceOf(ObjectName name, String className, Subject delegate) throws InstanceNotFoundException, IOException
   {
      if (isClosed()) throw new IOException("Connection has been closed");
      return getConnection().isInstanceOf(name, className, delegate);
   }

   public void addNotificationListener(ObjectName name, ObjectName listener, Object filter, Object handback, Subject delegate) throws InstanceNotFoundException, IOException
   {
      if (isClosed()) throw new IOException("Connection has been closed");
      getConnection().addNotificationListener(name, listener, filter, handback, delegate);
   }

   public void removeNotificationListener(ObjectName name, ObjectName listener, Subject delegate) throws InstanceNotFoundException, ListenerNotFoundException, IOException
   {
      if (isClosed()) throw new IOException("Connection has been closed");
      getConnection().removeNotificationListener(name, listener, delegate);
   }

   public void removeNotificationListener(ObjectName name, ObjectName listener, Object filter, Object handback, Subject delegate) throws InstanceNotFoundException, ListenerNotFoundException, IOException
   {
      if (isClosed()) throw new IOException("Connection has been closed");
      getConnection().removeNotificationListener(name, listener, filter, handback, delegate);
   }
}

--- NEW FILE: JMXConnectionMBeanServerConnection.java ---
/*
 * Copyright (C) MX4J.
 * All rights reserved.
 *
 * This software is distributed under the terms of the MX4J License version 1.0.
 * See the terms of the MX4J License in the documentation provided with this software.
 */

package mx4j.tools.remote;

import java.io.IOException;
import java.util.Set;
import javax.management.Attribute;
import javax.management.AttributeList;
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.MBeanInfo;
import javax.management.MBeanRegistrationException;
import javax.management.MBeanServerConnection;
import javax.management.NotCompliantMBeanException;
import javax.management.NotificationFilter;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import javax.management.QueryExp;
import javax.management.ReflectionException;
import javax.security.auth.Subject;

/**
 * Abstract implementation of an adapter that converts MBeanServerConnection calls
 * to JMXConnection calls.
 * It does not handle nor marshalling nor remote notifications, which are left to
 * subclasses.
 * This is the client side counterpart of {@link AbstractServerInvoker}
 *
 * @author <a href="mailto:[email protected]">Simone Bordet</a>
 * @version $Revision: 1.1 $
 */
public abstract class JMXConnectionMBeanServerConnection implements MBeanServerConnection
{
   private final JMXConnection connection;
   private final Subject delegate;

   protected JMXConnectionMBeanServerConnection(JMXConnection connection, Subject delegate)
   {
      this.connection = connection;
      this.delegate = delegate;
   }

   protected JMXConnection getConnection()
   {
      return connection;
   }

   protected Subject getDelegateSubject()
   {
      return delegate;
   }

   public MBeanInfo getMBeanInfo(ObjectName objectName) throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException
   {
      return getConnection().getMBeanInfo(objectName, getDelegateSubject());
   }

   public boolean isInstanceOf(ObjectName objectName, String className) throws InstanceNotFoundException, IOException
   {
      return getConnection().isInstanceOf(objectName, className, getDelegateSubject());
   }

   public String[] getDomains() throws IOException
   {
      return getConnection().getDomains(getDelegateSubject());
   }

   public String getDefaultDomain() throws IOException
   {
      return getConnection().getDefaultDomain(getDelegateSubject());
   }

   public ObjectInstance createMBean(String className, ObjectName objectName) throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException, IOException
   {
      return createMBean(className, objectName, null, null);
   }

   public ObjectInstance createMBean(String className, ObjectName objectName, Object[] args, String[] parameters) throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException, IOException
   {
      return getConnection().createMBean(className, objectName, args, parameters, getDelegateSubject());
   }

   public ObjectInstance createMBean(String className, ObjectName objectName, ObjectName loaderName) throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException, InstanceNotFoundException, IOException
   {
      return createMBean(className, objectName, loaderName, null, null);
   }

   public ObjectInstance createMBean(String className, ObjectName objectName, ObjectName loaderName, Object[] args, String[] parameters) throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException, InstanceNotFoundException, IOException
   {
      return getConnection().createMBean(className, objectName, loaderName, args, parameters, getDelegateSubject());
   }

   public void unregisterMBean(ObjectName objectName) throws InstanceNotFoundException, MBeanRegistrationException, IOException
   {
      getConnection().unregisterMBean(objectName, getDelegateSubject());
   }

   public Object getAttribute(ObjectName objectName, String attribute) throws MBeanException, AttributeNotFoundException, InstanceNotFoundException, ReflectionException, IOException
   {
      return getConnection().getAttribute(objectName, attribute, getDelegateSubject());
   }

   public void setAttribute(ObjectName objectName, Attribute attribute) throws InstanceNotFoundException, AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException, IOException
   {
      getConnection().setAttribute(objectName, attribute, getDelegateSubject());
   }

   public AttributeList getAttributes(ObjectName objectName, String[] attributes) throws InstanceNotFoundException, ReflectionException, IOException
   {
      return getConnection().getAttributes(objectName, attributes, getDelegateSubject());
   }

   public AttributeList setAttributes(ObjectName objectName, AttributeList attributes) throws InstanceNotFoundException, ReflectionException, IOException
   {
      return getConnection().setAttributes(objectName, attributes, getDelegateSubject());
   }

   public Object invoke(ObjectName objectName, String methodName, Object[] args, String[] parameters) throws InstanceNotFoundException, MBeanException, ReflectionException, IOException
   {
      return getConnection().invoke(objectName, methodName, args, parameters, getDelegateSubject());
   }

   public Integer getMBeanCount() throws IOException
   {
      return getConnection().getMBeanCount(getDelegateSubject());
   }

   public boolean isRegistered(ObjectName objectName) throws IOException
   {
      return getConnection().isRegistered(objectName, getDelegateSubject());
   }

   public ObjectInstance getObjectInstance(ObjectName objectName) throws InstanceNotFoundException, IOException
   {
      return getConnection().getObjectInstance(objectName, getDelegateSubject());
   }

   public Set queryMBeans(ObjectName patternName, QueryExp filter) throws IOException
   {
      return getConnection().queryMBeans(patternName, filter, getDelegateSubject());
   }

   public Set queryNames(ObjectName patternName, QueryExp filter) throws IOException
   {
      return getConnection().queryNames(patternName, filter, getDelegateSubject());
   }

   public void addNotificationListener(ObjectName observed, ObjectName listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException, IOException
   {
      getConnection().addNotificationListener(observed, listener, filter, handback, getDelegateSubject());
   }

   public void removeNotificationListener(ObjectName observed, ObjectName listener) throws InstanceNotFoundException, ListenerNotFoundException, IOException
   {
      getConnection().removeNotificationListener(observed, listener, getDelegateSubject());
   }

   public void removeNotificationListener(ObjectName observed, ObjectName listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException, ListenerNotFoundException, IOException
   {
      getConnection().removeNotificationListener(observed, listener, filter, handback, getDelegateSubject());
   }
}

--- NEW FILE: JMXConnection.java ---
/*
 * Copyright (C) MX4J.
 * All rights reserved.
 *
 * This software is distributed under the terms of the MX4J License version 1.0.
 * See the terms of the MX4J License in the documentation provided with this software.
 */
package mx4j.tools.remote;

import java.io.IOException;
import java.util.Set;
import javax.management.AttributeList;
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.MBeanInfo;
import javax.management.MBeanRegistrationException;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import javax.management.ReflectionException;
import javax.security.auth.Subject;

/**
 * @author <a href="mailto:[email protected]">Simone Bordet</a>
 * @version $Revision: 1.1 $
 */
public interface JMXConnection
{
   public void close()
           throws IOException;

   public ObjectInstance createMBean(String className, ObjectName name, Object params, String[] signature, Subject delegate)
           throws ReflectionException,
                  InstanceAlreadyExistsException,
                  MBeanRegistrationException,
                  MBeanException,
                  NotCompliantMBeanException,
                  IOException;

   public ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName, Object params, String[] signature, Subject delegate)
           throws ReflectionException,
                  InstanceAlreadyExistsException,
                  MBeanRegistrationException,
                  MBeanException,
                  NotCompliantMBeanException,
                  InstanceNotFoundException,
                  IOException;

   public void unregisterMBean(ObjectName name, Subject delegate)
           throws InstanceNotFoundException,
                  MBeanRegistrationException,
                  IOException;

   public ObjectInstance getObjectInstance(ObjectName name, Subject delegate)
           throws InstanceNotFoundException,
                  IOException;

   public Set queryMBeans(ObjectName name, Object query, Subject delegate)
           throws IOException;

   public Set queryNames(ObjectName name, Object query, Subject delegate)
           throws IOException;

   public boolean isRegistered(ObjectName name, Subject delegate)
           throws IOException;

   public Integer getMBeanCount(Subject delegate)
           throws IOException;

   public Object getAttribute(ObjectName name, String attribute, Subject delegate)
           throws MBeanException,
                  AttributeNotFoundException,
                  InstanceNotFoundException,
                  ReflectionException,
                  IOException;

   public AttributeList getAttributes(ObjectName name, String[] attributes, Subject delegate)
           throws InstanceNotFoundException,
                  ReflectionException,
                  IOException;

   public void setAttribute(ObjectName name, Object attribute, Subject delegate)
           throws InstanceNotFoundException,
                  AttributeNotFoundException,
                  InvalidAttributeValueException,
                  MBeanException,
                  ReflectionException,
                  IOException;

   public AttributeList setAttributes(ObjectName name, Object attributes, Subject delegate)
           throws InstanceNotFoundException,
                  ReflectionException,
                  IOException;

   public Object invoke(ObjectName name, String operationName, Object params, String[] signature, Subject delegate)
           throws InstanceNotFoundException,
                  MBeanException,
                  ReflectionException,
                  IOException;

   public String getDefaultDomain(Subject delegate)
           throws IOException;

   public String[] getDomains(Subject delegate)
           throws IOException;

   public MBeanInfo getMBeanInfo(ObjectName name, Subject delegate)
           throws InstanceNotFoundException,
                  IntrospectionException,
                  ReflectionException,
                  IOException;

   public boolean isInstanceOf(ObjectName name, String className, Subject delegate)
           throws InstanceNotFoundException,
                  IOException;

   public void addNotificationListener(ObjectName name, ObjectName listener, Object filter, Object handback, Subject delegate)
           throws InstanceNotFoundException,
                  IOException;

   public void removeNotificationListener(ObjectName name, ObjectName listener, Subject delegate)
           throws InstanceNotFoundException,
                  ListenerNotFoundException,
                  IOException;

   public void removeNotificationListener(ObjectName name, ObjectName listener, Object filter, Object handback, Subject delegate)
           throws InstanceNotFoundException,
                  ListenerNotFoundException,
                  IOException;
}



-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media
100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33
Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.