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: * @(#)MessageServiceStatistics.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.Date;
032: import java.util.logging.Logger;
033: import java.util.logging.Level;
034: import javax.management.openmbean.CompositeData;
035: import javax.management.openmbean.OpenDataException;
036:
037: import com.sun.jbi.EnvironmentContext;
038: import com.sun.jbi.StringTranslator;
039: import com.sun.jbi.management.LocalStringKeys;
040:
041: /**
042: * This class implements the MBean for collection of statistics for the
043: * deployment service. All statistics are since the last deployment service startup;
044: * they are all reset when the deployment service is restarted.
045: *
046: * @author Sun Microsystems, Inc.
047: */
048: public class DeploymentServiceStatistics implements
049: DeploymentServiceStatisticsMBean {
050: /** reference to deployment service */
051: private DeploymentService mDeploymentService;
052:
053: /**
054: * Time the deployment service was last successfully started.
055: */
056: private Date mLastRestartTime;
057:
058: /**
059: * EnvironmentContext
060: */
061: private EnvironmentContext mEnvContext;
062:
063: /**
064: * string translator
065: */
066: private StringTranslator mTranslator;
067:
068: /**
069: * logger
070: */
071: private Logger logger;
072:
073: /**
074: * Constructor to create the StatisticsBase and MessagingStatistics
075: * instances.
076: * @param mDeploySvc reference to the deployment service
077: * @param env EnvironmentContect
078: */
079: DeploymentServiceStatistics(DeploymentService mDeploySvc,
080: EnvironmentContext env) {
081: mDeploymentService = mDeploySvc;
082: mEnvContext = env;
083: mTranslator = (StringTranslator) mEnvContext
084: .getStringTranslator("com.sun.jbi.management");
085: String loggerName = com.sun.jbi.management.config.LoggerConfigurationFactory.DEPLOYMENT_LOGGER;
086: logger = Logger.getLogger(loggerName);
087: }
088:
089: /**
090: * Disable statistics collection. This method causes collection for this
091: * object and all its child objects to be disabled.
092: */
093: public void setDisabled() {
094: mDeploymentService.disableStatistics();
095: }
096:
097: /**
098: * Enable statistics collection. This method causes collection for this
099: * object and all its child objects to be disabled.
100: */
101: public void setEnabled() {
102: mDeploymentService.enableStatistics();
103: }
104:
105: /**
106: * Check if statistics collection is enabled
107: * @return true if enabled
108: */
109: public boolean isEnabled() {
110: return mDeploymentService.isStatisticsEnabled();
111: }
112:
113: /**
114: * Get the time that the deployment service was last started.
115: * @return The time of the last successful start() call.
116: */
117: public Date getLastRestartTime() {
118: return mLastRestartTime;
119: }
120:
121: /**
122: * This method is used to set the last restart time.
123: * @param The time of the last successful init() call.
124: */
125: public void setLastRestartTime(Date restartTime) {
126: mLastRestartTime = restartTime;
127: }
128:
129: /**
130: * Get the CompositeData instance that represents the current values for
131: * Service Assembly statistics.
132: * @param serviceAssemblyName SA name
133: * @return SA statistics in a CompositedData instance
134: */
135: public CompositeData getServiceAssemblyStatistics(
136: String serviceAssemblyName) throws OpenDataException,
137: RuntimeException {
138: ServiceAssemblyStatistics saStats = mDeploymentService
139: .getServiceAssemblyStatistics(serviceAssemblyName);
140: CompositeData cdata = null;
141: try {
142: if (saStats != null) {
143: cdata = saStats.getCompositeData();
144: }
145: } catch (OpenDataException ode) {
146: String message = mTranslator
147: .getString(
148: LocalStringKeys.DS_ERROR_IN_COMPOSING_STATISTICS_FOR_SA,
149: new Object[] {});
150: logger.warning(message);
151: if (ode.getMessage() != null) {
152: logger.log(Level.WARNING, ode.getMessage(), ode);
153: }
154: }
155: return cdata;
156: }
157: }
|