KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > controller > jmx > HttpAdaptor


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2005 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Marc Wick.
22  * Contributor(s): ______________________.
23  */

24
25 package org.objectweb.cjdbc.controller.jmx;
26
27 import java.net.InetAddress JavaDoc;
28 import java.net.UnknownHostException JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import java.util.List JavaDoc;
31
32 import javax.management.Attribute JavaDoc;
33 import javax.management.MBeanServer JavaDoc;
34 import javax.management.ObjectName JavaDoc;
35
36 import org.objectweb.cjdbc.common.i18n.Translate;
37 import org.objectweb.cjdbc.common.jmx.JmxException;
38 import org.objectweb.cjdbc.common.log.Trace;
39 import org.objectweb.cjdbc.common.net.SSLConfiguration;
40
41 /**
42  * This class defines a HttpAdaptor
43  *
44  * @author <a HREF="mailto:marc.wick@monte-bre.ch">Marc Wick </a>
45  * @version 1.0
46  */

47 public class HttpAdaptor
48
49 {
50   static Trace logger = Trace
51                                                                .getLogger("org.objectweb.cjdbc.controller.jmx");
52
53   private String JavaDoc hostName;
54   private int port;
55   //private JMXAuthenticator authenticator;
56
private SSLConfiguration sslConfig;
57
58   private mx4j.tools.adaptor.http.HttpAdaptor adaptor;
59   private ObjectName JavaDoc objectName;
60   private ObjectName JavaDoc processorName;
61
62   private static List JavaDoc httpAdaptors = new ArrayList JavaDoc();
63
64   /**
65    * Creates a new <code>HttpAdaptor</code> object
66    *
67    * @param hostName the host name the adaptor binds to
68    * @param port the http port
69    * @param sslConfig the ssl configuration, if null ssl is disabled
70    * @throws JmxException problems to get name of localhost
71    */

72   public HttpAdaptor(String JavaDoc hostName, int port, SSLConfiguration sslConfig)
73       throws JmxException
74   {
75     if (hostName != null)
76     {
77       this.hostName = hostName;
78     }
79     else
80     {
81       try
82       {
83         /** TODO: dssmith - determine applicability of getLocalHost() */
84         this.hostName = InetAddress.getLocalHost().getHostName();
85       }
86       catch (UnknownHostException JavaDoc ex)
87       {
88         throw new JmxException(ex);
89       }
90     }
91     this.port = port;
92     //this.authenticator = authenticator;
93
this.sslConfig = sslConfig;
94     addHttpAdaptor(this);
95   }
96
97   /**
98    * Start the HTTP adaptor
99    *
100    * @throws JmxException the adaptor could not be started
101    */

102   public void start() throws JmxException
103   {
104     try
105     {
106
107       MBeanServer JavaDoc server = MBeanServerManager.getInstance();
108       // register the HTTP adaptor MBean to the agent
109
logger.info(Translate.get("jmx.create.http.adaptor", new Object JavaDoc[]{
110           hostName, String.valueOf(port)}));
111       adaptor = new mx4j.tools.adaptor.http.HttpAdaptor();
112       objectName = new ObjectName JavaDoc("Server:name=HttpAdaptor");
113       server.registerMBean(adaptor, objectName);
114       adaptor.setHost(hostName);
115       adaptor.setPort(port);
116       // set XSLT processor
117
logger.debug(Translate.get("jmx.create.xslt.processor"));
118       processorName = new ObjectName JavaDoc("Server:name=XSLTProcessor");
119       server.createMBean(mx4j.tools.adaptor.http.XSLTProcessor.class.getName(),
120           processorName, null);
121       server.setAttribute(objectName, new Attribute JavaDoc("ProcessorName",
122           processorName));
123       if (this.sslConfig != null)
124       {
125         // TODO: SSL support for HTTP adaptor
126
throw new JmxException("ssl for http not implemented");
127       }
128       adaptor.start();
129     }
130     catch (Exception JavaDoc e)
131     {
132       e.printStackTrace();
133       throw new JmxException(e);
134     }
135   }
136
137   /**
138    * stop the http adaptor
139    *
140    * @throws JmxException problems stoping the adaptor
141    */

142   public void stop() throws JmxException
143   {
144     try
145     {
146       MBeanServer JavaDoc server = MBeanServerManager.getInstance();
147       adaptor.stop();
148       server.unregisterMBean(objectName);
149       server.unregisterMBean(processorName);
150     }
151     catch (Exception JavaDoc e)
152     {
153       throw new JmxException(e);
154     }
155   }
156
157   /**
158    * Returns a list of HttpAdaptor .
159    *
160    * @return Returns list of HttpAdaptor.
161    */

162   public static List JavaDoc getHttpAdaptors()
163   {
164     return httpAdaptors;
165   }
166
167   /**
168    * Adds an HttpAdaptor to the list.
169    *
170    * @param httpAdaptor The HttpAdaptor to add.
171    */

172   private static synchronized void addHttpAdaptor(HttpAdaptor httpAdaptor)
173   {
174     httpAdaptors.add(httpAdaptor);
175   }
176 }
177
Popular Tags