costin      2002/06/05 14:27:06

  Added:       jk/java/org/apache/jk/common JkMX.java
  Log:
  Initial code for the (experimental for now ) JMX support for jk.
  
  This is the first step in enabling JMX support for the C components
  and the remote native jk ( there is still a _lot_ of work for this to
  work ). However all java side jk components should magically become
  JMX aware.
  
  Of course this is not enabled by default nor finalized ( there are lots
  of debug infos ). Just some code that may sit in the jar, unused.
  
  Revision  Changes    Path
  1.1                  jakarta-tomcat-connectors/jk/java/org/apache/jk/common/JkMX.java
  
  Index: JkMX.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  package org.apache.jk.common;
  
  import java.io.*;
  import java.net.*;
  import java.util.*;
  
  import org.apache.jk.core.*;
  
  import javax.management.*;
  
  import org.apache.tomcat.util.mx.*;
  
  /** MX-enable jk.
   */
  public class JkMX extends JkHandler
  {
      MBeanServer mserver;
      private boolean mxAdapter=true;
      
      public JkMX()
      {
      }
  
      /* -------------------- Public methods -------------------- */
  
      /** Testing - load the jmx adapter
       */
      public void setLoadAdapter( boolean b ) {
          mxAdapter=b;
      }
      
      public DynamicMBean createMBean( Object proxy, String name ) {
          try {
              // XXX use aliases, suffix only, proxy.getName(), etc
              if( name==null )
                  name=proxy.getClass().getName();
              
              // XXX use jk domain
              String domain = "jk2";
              
              DynamicMBeanProxy mbean=new DynamicMBeanProxy();
  
              mbean.setReal( proxy );
              
              ObjectName oname=new ObjectName( domain + ": name=" + name );
              
              mserver.registerMBean( mbean, oname );
          } catch( Throwable t ) {
              log.error( "Error creating mbean ", t );
          }
          return null;
      }
  
      public void registerName( String name, String className ) {
          
      }
      
      /* ==================== Start/stop ==================== */
  
      /** Initialize the worker. After this call the worker will be
       *  ready to accept new requests.
       */
      public void loadAdapter() throws IOException {
          try {
              ObjectName serverName = new ObjectName("Http:name=HttpAdaptor");
              mserver.createMBean("mx4j.adaptor.http.HttpAdaptor", serverName, null);
              //mserver.setAttribute(serverName, new Attribute("Host", "10.0.0.181"));
              mserver.setAttribute(serverName, new Attribute("Port", new 
Integer(8012)));
              
              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);
  
          } catch( Throwable t ) {
              log.error( "Init error", t );
          }
      }
      public void init() throws IOException {
          try {
              mserver = MBeanServerFactory.createMBeanServer();
  
              if( mxAdapter ) {
                  loadAdapter();
              }
  
              for( int i=0; i< wEnv.getHandlerCount(); i++ ) {
                  JkHandler h=wEnv.getHandler( i );
                  createMBean( h, h.getName() );
              }
              
          } catch( Throwable t ) {
              log.error( "Init error", t );
          }
      }
  
      public void addHandlerCallback( JkHandler w ) {
          if( w!=this ) {
              createMBean( w, w.getName() );
          }
      }
  
  
      private static org.apache.commons.logging.Log log=
          org.apache.commons.logging.LogFactory.getLog( JkMX.class );
  
  }
  
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to