KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > common > MBeanServerFactory


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.common;
25
26 //JDK imports
27

28 //JMX imports
29
import javax.management.MBeanServer JavaDoc;
30
31 // i18n import
32
import com.sun.enterprise.admin.util.SOMLocalStringsManager;
33
34 /**
35     A class to create instances of MBeanServer. Note that this is not analogous
36     to classic Factory Pattern, since this factory needs to be initialized
37     according to context. Server Object Model requires MBeanServer reference
38     only when it runs in the context of admin server (meaning it is called from
39     the admin html GUI). In case of clients that do not run in the JVM of the
40     admin server, i.e. CLI and Plugin, Server Object Model does not need the
41     reference to MBeanServer as it goes via the HTTP connector.
42     Hence this class provides a method to initialize the factory. The factory
43     should be initialized at admin server startup. This is currently done
44     in AdminService class.
45
46     @version 1.0
47     @author Kedar Mhaswade
48 */

49
50 public class MBeanServerFactory
51 {
52     public static final String JavaDoc kDefaultInitializerClassName =
53         "com.sun.enterprise.admin.server.core.AdminService";
54
55     private static MBeanServer JavaDoc sMBeanServerInstance = null;
56
57     // i18n SOMLocalStringsManager
58
private static SOMLocalStringsManager localizedStrMgr =
59         SOMLocalStringsManager.getManager( MBeanServerFactory.class );
60
61     /**
62         Initializes this factory. Also creates the singleton MBeanServer instance
63         in the admin server's JVM. It does not allow any class to initialize the
64         factory. Currently only the default initializer is able to create the
65         instance. If the initializer is not the default one then IllegalArgumentException
66         will be thrown. The initializer has to initialize the MBeanServer instance.
67         The parameters may not be null.
68         @param initializer instance of Object with proper class.
69         @param mbs instance of MBeanServer's implementation that acts as singleton.
70         @throws IllegalArgumentException if the contract is not satisfied by caller.
71         @throws IllegalStateException if the initialize has been called already.
72     */

73     public static void initialize(Object JavaDoc initializer, MBeanServer JavaDoc mbs)
74     {
75         if (sMBeanServerInstance != null)
76         {
77             String JavaDoc msg = localizedStrMgr.getString( "admin.common.already_initialized" );
78             throw new IllegalStateException JavaDoc( msg );
79         }
80         if (initializer == null || mbs == null)
81         {
82             String JavaDoc msg = localizedStrMgr.getString( "admin.common.null_arg" );
83             throw new IllegalArgumentException JavaDoc( msg );
84         }
85         if (!initializer.getClass().getName().equals(kDefaultInitializerClassName))
86         {
87             String JavaDoc msg = localizedStrMgr.getString( "admin.common.invalid_initializer" );
88             throw new IllegalArgumentException JavaDoc( msg );
89         }
90         sMBeanServerInstance = mbs;
91     }
92     
93     /**
94         Returns the instance of singleton (for Admin Server's JVM) for MBeanServer.
95         Returns null if the factory is not initiazed earlier. Thus a null will be
96         returned when this method is called in a client's context. In case of
97         Server context, since the initiazation of factory is expected to provide
98         the implementation, this should return a non null value (a valid instance).
99         @return instance of MBeanServer, null if Factory is not initialized.
100     */

101     public static MBeanServer JavaDoc getMBeanServer()
102     {
103         return ( sMBeanServerInstance );
104     }
105 }
106
Popular Tags