KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > support > BootUtil


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 package com.sun.enterprise.management.support;
24
25 import javax.management.ObjectName JavaDoc;
26 import javax.management.MBeanServer JavaDoc;
27 import javax.management.MBeanServerInvocationHandler JavaDoc;
28
29 import com.sun.appserv.management.base.Util;
30 import com.sun.enterprise.management.support.AMXServerLogger;
31 import com.sun.enterprise.management.support.AMXMBeanRootLogger;
32
33 import com.sun.enterprise.admin.server.core.AdminService;
34
35 /**
36     Utilities to help boot up AMX.
37  */

38 public final class BootUtil
39 {
40     private final String JavaDoc mAppserverDomainName;
41
42     private final String JavaDoc mAMX_JMXDomain;
43     
44     private static BootUtil INSTANCE = null;
45     
46     private boolean mAMXReady;
47     
48     private final boolean mOfflineAMX;
49      
50         private
51     BootUtil(
52         final String JavaDoc appserverDomainName,
53         final boolean offline )
54     {
55         AMXServerLogger.getInstance();
56         AMXMBeanRootLogger.getInstance();
57         
58         mAppserverDomainName = appserverDomainName;
59         mAMX_JMXDomain = appserverDomainName;
60         
61         mAMXReady = false;
62         
63         mOfflineAMX = offline;
64     }
65     
66     /**
67         Return the name of the server in which this code is running.
68      */

69         public String JavaDoc
70     getServerName()
71     {
72         return AdminService.getAdminService().getAdminContext().getServerName();
73     }
74     
75         public static synchronized void
76     init( final boolean offline )
77     {
78         INSTANCE = new BootUtil( "amx", offline );
79     }
80
81         public boolean
82     getOffline()
83     {
84         return mOfflineAMX;
85     }
86
87         public static synchronized BootUtil
88     getInstance()
89     {
90         if ( INSTANCE == null )
91         {
92             throw new IllegalArgumentException JavaDoc( "must call init() first" );
93         }
94
95         return( INSTANCE );
96     }
97     
98         public boolean
99     getAMXReady()
100     {
101         return mAMXReady;
102     }
103     
104         public void
105     setAMXReady( final boolean ready)
106     {
107         if ( mAMXReady && ! ready )
108         {
109             throw new IllegalArgumentException JavaDoc();
110         }
111         
112         mAMXReady = ready;
113     }
114
115         private ObjectName JavaDoc
116     getObjectName( String JavaDoc props )
117     {
118         final String JavaDoc domain = getAMXSupportJMXDomain();
119         
120         return( Util.newObjectName( domain, props ) );
121     }
122     
123         public String JavaDoc
124     getAMXSupportJMXDomain()
125     {
126         return getAMXJMXDomainName() + "-support";
127     }
128     
129         public String JavaDoc
130     getAppserverDomainName()
131     {
132         return( mAppserverDomainName );
133     }
134     
135         public String JavaDoc
136     getAMXJMXDomainName()
137     {
138         return( mAMX_JMXDomain );
139     }
140 }
141
142
143
144
145
146
147
148
149
Popular Tags