KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mortbay > jetty > jmx > ServerMBean


1 // ========================================================================
2
// $Id: ServerMBean.java,v 1.12 2005/09/16 12:06:59 gregwilkins Exp $
3
// Copyright 1999-2004 Mort Bay Consulting Pty. Ltd.
4
// ------------------------------------------------------------------------
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
// ========================================================================
15

16 package org.mortbay.jetty.jmx;
17
18 import java.io.IOException JavaDoc;
19
20 import javax.management.InstanceNotFoundException JavaDoc;
21 import javax.management.MBeanException JavaDoc;
22 import javax.management.MBeanServer JavaDoc;
23 import javax.management.ObjectName JavaDoc;
24
25 import org.apache.commons.logging.Log;
26 import org.mortbay.log.LogFactory;
27 import org.mortbay.http.jmx.HttpServerMBean;
28 import org.mortbay.jetty.Server;
29 import org.mortbay.util.LogSupport;
30
31 /* ------------------------------------------------------------ */
32 /** JettyServer MBean.
33  * This Model MBean class provides the mapping for HttpServer
34  * management methods. It also registers itself as a membership
35  * listener of the HttpServer, so it can create and destroy MBean
36  * wrappers for listeners and contexts.
37  *
38  * @version $Revision: 1.12 $
39  * @author Greg Wilkins (gregw)
40  */

41 public class ServerMBean extends HttpServerMBean
42 {
43     private static Log log = LogFactory.getLog(ServerMBean.class);
44
45     private Server JavaDoc _jettyServer;
46     private String JavaDoc _configuration;
47
48     /* ------------------------------------------------------------ */
49     /** Constructor.
50      * @exception MBeanException
51      * @exception InstanceNotFoundException
52      */

53     public ServerMBean(Server JavaDoc jettyServer)
54         throws MBeanException JavaDoc, InstanceNotFoundException JavaDoc
55     {
56         super(jettyServer);
57     }
58
59     /* ------------------------------------------------------------ */
60     /** Constructor.
61      * @exception MBeanException
62      * @exception InstanceNotFoundException
63      */

64     public ServerMBean()
65         throws MBeanException JavaDoc, InstanceNotFoundException JavaDoc
66     {
67         this(new Server JavaDoc());
68     }
69
70     /* ------------------------------------------------------------ */
71     /** Constructor.
72      * @param configuration URL or File to jetty.xml style configuration file
73      * @exception IOException
74      * @exception MBeanException
75      * @exception InstanceNotFoundException
76      */

77     public ServerMBean(String JavaDoc configuration)
78         throws IOException JavaDoc,MBeanException JavaDoc, InstanceNotFoundException JavaDoc
79     {
80         this(new Server JavaDoc());
81         _configuration=configuration;
82     }
83
84     /* ------------------------------------------------------------ */
85     protected ObjectName JavaDoc newObjectName(MBeanServer JavaDoc server)
86     {
87         return uniqueObjectName(server, getDefaultDomain()+":Server=");
88     }
89
90     /* ------------------------------------------------------------ */
91     protected void defineManagedResource()
92     {
93         super.defineManagedResource();
94         
95         defineAttribute("configuration");
96         defineAttribute("rootWebApp");
97         defineAttribute("webApplicationConfigurationClassNames");
98         defineOperation("addWebApplication",
99                         new String JavaDoc[]{"java.lang.String",
100                                      "java.lang.String"},
101                         IMPACT_ACTION);
102
103         defineOperation("addWebApplication",
104                         new String JavaDoc[]{"java.lang.String",
105                                      "java.lang.String",
106                                      "java.lang.String"},
107                         IMPACT_ACTION);
108         defineOperation("addWebApplications",
109                         new String JavaDoc[]{"java.lang.String",
110                                      "java.lang.String"},
111                         IMPACT_ACTION);
112         _jettyServer=(Server JavaDoc)getManagedResource();
113     }
114     
115     
116     
117     /* ------------------------------------------------------------ */
118     /**
119      * @param ok
120      */

121     public void postRegister(Boolean JavaDoc ok)
122     {
123         super.postRegister(ok);
124         
125         if (ok.booleanValue())
126         {
127             if (_configuration!=null)
128             {
129                 try
130                 {
131                     _jettyServer.configure(_configuration);
132                     _jettyServer.start();
133                 }
134                 catch(Exception JavaDoc e)
135                 {
136                     log.warn(LogSupport.EXCEPTION,e);
137                 }
138             }
139         }
140     }
141     
142     /* ------------------------------------------------------------ */
143     public void postDeregister()
144     {
145         _configuration=null;
146         try
147         {
148             if (null!=_jettyServer)
149                 _jettyServer.stop();
150         }
151         catch(Exception JavaDoc e)
152         {
153             log.warn(e);
154         }
155         finally
156         {
157             super.postDeregister();
158         }
159         
160     }
161 }
162
Popular Tags