KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mortbay > jetty > servlet > jmx > ServletHandlerMBean


1 // ========================================================================
2
// $Id: ServletHandlerMBean.java,v 1.8 2005/08/13 00:01:27 gregwilkins Exp $
3
// Copyright 200-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.servlet.jmx;
17
18 import java.util.HashMap JavaDoc;
19
20 import javax.management.MBeanException JavaDoc;
21 import javax.management.ObjectName JavaDoc;
22
23 import org.apache.commons.logging.Log;
24 import org.mortbay.log.LogFactory;
25 import org.mortbay.http.jmx.HttpHandlerMBean;
26 import org.mortbay.jetty.servlet.ServletHandler;
27 import org.mortbay.jetty.servlet.SessionManager;
28
29 /* ------------------------------------------------------------ */
30 /**
31  *
32  * @version $Revision: 1.8 $
33  * @author Greg Wilkins (gregw)
34  */

35 public class ServletHandlerMBean extends HttpHandlerMBean
36 {
37     /* ------------------------------------------------------------ */
38     private static final Log log = LogFactory.getLog(ServletHandlerMBean.class);
39     private ServletHandler _servletHandler;
40     private HashMap JavaDoc _servletMap = new HashMap JavaDoc();
41     
42     /* ------------------------------------------------------------ */
43     /** Constructor.
44      * @exception MBeanException
45      */

46     public ServletHandlerMBean()
47         throws MBeanException JavaDoc
48     {}
49     
50     /* ------------------------------------------------------------ */
51     protected void defineManagedResource()
52     {
53         super.defineManagedResource();
54         defineAttribute("usingCookies");
55         defineAttribute("servlets",READ_ONLY,ON_MBEAN);
56         defineAttribute("sessionManager",READ_ONLY,ON_MBEAN);
57         _servletHandler=(ServletHandler)getManagedResource();
58     }
59
60     /* ------------------------------------------------------------ */
61     public ObjectName JavaDoc getSessionManager()
62     {
63         SessionManager sm=_servletHandler.getSessionManager();
64         if (sm==null)
65             return null;
66         ObjectName JavaDoc[] on=getComponentMBeans(new Object JavaDoc[]{sm},null);
67         return on[0];
68     }
69
70     
71     /* ------------------------------------------------------------ */
72     public ObjectName JavaDoc[] getServlets()
73     {
74         return getComponentMBeans(_servletHandler.getServlets(), _servletMap);
75     }
76     
77     /* ------------------------------------------------------------ */
78     public void postRegister(Boolean JavaDoc ok)
79     {
80         super.postRegister(ok);
81         if (ok.booleanValue())
82             getSessionManager();
83     }
84     
85     public void postDeregister ()
86     {
87         destroyComponentMBeans(_servletMap);
88         super.postDeregister();
89     }
90 }
91
Popular Tags