tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hgo...@apache.org
Subject cvs commit: jakarta-tomcat/proposals/JmxSupport/WEB-INF/classes/org/apache/tomcat/modules/config MxInterceptor.java DynamicMBeanProxy.java
Date Mon, 29 Sep 2003 07:38:10 GMT
hgomez      2003/09/29 00:38:10

  Modified:    proposals/JmxSupport/WEB-INF/classes/org/apache/tomcat/modules/config
                        MxInterceptor.java DynamicMBeanProxy.java
  Log:
  Add JRMP support if we ever use this Interceptor
  
  Revision  Changes    Path
  1.2       +127 -53   jakarta-tomcat/proposals/JmxSupport/WEB-INF/classes/org/apache/tomcat/modules/config/MxInterceptor.java
  
  Index: MxInterceptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/JmxSupport/WEB-INF/classes/org/apache/tomcat/modules/config/MxInterceptor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MxInterceptor.java	30 Sep 2002 02:17:43 -0000	1.1
  +++ MxInterceptor.java	29 Sep 2003 07:38:10 -0000	1.2
  @@ -58,12 +58,24 @@
    */
   package org.apache.tomcat.modules.config;
   
  -import org.apache.tomcat.core.*;
  -import org.apache.tomcat.util.io.FileUtil;
  -import java.io.*;
  -import java.util.*;
  +import java.io.IOException;
  +import java.net.InetAddress;
   
  -import javax.management.*;
  +import javax.management.Attribute;
  +import javax.management.MBeanServer;
  +import javax.management.ObjectName;
  +
  +import mx4j.adaptor.rmi.jrmp.JRMPAdaptorMBean;
  +import mx4j.tools.naming.NamingServiceMBean;
  +import mx4j.util.StandardMBeanProxy;
  +
  +import org.apache.tomcat.core.BaseInterceptor;
  +import org.apache.tomcat.core.Context;
  +import org.apache.tomcat.core.ContextManager;
  +import org.apache.tomcat.core.Request;
  +import org.apache.tomcat.core.Response;
  +import org.apache.tomcat.core.TomcatException;
  +import org.apache.tomcat.modules.config.DynamicMBeanProxy;
   
   /**
    *
  @@ -72,11 +84,12 @@
   public class MxInterceptor  extends BaseInterceptor { 
   
       MBeanServer     mserver;
  -    private int     port=-1;
  +    private int    port=-1;
       private String host;
  -    private String  auth;
  +    private String auth;
       private String user;
       private String password;
  +    private String type = "http";
       
       // -------------------- Tomcat callbacks --------------------
   
  @@ -101,7 +114,7 @@
   
       /* -------------------- Public methods -------------------- */
   
  -    /** Enable the MX4J internal adapter
  +    /** Enable the MX4J internal adaptor
        */
       public void setPort( int i ) {
           port=i;
  @@ -140,58 +153,119 @@
           return password != null && password.length() > 0;
       }
   
  +	public void setType(String type) {
  +		this.type = type;
  +	}
  +	
  +	public String getType() {
  +		return type;
  +	}
  +	
       /* ==================== Start/stop ==================== */
       ObjectName serverName=null;
       
  -    /** Initialize the worker. After this call the worker will be
  -     *  ready to accept new requests.
  -     */
  -    public void loadAdapter() throws IOException {
  -        try {
  -            serverName = new ObjectName("Http:name=HttpAdaptor");
  -            mserver.createMBean("mx4j.adaptor.http.HttpAdaptor", serverName, null);
  +	/** Initialize the JRMP Adaptor for JMX.
  +	 */
  +	private void loadJRMPAdaptor()
  +	{
  +		try
  +		{
  +			// Create the RMI Naming registry
  +			ObjectName naming = new ObjectName("Naming:type=registry");
  +			mserver.createMBean("mx4j.tools.naming.NamingService", naming, null, new Object[] {new
Integer(port)}, new String[] {"int"});
  +			NamingServiceMBean nsmbean = (NamingServiceMBean)StandardMBeanProxy.create(NamingServiceMBean.class,
mserver, naming);
  +			nsmbean.start();
  +
  +			// Create the JRMP adaptor
  +			ObjectName adaptor = new ObjectName("Adaptor:protocol=JRMP");
  +			mserver.createMBean("mx4j.adaptor.rmi.jrmp.JRMPAdaptor", adaptor, null);
  +			JRMPAdaptorMBean jrmpmbean = (JRMPAdaptorMBean)StandardMBeanProxy.create(JRMPAdaptorMBean.class,
mserver, adaptor);
  +	
  +			// Set the JNDI name with which will be registered
  +			String jndiName = "jrmp";
  +			jrmpmbean.setJNDIName(jndiName);
  +
  +			String lHost = host;
  +
  +			if (lHost == null)
  +				lHost = "localhost";
  +			else if (lHost.length() == 0)
  +					lHost = InetAddress.getLocalHost().getHostName();
  +
  +			log( "Started mx4j jrmp adaptor" + ((host != null) ? " for host " + host : "") + " at
port " + port);
  +
  +			jrmpmbean.putJNDIProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory");
  +			jrmpmbean.putJNDIProperty(javax.naming.Context.PROVIDER_URL, "rmi://" + lHost + ":"
+ port);
  +
  +			jrmpmbean.start();
  +			
  +		} 
  +		catch( Throwable t ) 
  +		{
  +			log("Can't load MX4J JRMP adaptor" + t.toString() );
  +		}
  +	}
  +
  +	/** Initialize the HTTP Adaptor for JMX.
  +	 */
  +	private void loadHTTPAdaptor() {
  +		try {
  +			serverName = new ObjectName("Http:name=HttpAdaptor");
  +			mserver.createMBean("mx4j.adaptor.http.HttpAdaptor", serverName, null);
               
  -            if( host!=null ) 
  -                mserver.setAttribute(serverName, new Attribute("Host", host));
  +			if( host!=null ) 
  +				mserver.setAttribute(serverName, new Attribute("Host", host));
               
  -            mserver.setAttribute(serverName, new Attribute("Port", new Integer(port)));
  +			mserver.setAttribute(serverName, new Attribute("Port", new Integer(port)));
   
  -            // use authentication if user/password set
  -            if( auth!=null && user!=null && password!=null) 
  -                mserver.setAttribute(serverName, new Attribute("AuthenticationMethod",
auth));
  -
  -            // add user names
  -            mserver.invoke(serverName, "addAuthorization", new Object[] {user, password},

  -                           new String[] {"java.lang.String", "java.lang.String"});
  -
  -            ObjectName processorName = new ObjectName("Http:name=XSLTProcessor");
  -            mserver.createMBean("mx4j.adaptor.http.XSLTProcessor", processorName, null);
  -            mserver.setAttribute(serverName, new Attribute("ProcessorName", processorName));
  +			// use authentication if user/password set
  +			if( auth!=null && user!=null && password!=null) 
  +				mserver.setAttribute(serverName, new Attribute("AuthenticationMethod", auth));
  +
  +			// add user names
  +			mserver.invoke(serverName, "addAuthorization", new Object[] {user, password}, 
  +						   new String[] {"java.lang.String", "java.lang.String"});
  +
  +			ObjectName processorName = new ObjectName("Http:name=XSLTProcessor");
  +			mserver.createMBean("mx4j.adaptor.http.XSLTProcessor", processorName, null);
  +			mserver.setAttribute(serverName, new Attribute("ProcessorName", processorName));
                   
  -            mserver.invoke(serverName, "start", null, null);
  -            log( "Started mx4j http adaptor" + ((host != null) ? " for host " + host :
"") + " at port " + port);
  -            return;
  -        } catch( Throwable t ) {
  -            log( "Can't load the MX4J http adapter " + t.toString()  );
  -        }
  -
  -        try {
  -            Class c=Class.forName( "com.sun.jdmk.comm.HtmlAdaptorServer" );
  -            Object o=c.newInstance();
  -            serverName=new ObjectName("Adaptor:name=html,port=" + port);
  -            log("Registering the JMX_RI html adapter " + serverName);
  -            mserver.registerMBean(o,  serverName);
  -
  -            mserver.setAttribute(serverName,
  -                                 new Attribute("Port", new Integer(port)));
  +			mserver.invoke(serverName, "start", null, null);
  +			log( "Started mx4j http adaptor" + ((host != null) ? " for host " + host : "") + " at
port " + port);
  +			return;
  +		} catch( Throwable t ) {
  +			log( "Can't load the MX4J http adaptor " + t.toString()  );
  +		}
  +
  +		try {
  +			Class c=Class.forName( "com.sun.jdmk.comm.HtmlAdaptorServer" );
  +			Object o=c.newInstance();
  +			serverName=new ObjectName("Adaptor:name=html,port=" + port);
  +			log("Registering the JMX_RI html adaptor " + serverName);
  +			mserver.registerMBean(o,  serverName);
  +
  +			mserver.setAttribute(serverName,
  +								 new Attribute("Port", new Integer(port)));
  +
  +			mserver.invoke(serverName, "start", null, null);
  +			log( "Start JMX_RI http adaptor at port " + port);
  +
  +		} catch( Throwable t ) {
  +			log( "Can't load the JMX_RI http adaptor " + t.toString()  );
  +		}
  +	}
   
  -            mserver.invoke(serverName, "start", null, null);
  -            log( "Start JMX_RI http adaptor at port " + port);
  -
  -        } catch( Throwable t ) {
  -            log( "Can't load the JMX_RI http adapter " + t.toString()  );
  -        }
  +    /** Initialize the worker. After this call the worker will be
  +     *  ready to accept new requests.
  +     */
  +    public void loadAdaptor() throws IOException {
  +    	
  +    	if (type.equalsIgnoreCase("jrmp"))
  +    		loadJRMPAdaptor();
  +    	else
  +			loadHTTPAdaptor();
       }
  +    	
   
       public void destroy() {
           try {
  @@ -233,7 +307,7 @@
   
                   if( port > 0 ) {
                       try {
  -                        loadAdapter();
  +                        loadAdaptor();
                       }
                       catch (IOException ioe)
                       {
  
  
  
  1.2       +22 -5     jakarta-tomcat/proposals/JmxSupport/WEB-INF/classes/org/apache/tomcat/modules/config/DynamicMBeanProxy.java
  
  Index: DynamicMBeanProxy.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/JmxSupport/WEB-INF/classes/org/apache/tomcat/modules/config/DynamicMBeanProxy.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DynamicMBeanProxy.java	30 Sep 2002 02:17:43 -0000	1.1
  +++ DynamicMBeanProxy.java	29 Sep 2003 07:38:10 -0000	1.2
  @@ -59,11 +59,28 @@
   
   package org.apache.tomcat.modules.config;
   
  -import java.io.*;
  -import java.net.*;
  -import java.lang.reflect.*;
  -import java.util.*;
  -import javax.management.*;
  +import java.lang.reflect.InvocationTargetException;
  +import java.lang.reflect.Method;
  +import java.lang.reflect.Modifier;
  +import java.util.Enumeration;
  +import java.util.Hashtable;
  +import java.util.Iterator;
  +
  +import javax.management.Attribute;
  +import javax.management.AttributeList;
  +import javax.management.AttributeNotFoundException;
  +import javax.management.DynamicMBean;
  +import javax.management.InvalidAttributeValueException;
  +import javax.management.MBeanAttributeInfo;
  +import javax.management.MBeanConstructorInfo;
  +import javax.management.MBeanException;
  +import javax.management.MBeanInfo;
  +import javax.management.MBeanNotificationInfo;
  +import javax.management.MBeanOperationInfo;
  +import javax.management.MBeanServer;
  +import javax.management.MBeanServerFactory;
  +import javax.management.ObjectName;
  +import javax.management.ReflectionException;
   
   /**
    * DynamicMBean implementation using introspection to manage any
  
  
  

Mime
View raw message