001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)ManagementContext.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.management.system;
030:
031: import java.util.logging.Logger;
032: import java.util.logging.Level;
033: import javax.management.MBeanServer;
034: import javax.management.MBeanServerConnection;
035: import javax.management.ObjectName;
036: import javax.management.remote.JMXConnectorServer;
037: import com.sun.jbi.EnvironmentContext;
038: import com.sun.jbi.VersionInfo;
039: import com.sun.jbi.management.MBeanNames;
040: import com.sun.jbi.management.MBeanHelper;
041: import com.sun.jbi.management.repository.Repository;
042: import com.sun.jbi.management.registry.Registry;
043:
044: import com.sun.jbi.JBIProvider;
045:
046: /**
047: * ManagementContext selects attributes from the Framework EnvironmentContext
048: * that are used by the management services, and adds attributes that are exclusive
049: * to the management services.
050: *
051: * @author Sun Microsystems, Inc.
052: */
053: public class ManagementContext {
054:
055: /** private copy of the framework's EnvironmentContext. */
056: private static EnvironmentContext sEnv = null;
057:
058: /** Logger for the management service. */
059: private static Logger sLog = null;
060:
061: /** MBeanHelper for the management service. */
062: private static MBeanHelper sMBeanHelper = null;
063:
064: /* Management Message Object */
065: private static BuildManagementMessageImpl mMMImpl = null;
066:
067: /** Repository containing JBI archives. There is only one instance
068: * of the repository in a JBI environment.
069: */
070: private static Repository sRepository;
071:
072: /**
073: * Constructs a <CODE>ManagementContext</CODE>.
074: * @param anEnv the base framework environment that we re-exporting.
075: */
076: public ManagementContext(EnvironmentContext anEnv) {
077: sEnv = anEnv;
078: // This logger inherits the level from "com.sun.jbi"
079: sLog = Logger.getLogger("com.sun.jbi.management");
080:
081: //allocate a MBeanHelper (note the typecast):
082: sMBeanHelper = (MBeanHelper) anEnv.getMBeanHelper();
083: }
084:
085: ////////////
086: //Attributes following are copied from the framework's EnvironmentContext.
087: ////////////
088:
089: /**
090: * Get the installation root directory of the JBI system.
091: * @return String containing the installation root directory path
092: */
093: public static String getJbiInstallRoot() {
094: return sEnv.getJbiInstanceRoot();
095: }
096:
097: /**
098: * Get the installation root directory of the JBI system.
099: * @return String containing the installation root directory path
100: */
101: public static VersionInfo getVersionInfo() {
102: return sEnv.getVersionInfo();
103: }
104:
105: /**
106: * Get the logger for the ManagementService.
107: * @return java.util.Logger is the logger
108: */
109: public static Logger getLogger() {
110: return sLog;
111: }
112:
113: /**
114: * Get the MBeanNames service handle.
115: * @return The handle to the MBeanNames.
116: */
117: public static MBeanNames getMBeanNames() {
118: return (com.sun.jbi.management.MBeanNames) sEnv.getMBeanNames();
119: }
120:
121: /**
122: * @return the MBeanNamesImpl for a specific instance
123: */
124: public MBeanNames getMBeanNames(String instanceName) {
125: ObjectName someName = getMBeanNames().getBindingMBeanName(
126: "xyz", MBeanNames.CONTROL_TYPE_LIFECYCLE);
127:
128: String domainName = someName.getDomain();
129:
130: com.sun.jbi.management.support.MBeanNamesImpl mbnNames = new com.sun.jbi.management.support.MBeanNamesImpl(
131: domainName, instanceName);
132:
133: return mbnNames;
134: }
135:
136: /**
137: * Get the handle for the MBeanHelper class.
138: * @return The handle to the MBeanHelper.
139: */
140: public static MBeanHelper getMBeanHelper() {
141: //TODO: replace this with the framework version once it is available:
142: return sMBeanHelper;
143: }
144:
145: /**
146: * Get the MBean server with which all MBeans are registered.
147: * @return javax.management.MBeanServer the main MBean server
148: */
149: public static MBeanServer getMBeanServer() {
150: return sEnv.getMBeanServer();
151: }
152:
153: /**
154: * Get the Central MBean server for the ${ESB}.
155: * @return the Master Agent MBean Server Connection
156: */
157: public static MBeanServerConnection getCentralMBeanServer() {
158: return sEnv.getMBeanServer();
159: }
160:
161: /**
162: * Get the Component Manager service handle.
163: * @return com.sun.jbi.ComponentManager the Component Manager service.
164: */
165: public com.sun.jbi.ComponentManager getComponentManager() {
166: return sEnv.getComponentManager();
167: }
168:
169: /**
170: * Get the Component Query service handle.
171: * @return com.sun.jbi.ComponentQuery the Component Query service.
172: */
173: public com.sun.jbi.ComponentQuery getComponentQuery() {
174: return sEnv.getComponentQuery();
175: }
176:
177: /**
178: * Get a handle to the class implementing management for the named
179: * JBI system service.
180: * @param aServiceName is the name of the management service.
181: * @return Object is the class implementing manangment.
182: */
183: public Object getManagementClass(String aServiceName) {
184: return sEnv.getManagementClass(aServiceName);
185: }
186:
187: ////////////
188: //Attributes following are only used by the management services:
189: ////////////
190:
191: /**
192: * Get the JBI_DOMAIN_ROOT.
193: * @return string representing JBI domain root directory
194: */
195: public static String getJbiDomainRoot() {
196: return System.getProperty("com.sun.jbi.domain.root");
197: }
198:
199: /**
200: * Get the framework environment context.
201: * @return reference to the framework EnvironmentContext
202: */
203: public static EnvironmentContext getEnvironmentContext() {
204: return sEnv;
205: }
206:
207: /**
208: * Getter for JbiPropertiesFileName.
209: * @return the current value of JbiPropertiesFileName.
210: * @deprecated - used by jbisan only
211: */
212: public static String getJbiPropertiesFullPath() {
213: return getJbiDomainRoot() + "/jbi/config/jbienv.properties";
214: }
215:
216: /**
217: * Get the management message object.
218: * @return BuildManagementMessageImpl is the message object
219: */
220: public synchronized static BuildManagementMessageImpl getManagementMessageObject() {
221: if (mMMImpl == null) {
222: mMMImpl = new BuildManagementMessageImpl();
223: }
224: return mMMImpl;
225: }
226:
227: /**
228: * Get the ServiceUnitRegistration handle.
229: * @return com.sun.jbi.ServiceUnitRegistation service unit registration handle.
230: */
231: public com.sun.jbi.ServiceUnitRegistration getServiceUnitRegistration() {
232: return sEnv.getServiceUnitRegistration();
233: }
234:
235: /** Private storage for MBeanServerPort: */
236: private static int sMBeanServerPort;
237:
238: /**
239: * Setter for MBeanServerPort.
240: * @param aMBeanServerPort - the initialization value.
241: */
242: public static void setMBeanServerPort(int aMBeanServerPort) {
243: sMBeanServerPort = aMBeanServerPort;
244: }
245:
246: /**
247: * Getter for MBeanServerPort.
248: * @return the current value of MBeanServerPort.
249: */
250: public static int getMBeanServerPort() {
251: return sMBeanServerPort;
252: }
253:
254: /** Private storage for JmxRemoteServer: */
255: private static JMXConnectorServer sJmxRemoteServer;
256:
257: /**
258: * Setter for JmxRemoteServer.
259: * @param aJmxRemoteServer - the initialization value.
260: */
261: public static void setJmxRemoteServer(
262: JMXConnectorServer aJmxRemoteServer) {
263: sJmxRemoteServer = aJmxRemoteServer;
264: }
265:
266: /**
267: * Getter for JmxRemoteServer.
268: * @return the current value of JmxRemoteServer.
269: */
270: public static JMXConnectorServer getJmxRemoteServer() {
271: return sJmxRemoteServer;
272: }
273:
274: /** Private storage for JbiRoot: */
275: private static String sJbiRoot;
276:
277: /**
278: * Setter for JbiRoot.
279: * @param aJbiRoot - the initialization value.
280: */
281: public static void setJbiRoot(String aJbiRoot) {
282: sJbiRoot = aJbiRoot;
283: }
284:
285: /**
286: * Getter for JbiRoot.
287: * @return the current value of JbiRoot.
288: */
289: public static String getJbiRoot() {
290: return sJbiRoot;
291: }
292:
293: /** Private storage for AdminServiceHandle: */
294: private static AdminService sAdminServiceHandle;
295:
296: /**
297: * Setter for AdminServiceHandle.
298: * @param aAdminServiceHandle - the initialization value.
299: */
300: public static void setAdminServiceHandle(
301: AdminService aAdminServiceHandle) {
302: sAdminServiceHandle = aAdminServiceHandle;
303: }
304:
305: /**
306: * Getter for AdminServiceHandle.
307: * @return the current value of AdminServiceHandle.
308: */
309: public static AdminService getAdminServiceHandle() {
310: return sAdminServiceHandle;
311: }
312:
313: /** Private storage for ConfigurationServiceHandle: */
314: private static ConfigurationService sConfigurationServiceHandle;
315:
316: /**
317: * Setter for ConfigurationServiceHandle.
318: * @param aConfigurationServiceHandle - the initialization value.
319: *
320: public static
321: void setConfigurationServiceHandle(ConfigurationService aConfigurationServiceHandle)
322: {
323: sConfigurationServiceHandle = aConfigurationServiceHandle;
324: }*/
325:
326: /**
327: * Getter for ConfigurationServiceHandle.
328: * @return the current value of ConfigurationServiceHandle.
329: *
330: public static ConfigurationService
331: getConfigurationServiceHandle()
332: {
333: return sConfigurationServiceHandle;
334: }*/
335:
336: /** Private storage for DeploymentServiceHandle: */
337: private static DeploymentService sDeploymentServiceHandle;
338:
339: /**
340: * Setter for DeploymentServiceHandle.
341: * @param aDeploymentServiceHandle - the initialization value.
342: */
343: public static void setDeploymentServiceHandle(
344: DeploymentService aDeploymentServiceHandle) {
345: sDeploymentServiceHandle = aDeploymentServiceHandle;
346: }
347:
348: /**
349: * Getter for DeploymentServiceHandle.
350: * @return the current value of DeploymentServiceHandle.
351: */
352: public static DeploymentService getDeploymentServiceHandle() {
353: return sDeploymentServiceHandle;
354: }
355:
356: /** Private storage for InstallationServiceHandle: */
357: private static InstallationService sInstallationServiceHandle;
358:
359: /**
360: * Setter for InstallationServiceHandle.
361: * @param aInstallationServiceHandle - the initialization value.
362: */
363: public static void setInstallationServiceHandle(
364: InstallationService aInstallationServiceHandle) {
365: sInstallationServiceHandle = aInstallationServiceHandle;
366: }
367:
368: /**
369: * Getter for InstallationServiceHandle.
370: * @return the current value of InstallationServiceHandle.
371: */
372: public static InstallationService getInstallationServiceHandle() {
373: return sInstallationServiceHandle;
374: }
375:
376: /** Private storage for LoggingServiceHandle: */
377: private static LoggingService sLoggingServiceHandle;
378:
379: /**
380: * Setter for LoggingServiceHandle.
381: * @param aLoggingServiceHandle - the initialization value.
382: */
383: public static void setLoggingServiceHandle(
384: LoggingService aLoggingServiceHandle) {
385: sLoggingServiceHandle = aLoggingServiceHandle;
386: }
387:
388: /**
389: * Getter for LoggingServiceHandle.
390: * @return the current value of LoggingServiceHandle.
391: */
392: public static LoggingService getLoggingServiceHandle() {
393: return sLoggingServiceHandle;
394: }
395:
396: /**
397: * Get the ConnectionManager handle.
398: * @return The ConnectionManager instance.
399: */
400: public static com.sun.jbi.messaging.ConnectionManager getConnectionManager() {
401: return sEnv.getConnectionManager();
402: }
403:
404: /**
405: * Get the FrameworkConfiguration MBean Object Name.
406: *
407: * @return the FrameworkConfiguration MBean ObjectName
408: */
409: public static ObjectName getFrameworkConfigurationMBeanName() {
410: return getMBeanNames().getSystemServiceMBeanName(
411: getMBeanNames().SERVICE_NAME_FRAMEWORK,
412: getMBeanNames().CONTROL_TYPE_CONFIGURATION);
413: }
414:
415: public Repository getRepository() {
416: return sRepository;
417: }
418:
419: public void setRepository(Repository repos) {
420: sRepository = repos;
421: }
422:
423: }
|