hgomez      2003/10/16 04:41:18

  Modified:    jk/java/org/apache/jk/common JkMX.java
  Log:
  Update code to be able to select HTTP + JRMP support,
  also you should use now mx.enabled
  
  mx.enabled=true
  mx.httpPort=8098
  mx.httpHost=mymachine
  mx.jrmpPort=8098
  mx.jrmpHost=mymachine
  
  
  
  Revision  Changes    Path
  1.17      +73 -47    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.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- JkMX.java 16 Oct 2003 11:09:09 -0000      1.16
  +++ JkMX.java 16 Oct 2003 11:41:18 -0000      1.17
  @@ -76,9 +76,10 @@
   public class JkMX extends JkHandler
   {
       MBeanServer mserver;
  -     private int port=-1;
  -     private String host;
  -     private int jrmpport=1099;
  +     private boolean enabled=false;
  +     private int httpport=-1;
  +     private String httphost="localhost";
  +     private int jrmpport=-1;
        private String jrmphost="localhost";
   
       public JkMX()
  @@ -87,22 +88,42 @@
   
       /* -------------------- Public methods -------------------- */
   
  -     /** Enable the MX4J internal adapter
  +     /** Enable the MX4J adapters (new way)
         */
  -     public void setPort( int i ) {
  -             port=i;
  +     public void setEnabled(boolean b) {
  +             enabled=b;
        }
  -
  +     
  +     public boolean getEnabled() {
  +             return enabled;
  +     }
  +     
  +     /** Enable the MX4J adapters (old way, compatible)
  +      */
  +     public void setPort(int i) {
  +             enabled=(i != -1);
  +     }
  +     
        public int getPort() {
  -             return port;
  +             return ((httpport != -1) ? httpport : jrmpport);
        }
   
  -     public void setHost(String host ) {
  -             this.host=host;
  +     /** Enable the MX4J HTTP internal adapter
  +      */     
  +     public void setHTTPPort( int i ) {
  +             httpport=i;
        }
   
  -     public String getHost() {
  -             return host;
  +     public int getHTTPPort() {
  +             return httpport;
  +     }
  +
  +     public void setHTTPHost(String host ) {
  +             this.httphost=host;
  +     }
  +
  +     public String getHTTPHost() {
  +             return httphost;
        }
   
        /** Enable the MX4J JRMP internal adapter
  @@ -124,21 +145,23 @@
        }
   
       /* ==================== Start/stop ==================== */
  -    ObjectName serverName=null;
  +     ObjectName httpServerName=null;
  +     ObjectName jrmpServerName=null;
   
       /** Initialize the worker. After this call the worker will be
        *  ready to accept new requests.
        */
       public void loadAdapter() throws IOException {
  -        boolean adapterLoaded = false;
  +             boolean httpAdapterLoaded = false;
  +             boolean jrmpAdapterLoaded = false;
   
  -        if (classExists("mx4j.adaptor.http.HttpAdaptor")) {
  +        if ((httpport != -1) && classExists("mx4j.adaptor.http.HttpAdaptor")) {
               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)));
  +                             httpServerName = new 
ObjectName("Http:name=HttpAdaptor");
  +                mserver.createMBean("mx4j.adaptor.http.HttpAdaptor", 
httpServerName, null);
  +                if( httphost!=null )
  +                    mserver.setAttribute(httpServerName, new Attribute("Host", 
httphost));
  +                mserver.setAttribute(httpServerName, new Attribute("Port", new 
Integer(httpport)));
   
                   ObjectName processorName = new 
ObjectName("Http:name=XSLTProcessor");
                   mserver.createMBean("mx4j.adaptor.http.XSLTProcessor", 
processorName, null);
  @@ -146,7 +169,7 @@
                   //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));
  +                mserver.setAttribute(httpServerName, new Attribute("ProcessorName", 
processorName));
   
                   //server.invoke(serverName, "addAuthorization",
                   //             new Object[] {"openjmx", "openjmx"},
  @@ -166,25 +189,25 @@
                   //             server.setAttribute(serverName, new 
Attribute("SocketFactoryName", sslFactory.toString()));
   
                   // starts the server
  -                mserver.invoke(serverName, "start", null, null);
  +                mserver.invoke(httpServerName, "start", null, null);
   
  -                log.info( "Started MX4J console on host " + host + " at port " + 
port);
  +                log.info( "Started MX4J console on host " + httphost + " at port " 
+ httpport);
                   //return;
   
  -                adapterLoaded = true;
  +                             httpAdapterLoaded = true;
   
               } catch( Throwable t ) {
  -                serverName=null;
  +                             httpServerName=null;
                   log.error( "Can't load the MX4J http adapter " + t.toString()  );
               }
           }
   
  -        if (! adapterLoaded && classExists("mx4j.tools.naming.NamingService")) {
  +        if ((jrmpport != -1) && classExists("mx4j.tools.naming.NamingService")) {
               try {
  -                serverName = new ObjectName("Naming:name=rmiregistry");
  -                mserver.createMBean("mx4j.tools.naming.NamingService", serverName, 
null);
  -                mserver.invoke(serverName, "start", null, null);
  -                log.info( "Creating " + serverName );
  +                jrmpServerName = new ObjectName("Naming:name=rmiregistry");
  +                mserver.createMBean("mx4j.tools.naming.NamingService", 
jrmpServerName, null);
  +                mserver.invoke(jrmpServerName, "start", null, null);
  +                log.info( "Creating " + jrmpServerName );
   
                   // Create the JRMP adaptor
                   ObjectName adaptor = new ObjectName("Adaptor:protocol=jrmp");
  @@ -215,36 +238,36 @@
                   //   mbean.start();
                   log.info( "Creating " + adaptor + " on host " + jrmphost + " at 
port " + jrmpport);
   
  -                adapterLoaded = true;
  +                jrmpAdapterLoaded = true;
   
               } catch( Exception ex ) {
  -                             serverName = null;
  +                             jrmpServerName = null;
                   log.error( "MX4j RMI adapter not loaded: " + ex.toString());
               }
           }
   
  -        if (! adapterLoaded && classExists("com.sun.jdmk.comm.HtmlAdaptorServer")) {
  +        if ((httpport != -1) && (! httpAdapterLoaded) && 
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 + " at 
port " + port);
  -                mserver.registerMBean(o,  serverName);
  +                httpServerName=new ObjectName("Adaptor:name=html,port=" + httpport);
  +                log.info("Registering the JMX_RI html adapter " + httpServerName + 
" at port " + httpport);
  +                mserver.registerMBean(o,  httpServerName);
   
  -                mserver.setAttribute(serverName,
  -                                     new Attribute("Port", new Integer(port)));
  +                mserver.setAttribute(httpServerName,
  +                                     new Attribute("Port", new Integer(httpport)));
   
  -                mserver.invoke(serverName, "start", null, null);
  +                mserver.invoke(httpServerName, "start", null, null);
   
  -                adapterLoaded = true;
  +                             httpAdapterLoaded = true;
               } catch( Throwable t ) {
  -                             serverName = null;
  +                             httpServerName = null;
                   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.");
  +        if ((!httpAdapterLoaded) || (!jrmpAdapterLoaded))
  +            log.warn( "No adaptors were loaded but mx.enabled was defined.");
   
       }
   
  @@ -252,9 +275,12 @@
           try {
               log.info("Stoping JMX ");
   
  -            if( serverName!=null ) {
  -                mserver.invoke(serverName, "stop", null, null);
  -            }
  +                     if( httpServerName!=null ) {
  +                             mserver.invoke(httpServerName, "stop", null, null);
  +                     }
  +                     if( jrmpServerName!=null ) {
  +                             mserver.invoke(jrmpServerName, "stop", null, null);
  +                     }
           } catch( Throwable t ) {
               log.error( "Destroy error" + t );
           }
  @@ -264,7 +290,7 @@
           try {
               mserver = getMBeanServer();
   
  -            if( port > 0 ) {
  +            if( enabled ) {
                   loadAdapter();
               }
   
  
  
  

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

Reply via email to