KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > scalagent > jmx > JMXRIHttpService


1 /*
2  * Copyright (C) 2001 - 2005 ScalAgent Distributed Technologies
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17  * USA.
18  */

19 package com.scalagent.jmx;
20
21 import java.io.*;
22 import java.util.*;
23
24 import com.sun.jdmk.comm.*;
25 import javax.management.*;
26
27 import org.objectweb.util.monolog.api.BasicLevel;
28 import org.objectweb.util.monolog.api.Logger;
29 import org.objectweb.util.monolog.api.LoggerFactory;
30
31 import fr.dyade.aaa.util.Debug;
32 import fr.dyade.aaa.util.management.MXWrapper;
33
34 /**
35  * A <code>JMXRIHttpService</code> service provides a JMX server throught the
36  * Sun RI. An HTTP adaptor is launch to access management functions in running
37  * agent servers.
38  * <p>
39  * The <code>JMXRIHttpService</code> service needs an argument: the TCP port.
40  * By default port 8082 is used.
41  */

42 public class JMXRIHttpService {
43   static HtmlAdaptorServer adapterServer = null;
44
45   /**
46    * Initializes the service.
47    *
48    * @param args parameters from the configuration file
49    * @param firstTime <code>true</code> when service starts anew
50    */

51   public static void init(String JavaDoc args,
52                           boolean firstTime) throws Exception JavaDoc {
53     int port = 8082;
54     if (args != null && args.length()!=0) {
55       try {
56     port = Integer.parseInt(args);
57       } catch (NumberFormatException JavaDoc exc) {}
58     }
59
60     try {
61       adapterServer = new HtmlAdaptorServer();
62       adapterServer.setPort(port);
63       MXWrapper.registerMBean(adapterServer,
64                               "JMXRIHttpService",
65                               "name=htmladapter,port=" + port);
66
67       startService();
68     } catch (Exception JavaDoc exc) {
69       Debug.getLogger("com.scalagent.jmx").log(
70         BasicLevel.ERROR, "JMXRIService initialization failed", exc);
71       throw exc;
72     }
73   }
74  
75   public static void startService() {
76     Debug.getLogger("com.scalagent.jmx").log(BasicLevel.DEBUG,
77                                              "JMXRIHttpService.startService");
78
79     adapterServer.start();
80   }
81
82   public static void stopService() {
83     Debug.getLogger("com.scalagent.jmx").log(BasicLevel.DEBUG,
84                                              "JMXRIHttpService.stopService");
85
86     adapterServer.stop();
87   }
88
89 }
90
Popular Tags