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: * @(#)LoggingService.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 javax.management.ObjectName;
032: import com.sun.jbi.management.MBeanNames;
033: import com.sun.jbi.management.support.JbiNameInfo;
034: import com.sun.jbi.management.LocalStringKeys;
035: import com.sun.jbi.StringTranslator;
036: import java.util.ArrayList;
037: import java.util.Iterator;
038: import java.util.Set;
039: import java.util.logging.Logger;
040:
041: /**
042: * This is the JBI Framework Logging Service, which manages the loggers
043: * for all components and system services.
044: *
045: * @author Sun Microsystems, Inc.
046: */
047: public class LoggingService extends ModelSystemService implements
048: LoggingServiceMBean {
049: /** our immutable name: */
050: private final JbiNameInfo mJbiNameInfo = new JbiNameInfo(
051: "LoggingService");
052:
053: /**
054: * Management context
055: */
056: private ManagementContext mContext = null;
057:
058: /**
059: * Management Message Object
060: */
061: private BuildManagementMessageImpl mMMImpl = null;
062:
063: /**
064: * Constructs a LoggingService.
065: * @param anEnv is the ManagementContext.
066: */
067: public LoggingService(ManagementContext anEnv) {
068: mContext = anEnv;
069:
070: /*
071: * Local initialization of this service.
072: * Local routine is responsible for calling super.initModelSystemService(..).
073: */
074: initModelSystemService(anEnv.getEnvironmentContext());
075:
076: mMMImpl = mContext.getManagementMessageObject();
077: }
078:
079: /** local model init - called by constructor - create custom mbeans. */
080: protected void initModelSystemService(
081: com.sun.jbi.EnvironmentContext anEnv) {
082: String loggerName = com.sun.jbi.management.config.LoggerConfigurationFactory.LOGGING_LOGGER;
083:
084: Logger logger = Logger.getLogger(loggerName);
085:
086: //initialize the super.
087: super .initModelSystemService(anEnv, logger, mJbiNameInfo);
088:
089: //add AdminService MBean to START/STOP mbean set:
090: mStartMBeans
091: .add(
092: mLoggingServiceMBeanName,
093: com.sun.jbi.management.system.LoggingServiceMBean.class,
094: this );
095: }
096:
097: /**
098: * Lookup a system LoggerMBean by system service name.
099: * @param aSvcName is the name of the system service
100: * @return the JMX object name of the service LoggerMBean or null
101: */
102: public ObjectName getSystemLoggerMBean(String aSvcName) {
103: MBeanNames mbn = mContext.getMBeanNames();
104: String tmp = mbn.getJmxDomainName();
105:
106: tmp += ":" + mbn.SERVICE_NAME_KEY + "=" + aSvcName;
107: tmp += "," + mbn.CONTROL_TYPE_KEY + "="
108: + mbn.CONTROL_TYPE_LOGGER;
109: tmp += "," + mbn.COMPONENT_TYPE_KEY + "="
110: + mbn.COMPONENT_TYPE_SYSTEM;
111: //wildcard goes at the end:
112: tmp += ",*";
113:
114: //exec the query:
115: ObjectName[] names = queryHelper(tmp);
116:
117: if (names.length >= 1) {
118: if (names.length > 1) {
119: String statusMsg = mTranslator
120: .getString(
121: LocalStringKeys.LS_GETSYSTEMLOGGERMBEAN_TOO_MANY_MBEANS,
122: tmp);
123: mLogger.severe(statusMsg);
124: }
125:
126: //always return the first mbean name, even if many:
127: return names[0];
128: } else {
129: String statusMsg = mTranslator
130: .getString(
131: LocalStringKeys.LS_GETSYSTEMLOGGERMBEAN_LOOKUP_FAILED,
132: tmp);
133: mLogger.warning(statusMsg);
134: }
135:
136: return null;
137: }
138:
139: /**
140: * Looks up LoggerMBeans for all JBI Framework
141: * System Services currently installed.
142: * @return array of object names for all system service LoggerMBeans.
143: * @return zero-length array if no services registered.
144: */
145: public ObjectName[] getSystemLoggerMBeans() {
146: MBeanNames mbn = mContext.getMBeanNames();
147: String tmp = mbn.getJmxDomainName();
148:
149: tmp += ":" + mbn.COMPONENT_TYPE_KEY + "="
150: + mbn.COMPONENT_TYPE_SYSTEM;
151: tmp += "," + mbn.CONTROL_TYPE_KEY + "="
152: + mbn.CONTROL_TYPE_LOGGER;
153: //wildcard goes at the end:
154: tmp += ",*";
155:
156: //exec the query:
157: ObjectName[] names = queryHelper(tmp);
158:
159: //if no logger mbeans found for any system service...
160: if (names.length <= 1) {
161: String statusMsg = mTranslator
162: .getString(LocalStringKeys.LS_GETSYSTEMLOGGERMBEANS_NO_SERVICES);
163: mLogger.severe(statusMsg);
164: return (new ObjectName[0]);
165: }
166:
167: return names;
168: }
169:
170: /**
171: * lookup a JBI Installable Component by its unique ID.
172: * @param aComponentId is the unique ID of the BC or SE.
173: * @return the JMX object name of the LifeCycle MBean for the component
174: */
175: public ObjectName getComponentLoggerMBeanById(String aComponentId) {
176: /*
177: * EXAMPLE:
178: com.sun.jbi:ComponentId=ABC,ControlType=Lifecycle,ComponentType=Installed,*
179: */
180:
181: MBeanNames mbn = mContext.getMBeanNames();
182: String tmp = mbn.getJmxDomainName();
183:
184: tmp += ":" + mbn.COMPONENT_ID_KEY + "=" + aComponentId;
185: tmp += "," + mbn.COMPONENT_TYPE_KEY + "="
186: + mbn.COMPONENT_TYPE_INSTALLED;
187: tmp += "," + mbn.CONTROL_TYPE_KEY + "="
188: + mbn.CONTROL_TYPE_LOGGER;
189: //wildcard goes at the end:
190: tmp += ",*";
191:
192: //exec the query:
193: ObjectName[] names = queryHelper(tmp);
194:
195: /*
196: mLogger.info(
197: "LoggingService.getComponentLoggerMBeanById: T1 names.length=" + names.length );
198: mLogger.info("LoggingService.getComponentLoggerMBeanById: T1 tmp=" + tmp);
199: */
200:
201: if (names.length >= 1) {
202: if (names.length > 1) {
203: String statusMsg = mTranslator
204: .getString(
205: LocalStringKeys.LS_GETCOMPONENTLOGGERMBEANBYID_TOO_MANY_MBEANS,
206: tmp);
207: mLogger.severe(statusMsg);
208: }
209:
210: //always return the first mbean name, even if many:
211: return names[0];
212: } else {
213: String statusMsg = mTranslator
214: .getString(
215: LocalStringKeys.LS_GETCOMPONENTLOGGERMBEANBYID_LOOKUP_FAILED,
216: tmp);
217: mLogger.warning(statusMsg);
218: }
219:
220: return null;
221: }
222:
223: /////////
224: //methods private to LoggingService
225: /////////
226:
227: /**
228: * Stub that calls AdminService queryHelper.
229: * @param qStr is a JMX formatted query string
230: * @return array of JMX object names, possibly of zero length.
231: */
232: private ObjectName[] queryHelper(String qStr) {
233: return mContext.getAdminServiceHandle().queryHelper(qStr);
234: }
235: }
|