KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > server > core > mbean > config > ManagedJVM


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.mbean.config;
25
26 /**
27     Represents the manageable Java Virtual Machine. Various things can be
28     queried for in this JVM. An MBean correponding to this JVM will be
29     registered in the MBeanServer. The JVM will be always associated with
30     a Server Instance or the Admin Server. JVMPI will be used to get
31     certain management information from a running JVM.
32     <p>
33     For iAS SE it is thought that there will be one JVM per Server Instance.
34     But it should be possible to have multiple JVMs.
35     <p>
36     ObjectName of this MBean is:
37         ias:type=jvm, ServerInstance=<serverInstance>
38 */

39
40 //JMX imports
41
import javax.management.*;
42
43 //Config imports
44
import com.sun.enterprise.config.ConfigException;
45 import com.sun.enterprise.config.serverbeans.ServerTags;
46 import com.sun.enterprise.config.serverbeans.JavaConfig;
47 import com.sun.enterprise.config.serverbeans.Profiler;
48
49 //Admin imports
50
import com.sun.enterprise.admin.server.core.mbean.meta.MBeanEasyConfig;
51 import com.sun.enterprise.admin.common.exception.MBeanConfigException;
52 import com.sun.enterprise.admin.common.constant.ConfigAttributeName;
53 import com.sun.enterprise.admin.common.ObjectNames;
54
55 public class ManagedJVM extends ConfigMBeanBase implements ConfigAttributeName.JavaConfig
56 {
57  private static final String JavaDoc[][] MAPLIST = {
58    { kJavaHome, ATTRIBUTE + ServerTags.JAVA_HOME },
59    { kDebugEnabled, ATTRIBUTE + ServerTags.DEBUG_ENABLED },
60    { kDebugOptions, ATTRIBUTE + ServerTags.DEBUG_OPTIONS },
61    { kRmicOptions, ATTRIBUTE + ServerTags.RMIC_OPTIONS},
62    { kJavacOptions, ATTRIBUTE + ServerTags.JAVAC_OPTIONS},
63    { kClasspathPrefix, ATTRIBUTE + ServerTags.CLASSPATH_PREFIX},
64     { kServerClasspath, ATTRIBUTE + ServerTags.SERVER_CLASSPATH},
65    { kClasspathSuffix, ATTRIBUTE + ServerTags.CLASSPATH_SUFFIX},
66    { kNativeLibraryPathPrefix, ATTRIBUTE + ServerTags.NATIVE_LIBRARY_PATH_PREFIX},
67    { kNativeLibraryPathSuffix, ATTRIBUTE + ServerTags.NATIVE_LIBRARY_PATH_SUFFIX},
68    { kEnvClasspathIgnored, ATTRIBUTE + ServerTags.ENV_CLASSPATH_IGNORED},
69  };
70
71  private static final String JavaDoc[] ATTRIBUTES = {
72     kJavaHome + ", String, RW",
73     kDebugEnabled + ", boolean, RW",
74     kDebugOptions + ", String, RW",
75     kRmicOptions + ", String, RW",
76     kJavacOptions + ", String, RW",
77     kClasspathPrefix + ", String, RW",
78     kServerClasspath + ", String, RW",
79     kClasspathSuffix + ", String, RW",
80     kNativeLibraryPathPrefix + ", String, RW",
81     kNativeLibraryPathSuffix + ", String, RW",
82     kEnvClasspathIgnored + ", boolean, RW",
83  };
84
85  private static final String JavaDoc[] OPERATIONS =
86  {
87     "createProfiler(String name, String classpath, String nativeLibraryPath, Boolean enabled), ACTION",
88     "deleteProfiler(), ACTION",
89     "isProfilerExist(), INFO",
90     "getProfiler(), INFO",
91     "getJvmOptions(), INFO",
92     "setJvmOptions(String[] options), ACTION",
93  };
94
95  private final String JavaDoc JVM_NODE_PATH = "/server/java-config";
96
97     /**
98         Default constructor sets MBean description tables
99     */

100     public ManagedJVM() throws MBeanConfigException
101     {
102         this.setDescriptions(MAPLIST, ATTRIBUTES, OPERATIONS);
103     }
104
105     /**
106         Constructs Config MBean for JAVA-CONFIG.
107         @param instanceName The server instance name.
108     */

109     public ManagedJVM(String JavaDoc instanceName) throws MBeanConfigException
110     {
111         this(); //set description tables
112
initialize(ObjectNames.kJvmType, new String JavaDoc[]{instanceName});
113     }
114
115     /**
116     This operation creates Profiler according to attributes and adds(links) it to current HTTP Service;
117     If attribute is 'null' then default value will be set.
118      */

119     public void createProfiler(String JavaDoc name, String JavaDoc classpath, String JavaDoc nativeLibraryPath, Boolean JavaDoc enabled) throws ConfigException
120     {
121         Profiler element = new Profiler();
122         if(name!=null)
123             element.setName(name);
124         if(classpath!=null)
125             element.setClasspath(classpath);
126         if(nativeLibraryPath!=null)
127             element.setNativeLibraryPath(nativeLibraryPath);
128         if(enabled!=null)
129             element.setEnabled(enabled.booleanValue());
130         JavaConfig javaConfig = (JavaConfig)getBaseConfigBean();
131         javaConfig.setProfiler(element);
132         
133         getConfigContext().flush();
134     }
135     
136     /**
137     This operation deletes Profiler according to id if it connected to current HTTP Service.
138     @throws ConfigException in case of failure.
139      */

140     public void deleteProfiler() throws ConfigException
141     {
142         JavaConfig javaConfig = (JavaConfig)getBaseConfigBean();
143         javaConfig.setProfiler(null);
144         getConfigContext().flush();
145     }
146
147     /**
148     This operation returns true if Profiler connected to current HTTP Service.
149     @throws ConfigException in case of failure.
150      */

151     public boolean isProfilerExist() throws ConfigException
152     {
153         JavaConfig javaConfig = (JavaConfig)getBaseConfigBean();
154         return (javaConfig.getProfiler()!=null);
155     }
156
157     /**
158      * Returns the name of the profiler this JVM is configured with.
159      * Returns null if no profiler is registered.
160      */

161     public String JavaDoc getProfiler() throws ConfigException
162     {
163         String JavaDoc profilerName = null;
164         JavaConfig javaConfig = (JavaConfig)getBaseConfigBean();
165         Profiler profiler = javaConfig.getProfiler();
166         if (profiler != null)
167         {
168             profilerName = profiler.getName();
169         }
170         return profilerName;
171     }
172
173     /**
174     This operation returns list of JvmOptions connected to this class.
175      */

176     public String JavaDoc[] getJvmOptions() throws ConfigException
177     {
178         JavaConfig javaConfig = (JavaConfig)getBaseConfigBean();
179         return javaConfig.getJvmOptions();
180     }
181
182     /**
183     This operation returns list of JvmOptions connected to this class.
184      */

185     public void setJvmOptions(String JavaDoc[] options) throws ConfigException
186     {
187         JavaConfig javaConfig = (JavaConfig)getBaseConfigBean();
188         javaConfig.setJvmOptions(options);
189         getConfigContext().flush();
190     }
191 }
192
Popular Tags