tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "RAJENDRA WARRIER" <rajendrawarr...@hotmail.com>
Subject Re: cvs commit: jakarta-tomcat-connectors/jk/java/org/apache/jk/common JkMX.java
Date Mon, 02 Jun 2003 14:12:21 GMT
could you pl. redirect these messages to rajendra_warrier@pharmchem.com

thanks & best  regards
Rajendra K. Warrier





From: funkman@apache.org
Reply-To: "Tomcat Developers List" <tomcat-dev@jakarta.apache.org>
To: jakarta-tomcat-connectors-cvs@apache.org
Subject: cvs commit: jakarta-tomcat-connectors/jk/java/org/apache/jk/common 
JkMX.java
Date: 2 Jun 2003 01:22:33 -0000

funkman     2003/06/01 18:22:33

   Modified:    jk/java/org/apache/jk/common JkMX.java
   Log:
   Check for the existence of the class before trying to load the adapter.
   This is an attempt to prevent the logging of error messages
   since they aren't errors. If no adapters get loaded, but mx.port
   was defined, expose a warning message.

   Revision  Changes    Path
   1.12      +119 -88   
jakarta-tomcat-connectors/jk/java/org/apache/jk/common/JkMX.java

   Index: JkMX.java
   ===================================================================
   RCS file: 
/home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/common/JkMX.java,v
   retrieving revision 1.11
   retrieving revision 1.12
   diff -u -r1.11 -r1.12
   --- JkMX.java	11 Apr 2003 20:25:42 -0000	1.11
   +++ JkMX.java	2 Jun 2003 01:22:32 -0000	1.12
   @@ -78,7 +78,7 @@
        MBeanServer mserver;
        private int port=-1;
        private String host;
   -
   +
        public JkMX()
        {
        }
   @@ -105,105 +105,124 @@

        /* ==================== 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);
   -            if( host!=null )
   -                mserver.setAttribute(serverName, new Attribute("Host", 
host));
   -            mserver.setAttribute(serverName, new Attribute("Port", new 
Integer(port)));
   -
   -            ObjectName processorName = new 
ObjectName("Http:name=XSLTProcessor");
   -            mserver.createMBean("mx4j.adaptor.http.XSLTProcessor", 
processorName, null);
   -
   -            //mserver.setAttribute(processorName, new Attribute("File", 
"/opt/41/server/lib/openjmx-tools.jar"));
   -            //mserver.setAttribute(processorName, new 
Attribute("UseCache", new Boolean(false)));
   -            //mserver.setAttribute(processorName, new 
Attribute("PathInJar", "/openjmx/adaptor/http/xsl"));
   -            mserver.setAttribute(serverName, new 
Attribute("ProcessorName", processorName));
   -
   -            //server.invoke(serverName, "addAuthorization",
   -            //             new Object[] {"openjmx", "openjmx"},
   -            //             new String[] {"java.lang.String", 
"java.lang.String"});
   -
   -            // use basic authentication
   -            //server.setAttribute(serverName, new 
Attribute("AuthenticationMethod", "basic"));
   -
   -            //  ObjectName sslFactory = new 
ObjectName("Adaptor:service=SSLServerSocketFactory");
   -            //         
server.createMBean("openjmx.adaptor.ssl.SSLAdaptorServerSocketFactory", 
sslFactory, null);
   -            //        SSLAdaptorServerSocketFactoryMBean factory =
   -            // 
(SSLAdaptorServerSocketFactoryMBean)StandardMBeanProxy.create(SSLAdaptorServerSocketFactoryMBean.class,

server, sslFactory);
   -            //             // Customize the values below
   -            //             factory.setKeyStoreName("certs");
   -            //             factory.setKeyStorePassword("openjmx");
   -
   -            //             server.setAttribute(serverName, new 
Attribute("SocketFactoryName", sslFactory.toString()));
   +        boolean adapterLoaded = false;
   +
   +        if (classExists("mx4j.adaptor.http")) {
   +            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));
   +                mserver.setAttribute(serverName, new Attribute("Port", 
new Integer(port)));
   +
   +                ObjectName processorName = new 
ObjectName("Http:name=XSLTProcessor");
   +                mserver.createMBean("mx4j.adaptor.http.XSLTProcessor", 
processorName, null);
   +
   +                //mserver.setAttribute(processorName, new 
Attribute("File", "/opt/41/server/lib/openjmx-tools.jar"));
   +                //mserver.setAttribute(processorName, new 
Attribute("UseCache", new Boolean(false)));
   +                //mserver.setAttribute(processorName, new 
Attribute("PathInJar", "/openjmx/adaptor/http/xsl"));
   +                mserver.setAttribute(serverName, new 
Attribute("ProcessorName", processorName));
   +
   +                //server.invoke(serverName, "addAuthorization",
   +                //             new Object[] {"openjmx", "openjmx"},
   +                //             new String[] {"java.lang.String", 
"java.lang.String"});
   +
   +                // use basic authentication
   +                //server.setAttribute(serverName, new 
Attribute("AuthenticationMethod", "basic"));
   +
   +                //  ObjectName sslFactory = new 
ObjectName("Adaptor:service=SSLServerSocketFactory");
   +                //         
server.createMBean("openjmx.adaptor.ssl.SSLAdaptorServerSocketFactory", 
sslFactory, null);
   +                //        SSLAdaptorServerSocketFactoryMBean factory =
   +                // 
(SSLAdaptorServerSocketFactoryMBean)StandardMBeanProxy.create(SSLAdaptorServerSocketFactoryMBean.class,

server, sslFactory);
   +                //             // Customize the values below
   +                //             factory.setKeyStoreName("certs");
   +                //             factory.setKeyStorePassword("openjmx");
   +
   +                //             server.setAttribute(serverName, new 
Attribute("SocketFactoryName", sslFactory.toString()));

   -            // starts the server
   -            mserver.invoke(serverName, "start", null, null);
   +                // starts the server
   +                mserver.invoke(serverName, "start", null, null);

   -            log.info( "Started MX4J console on " + port);
   -            //return;
   -        } catch( Throwable t ) {
   -            serverName=null;
   -            log.error( "Can't load the MX4J http adapter " + 
t.toString()  );
   -        }
   -        try {
   -            ObjectName serverName2 = new 
ObjectName("Naming:name=rmiregistry");
   -            mserver.createMBean("mx4j.tools.naming.NamingService", 
serverName2, null);
   -            mserver.invoke(serverName2, "start", null, null);
   -            log.info( "Creating " + serverName2 );
   -
   -            // Create the JRMP adaptor
   -            ObjectName adaptor = new 
ObjectName("Adaptor:protocol=jrmp");
   -            mserver.createMBean("mx4j.adaptor.rmi.jrmp.JRMPAdaptor", 
adaptor, null);
   -
   -            //    mx4j.adaptor.rmi.jrmp.JRMPAdaptorMBean mbean = 
(mx4j.adaptor.rmi.jrmp.JRMPAdaptorMBean)mx4j.util.StandardMBeanProxy.
   -            //        
create(mx4j.adaptor.rmi.jrmp.JRMPAdaptorMBean.class, mserver, adaptor);
   -
   -            mserver.setAttribute(adaptor, new Attribute("JNDIName", 
"jrmp"));
   -
   -            mserver.invoke( adaptor, "putNamingProperty",
   -                    new Object[] {
   -                        javax.naming.Context.INITIAL_CONTEXT_FACTORY,
   -                        
"com.sun.jndi.rmi.registry.RegistryContextFactory"},
   -                    new String[] { "java.lang.Object", 
"java.lang.Object" });
   -
   -            mserver.invoke( adaptor, "putNamingProperty",
   -                    new Object[] {
   -                        javax.naming.Context.PROVIDER_URL,
   -                        "rmi://localhost:1099"},
   -                    new String[] { "java.lang.Object", 
"java.lang.Object" });
   -
   -            
//mbean.putNamingProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, 
"com.sun.jndi.rmi.registry.RegistryContextFactory");
   -            //mbean.putNamingProperty(javax.naming.Context.PROVIDER_URL, 
"rmi://localhost:1099");
   -            // Registers the JRMP adaptor in JNDI and starts it
   -            mserver.invoke(adaptor, "start", null, null);
   -            //   mbean.start();
   -            log.info( "Creating " + adaptor );
   -        } catch( Exception ex ) {
   -            log.info( "MX4j RMI adapter not loaded: " + ex.toString());
   +                log.info( "Started MX4J console on " + port);
   +                //return;
   +
   +                adapterLoaded = true;
   +
   +            } catch( Throwable t ) {
   +                serverName=null;
   +                log.error( "Can't load the MX4J http adapter " + 
t.toString()  );
   +            }
            }

   +        if (classExists("mx4j.tools.naming.NamingService")) {
   +            try {
   +                ObjectName serverName2 = new 
ObjectName("Naming:name=rmiregistry");
   +                mserver.createMBean("mx4j.tools.naming.NamingService", 
serverName2, null);
   +                mserver.invoke(serverName2, "start", null, null);
   +                log.info( "Creating " + serverName2 );
   +
   +                // Create the JRMP adaptor
   +                ObjectName adaptor = new 
ObjectName("Adaptor:protocol=jrmp");
   +                mserver.createMBean("mx4j.adaptor.rmi.jrmp.JRMPAdaptor", 
adaptor, null);
   +
   +                //    mx4j.adaptor.rmi.jrmp.JRMPAdaptorMBean mbean = 
(mx4j.adaptor.rmi.jrmp.JRMPAdaptorMBean)mx4j.util.StandardMBeanProxy.
   +                //        
create(mx4j.adaptor.rmi.jrmp.JRMPAdaptorMBean.class, mserver, adaptor);
   +
   +                mserver.setAttribute(adaptor, new Attribute("JNDIName", 
"jrmp"));
   +
   +                mserver.invoke( adaptor, "putNamingProperty",
   +                        new Object[] {
   +                            
javax.naming.Context.INITIAL_CONTEXT_FACTORY,
   +                            
"com.sun.jndi.rmi.registry.RegistryContextFactory"},
   +                        new String[] { "java.lang.Object", 
"java.lang.Object" });
   +
   +                mserver.invoke( adaptor, "putNamingProperty",
   +                        new Object[] {
   +                            javax.naming.Context.PROVIDER_URL,
   +                            "rmi://localhost:1099"},
   +                        new String[] { "java.lang.Object", 
"java.lang.Object" });
   +
   +                
//mbean.putNamingProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, 
"com.sun.jndi.rmi.registry.RegistryContextFactory");
   +                
//mbean.putNamingProperty(javax.naming.Context.PROVIDER_URL, 
"rmi://localhost:1099");
   +                // Registers the JRMP adaptor in JNDI and starts it
   +                mserver.invoke(adaptor, "start", null, null);
   +                //   mbean.start();
   +                log.info( "Creating " + adaptor );

   -        try {
   -            Class c=Class.forName( "com.sun.jdmk.comm.HtmlAdaptorServer" 
);
   -            Object o=c.newInstance();
   -            serverName=new ObjectName("Adaptor:name=html,port=" + port);
   -            log.info("Registering the JMX_RI html adapter " + 
serverName);
   -            mserver.registerMBean(o,  serverName);
   +                adapterLoaded = true;

   -            mserver.setAttribute(serverName,
   -                                 new Attribute("Port", new 
Integer(port)));
   +            } catch( Exception ex ) {
   +                log.info( "MX4j RMI adapter not loaded: " + 
ex.toString());
   +            }
   +        }

   -            mserver.invoke(serverName, "start", null, null);
   +        if (classExists("com.sun.jdmk.comm.HtmlAdaptorServer")) {
   +            try {
   +                Class c=Class.forName( 
"com.sun.jdmk.comm.HtmlAdaptorServer" );
   +                Object o=c.newInstance();
   +                serverName=new ObjectName("Adaptor:name=html,port=" + 
port);
   +                log.info("Registering the JMX_RI html adapter " + 
serverName);
   +                mserver.registerMBean(o,  serverName);

   -        } catch( Throwable t ) {
   -            log.error( "Can't load the JMX_RI http adapter " + 
t.toString()  );
   +                mserver.setAttribute(serverName,
   +                                     new Attribute("Port", new 
Integer(port)));
   +
   +                mserver.invoke(serverName, "start", null, null);
   +
   +                adapterLoaded = true;
   +            } catch( Throwable t ) {
   +                log.error( "Can't load the JMX_RI http adapter " + 
t.toString()  );
   +            }
            }
   +
   +        if (!adapterLoaded)
   +            log.warn( "No adaptors were loaded but mx.port was 
defined.");
   +
        }

        public void destroy() {
   @@ -237,7 +256,7 @@

                /*
                DynamicMBeanProxy.createMBean( JkMain.getJkMain(), "jk2", 
"name=JkMain" );
   -
   +
                for( int i=0; i< wEnv.getHandlerCount(); i++ ) {
                    JkHandler h=wEnv.getHandler( i );
                    DynamicMBeanProxy.createMBean( h, "jk2", "name=" + 
h.getName() );
   @@ -263,6 +282,18 @@
                server=MBeanServerFactory.createMBeanServer();
            }
            return (server);
   +    }
   +
   +
   +    private static boolean classExists(String className) {
   +        try {
   +            
Thread.currentThread().getContextClassLoader().loadClass(className);
   +            return true;
   +        } catch(Throwable e) {
   +            if (log.isInfoEnabled())
   +                log.info( "className [" + className + "] does not 
exist");
   +            return false;
   +        }
        }






---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org

_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE*  
http://join.msn.com/?page=features/junkmail


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Mime
View raw message