Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

HttpAdaptor.java

00001 /**
00002  * C-JDBC: Clustered JDBC.
00003  * Copyright (C) 2002-2005 French National Institute For Research In Computer
00004  * Science And Control (INRIA).
00005  * Contact: c-jdbc@objectweb.org
00006  * 
00007  * This library is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU Lesser General Public License as published by the
00009  * Free Software Foundation; either version 2.1 of the License, or any later
00010  * version.
00011  * 
00012  * This library is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00015  * for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this library; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00020  *
00021  * Initial developer(s): Marc Wick.
00022  * Contributor(s): ______________________.
00023  */
00024 
00025 package org.objectweb.cjdbc.controller.jmx;
00026 
00027 import java.net.InetAddress;
00028 import java.net.UnknownHostException;
00029 import java.util.ArrayList;
00030 import java.util.List;
00031 
00032 import javax.management.Attribute;
00033 import javax.management.MBeanServer;
00034 import javax.management.ObjectName;
00035 import javax.management.remote.JMXAuthenticator;
00036 
00037 import org.objectweb.cjdbc.common.i18n.Translate;
00038 import org.objectweb.cjdbc.common.jmx.JmxException;
00039 import org.objectweb.cjdbc.common.log.Trace;
00040 import org.objectweb.cjdbc.common.net.SSLConfiguration;
00041 
00042 /**
00043  * This class defines a HttpAdaptor
00044  * 
00045  * @author <a href="mailto:marc.wick@monte-bre.ch">Marc Wick </a>
00046  * @version 1.0
00047  */
00048 public class HttpAdaptor
00049 
00050 {
00051   static Trace                                logger       = Trace
00052                                                                .getLogger("org.objectweb.cjdbc.controller.jmx");
00053 
00054   private String                              hostName;
00055   private int                                 port;
00056   //private JMXAuthenticator authenticator;
00057   private SSLConfiguration                    sslConfig;
00058 
00059   private mx4j.tools.adaptor.http.HttpAdaptor adaptor;
00060   private ObjectName                          objectName;
00061   private ObjectName                          processorName;
00062 
00063   private static List                         httpAdaptors = new ArrayList();
00064 
00065   /**
00066    * Creates a new <code>HttpAdaptor.java</code> object
00067    * 
00068    * @param hostName the host name the adaptor binds to
00069    * @param port the http port
00070    * @param authenticator the authenticator used for the connection, if null no
00071    *          authentication on the connection
00072    * @param sslConfig the ssl configuration, if null ssl is disabled
00073    * @throws JmxException problems to get name of localhost
00074    */
00075   public HttpAdaptor(String hostName, int port, JMXAuthenticator authenticator,
00076       SSLConfiguration sslConfig) throws JmxException
00077   {
00078     if (hostName != null)
00079     {
00080       this.hostName = hostName;
00081     }
00082     else
00083     {
00084       try
00085       {
00086         /** TODO: dssmith - determine applicability of getLocalHost() */
00087         this.hostName = InetAddress.getLocalHost().getHostName();
00088       }
00089       catch (UnknownHostException ex)
00090       {
00091         throw new JmxException(ex);
00092       }
00093     }
00094     this.port = port;
00095     //this.authenticator = authenticator;
00096     this.sslConfig = sslConfig;
00097     addHttpAdaptor(this);
00098   }
00099 
00100   /**
00101    * start the http adaptor
00102    * 
00103    * @throws JmxException the adaptor could not be started
00104    */
00105   public void start() throws JmxException
00106   {
00107     try
00108     {
00109 
00110       MBeanServer server = MBeanServerManager.getInstance();
00111       // register the HTTP adaptor MBean to the agent
00112       logger.info(Translate.get("jmx.create.http.adaptor", new Object[]{
00113           hostName, String.valueOf(port)}));
00114       adaptor = new mx4j.tools.adaptor.http.HttpAdaptor();
00115       objectName = new ObjectName("Server:name=HttpAdaptor");
00116       server.registerMBean(adaptor, objectName);
00117       adaptor.setHost(hostName);
00118       adaptor.setPort(port);
00119       // set XSLT processor
00120       logger.debug(Translate.get("jmx.create.xslt.processor"));
00121       processorName = new ObjectName("Server:name=XSLTProcessor");
00122       server.createMBean(mx4j.tools.adaptor.http.XSLTProcessor.class.getName(),
00123           processorName, null);
00124       server.setAttribute(objectName, new Attribute("ProcessorName",
00125           processorName));
00126       if (this.sslConfig != null)
00127       {
00128         //:TODO
00129         throw new JmxException("ssl for http not implemented");
00130       }
00131       adaptor.start();
00132     }
00133     catch (Exception e)
00134     {
00135       e.printStackTrace();
00136       throw new JmxException(e);
00137     }
00138   }
00139 
00140   /**
00141    * stop the http adaptor
00142    * 
00143    * @throws JmxException problems stoping the adaptor
00144    */
00145   public void stop() throws JmxException
00146   {
00147     try
00148     {
00149       MBeanServer server = MBeanServerManager.getInstance();
00150       adaptor.stop();
00151       server.unregisterMBean(objectName);
00152       server.unregisterMBean(processorName);
00153     }
00154     catch (Exception e)
00155     {
00156       throw new JmxException(e);
00157     }
00158   }
00159 
00160   /**
00161    * Returns a list of HttpAdaptor .
00162    * 
00163    * @return Returns list of HttpAdaptor.
00164    */
00165   public static List getHttpAdaptors()
00166   {
00167     return httpAdaptors;
00168   }
00169 
00170   /**
00171    * Adds an HttpAdaptor to the list.
00172    * 
00173    * @param httpAdaptor The HttpAdaptor to add.
00174    */
00175   private static synchronized void addHttpAdaptor(HttpAdaptor httpAdaptor)
00176   {
00177     httpAdaptors.add(httpAdaptor);
00178   }
00179 }

Generated on Mon Apr 11 22:01:32 2005 for C-JDBC by  doxygen 1.3.9.1