Package org.objectweb.speedo.jmx

Source Code of org.objectweb.speedo.jmx.MX4J_HtmlAdaptor

/**
* Speedo: an implementation of JDO compliant personality on top of JORM generic
* I/O sub-system.
* Copyright (C) 2001-2005 France Telecom R&D
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*
*
*
* Contact: speedo@objectweb.org
*
* Authors: S.Chassande-Barrioz.
*
*/
package org.objectweb.speedo.jmx;

import javax.management.Attribute;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;

import mx4j.log.Log;
import mx4j.tools.adaptor.http.HttpAdaptor;
import mx4j.tools.adaptor.http.HttpAdaptorMBean;
import mx4j.tools.adaptor.http.XSLTProcessor;

import org.objectweb.fractal.api.control.BindingController;
import org.objectweb.fractal.api.control.LifeCycleController;
import org.objectweb.fractal.jmx.agent.AdminAttributes;
import org.objectweb.speedo.jmx.api.MX4J_HtmlAdaptorCA;
import org.objectweb.util.monolog.api.BasicLevel;
import org.objectweb.util.monolog.api.Logger;

/**
* This class is an adaptor for the HTML adaptor provided by MX4J.
*
* @author S.Chassande-Barrioz
*/
public class MX4J_HtmlAdaptor
  implements BindingController, LifeCycleController, MX4J_HtmlAdaptorCA {
   
  private static final String ADAPTOR = "MX4J_HtmlAdaptor";
  private final static String BINDING_ADMIN_ATT = "adminAtt";
  private AdminAttributes adminAtt;
  private HttpAdaptorMBean adapter = null;
  private int port;
  private String host;
  private Logger logger;

  private ObjectName getObjectName() throws MalformedObjectNameException {
    String id = '@' + Integer.toHexString(this.hashCode());
      return new ObjectName(ADAPTOR + id
              + ":type=html,port=" + adapter.getPort());
  }

  // --------------------------------------------------------------------------
  // Implementation of the BindingController interface
  // --------------------------------------------------------------------------
  public String[] listFc() {
    return new String[] {BINDING_ADMIN_ATT};
  }

  public Object lookupFc(final String itfName) {
    if (BINDING_ADMIN_ATT.equals(itfName)) {
      return adminAtt;
    } else {
      return null;
    }
  }

  public void bindFc(final String itfName, final Object itfValue) {
      if ("logger".equals(itfName)) {
          logger = (Logger) itfValue;
      } else if (BINDING_ADMIN_ATT.equals(itfName)) {
      adminAtt = (AdminAttributes) itfValue;
    }
  }

  public void unbindFc(final String itfName) {
    if (BINDING_ADMIN_ATT.equals(itfName)) {
      adminAtt = null;
    }
  }
 
  // -------------------------------------------------------------------------
  // implements Attribute controller
  // -------------------------------------------------------------------------

  public int getPort() {
    return port;
  }

  public void setPort(final int port) {
    this.port = port;
  }

  // -------------------------------------------------------------------------
  // implements MX4J_HtmlAdaptatorCA
  // -------------------------------------------------------------------------

  public String getHost() {
    return host;
  }
  public void setHost(String host) {
    this.host = host;
  }
  // -------------------------------------------------------------------------
  // implementation of the LifeCycleController interface
  // -------------------------------------------------------------------------
  public String getFcState() {
    return null;
  }

  public synchronized void startFc() {
    try {
      if (adapter != null
        && adapter.isActive()
        && adapter.getPort() == port) {
        return;
      }
      Log.redirectTo(new MX4JLoggerMonolog(logger));
      MBeanServer server = adminAtt.getRawMBeanServer();
      adapter = new HttpAdaptor();
      server.registerMBean(adapter, getObjectName());

      XSLTProcessor processor = new XSLTProcessor();
      processor.setPathInJar("org/objectweb/speedo/jmx/xsl");
      processor.setUseCache(false);
      ObjectName processorName = new ObjectName("Server:name=XSLTProcessor");
      server.registerMBean(processor, processorName);

      server.setAttribute(getObjectName(),
              new Attribute("ProcessorName", processorName));

      adapter.setPort(port);
      adapter.setHost(host);
      adapter.start();
      logger.log(BasicLevel.INFO, "MX4J HTTP Adaptor launched: "
              + "\n\tUrl: http://" + adapter.getHost()
              + ":" + adapter.getPort());
    } catch (Exception e) {
        logger.log(BasicLevel.ERROR,
                "Error during the instanciation of the MX4J Htttp adaptor:", e);
    }
  }

  public void stopFc() {
    if (adapter != null) {
            logger.log(BasicLevel.INFO, "Stopping MX4J HTTP console of Speedo");
        adapter.stop();
    }
    }
}
TOP

Related Classes of org.objectweb.speedo.jmx.MX4J_HtmlAdaptor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.