KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > server > core > jmx > AppServerMBeanServerFactory


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.admin.server.core.jmx;
25
26 import javax.management.MBeanServer JavaDoc;
27 import java.lang.management.ManagementFactory JavaDoc;
28
29 /**
30  * AppServer's MBS factory to create a singleton MBS
31  * (with interceptors) necessary for the appserver.
32  *
33  * @author sridatta
34  */

35 public class AppServerMBeanServerFactory {
36     
37     private static MBeanServer JavaDoc _mbs = null;
38     
39     /**
40      * Factory method to generate the only instance of this class in the JVM.
41      * Makes sure that the constructor of this class is called exactly once.
42      *
43      * @return MBeanServer instance by calling private constructor.
44      * @throws InitException if the MBeanServer can not be initialized.
45      */

46     public synchronized static MBeanServer JavaDoc getMBeanServerInstance()
47     throws InitException {
48         if (_mbs == null) {
49             _mbs = getAppServerMBeanServer();
50             //Also bind in JNDI // TBD FIXME
51
// so that it can be used in a generic way
52
}
53         return ( _mbs );
54     }
55     
56     /**
57      * This method gets app server's MBS. First, it
58      * enables AppServer MBS on the builder, then creates
59      * the MBS using the standard mechanism and then
60      * resets the flag. It is synchronized on the builder
61      * since we do not want anyone creating an MBS
62      * during this period.
63      */

64     private static MBeanServer JavaDoc getAppServerMBeanServer() {
65         MBeanServer JavaDoc ms = null;
66         synchronized (AppServerMBeanServerBuilder.class) {
67             AppServerMBeanServerBuilder.enableAppServerMBeanServer(true);
68             try {
69                 ms = ManagementFactory.getPlatformMBeanServer();
70             } finally {
71                 AppServerMBeanServerBuilder.enableAppServerMBeanServer(false);
72             }
73         }
74         return ms;
75     }
76 }
77
Popular Tags