001: /*
002: * MCS Media Computer Software Copyright (c) 2007 by MCS
003: * -------------------------------------- Created on 09.01.2007 by W.Klaas
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
006: * use this file except in compliance with the License. You may obtain a copy of
007: * the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
013: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
014: * License for the specific language governing permissions and limitations under
015: * the License.
016: */
017: package de.mcs.jmeasurement.jmx;
018:
019: import java.io.File;
020: import java.io.FileWriter;
021: import java.io.IOException;
022: import java.io.Writer;
023:
024: import org.xml.sax.SAXException;
025:
026: import de.mcs.jmeasurement.JMConfig;
027: import de.mcs.jmeasurement.MeasureFactory;
028: import de.mcs.jmeasurement.RendererMustNotBeNullException;
029: import de.mcs.jmeasurement.renderer.DefaultHTMLRenderer;
030:
031: /**
032: * The MBean implementation for the configuration. To register this JMX
033: * Extension, you can use the
034: * {@link de.mcs.jmeasurement.MeasureFactory#registerMBeans()} method, so the
035: * MBeans will be registered in the standard MBean server deployed with the JRE.
036: *
037: * @author W.Klaas
038: *
039: */
040: public class JmxConfig implements JmxConfigMBean {
041:
042: /**
043: * @return the backgroundTime
044: */
045: public final int getBackgroundTime() {
046: return MeasureFactory.getConfig().getInteger(
047: JMConfig.OPTION_BACKGROUND_TIME);
048: }
049:
050: /**
051: * @param backgroundTime
052: * the backgroundTime to set
053: */
054: public final void setBackgroundTime(final int backgroundTime) {
055: MeasureFactory.getConfig().setInteger(
056: JMConfig.OPTION_BACKGROUND_TIME, backgroundTime);
057: }
058:
059: /**
060: * @return the configAutofile
061: */
062: public final boolean isConfigAutofile() {
063: return MeasureFactory.getConfig().getBoolean(
064: JMConfig.OPTION_CONFIG_AUTOFILE);
065: }
066:
067: /**
068: * @param configAutofile
069: * the configAutofile to set
070: */
071: public final void setConfigAutofile(final boolean configAutofile) {
072: MeasureFactory.getConfig().setBoolean(
073: JMConfig.OPTION_CONFIG_AUTOFILE, configAutofile);
074: }
075:
076: /**
077: * @return the disableDeviation
078: */
079: public final boolean isDisableDeviation() {
080: return MeasureFactory.getConfig().getBoolean(
081: JMConfig.OPTION_DISABLE_DEVIATION);
082:
083: }
084:
085: /**
086: * @param disableDeviation
087: * the disableDeviation to set
088: */
089: public final void setDisableDeviation(final boolean disableDeviation) {
090: MeasureFactory.getConfig().setBoolean(
091: JMConfig.OPTION_DISABLE_DEVIATION, disableDeviation);
092: }
093:
094: /**
095: * @return the enableAutosnapshot
096: */
097: public final boolean isEnableAutosnapshot() {
098: return MeasureFactory.getConfig().getBoolean(
099: JMConfig.OPTION_ENABLE_AUTOSNAPSHOT);
100:
101: }
102:
103: /**
104: * @param enableAutosnapshot
105: * the enableAutosnapshot to set
106: */
107: public final void setEnableAutosnapshot(
108: final boolean enableAutosnapshot) {
109: MeasureFactory.getConfig()
110: .setBoolean(JMConfig.OPTION_ENABLE_AUTOSNAPSHOT,
111: enableAutosnapshot);
112: }
113:
114: /**
115: * @return the enableMeasurement
116: */
117: public final boolean isEnableMeasurement() {
118: return MeasureFactory.getConfig().getBoolean(
119: JMConfig.OPTION_ENABLE_MEASUREMENT);
120:
121: }
122:
123: /**
124: * @param enableMeasurement
125: * the enableMeasurement to set
126: */
127: public final void setEnableMeasurement(
128: final boolean enableMeasurement) {
129: MeasureFactory.getConfig().setBoolean(
130: JMConfig.OPTION_ENABLE_MEASUREMENT, enableMeasurement);
131: }
132:
133: /**
134: * @return the enableMemorySavings
135: */
136: public final boolean isEnableMemorySavings() {
137: return MeasureFactory.getConfig().getBoolean(
138: JMConfig.OPTION_ENABLE_MEMORY_SAVINGS);
139:
140: }
141:
142: /**
143: * @param enableMemorySavings
144: * the enableMemorySavings to set
145: */
146: public final void setEnableMemorySavings(
147: final boolean enableMemorySavings) {
148: MeasureFactory.getConfig().setBoolean(
149: JMConfig.OPTION_ENABLE_MEMORY_SAVINGS,
150: enableMemorySavings);
151: }
152:
153: /**
154: * @return the exceptionHandling
155: */
156: public final int getExceptionHandling() {
157: return MeasureFactory.getConfig().getInteger(
158: JMConfig.OPTION_EXCEPTION_HANDLING);
159:
160: }
161:
162: /**
163: * @param exceptionHandling
164: * the exceptionHandling to set
165: */
166: public final void setExceptionHandling(final int exceptionHandling) {
167: MeasureFactory.getConfig().setInteger(
168: JMConfig.OPTION_EXCEPTION_HANDLING, exceptionHandling);
169: }
170:
171: /**
172: * @return the pointIdletime
173: */
174: public final int getPointIdletime() {
175: return MeasureFactory.getConfig().getInteger(
176: JMConfig.OPTION_POINT_IDLETIME);
177: }
178:
179: /**
180: * @param pointIdletime
181: * the pointIdletime to set
182: */
183: public final void setPointIdletime(final int pointIdletime) {
184: MeasureFactory.getConfig().setInteger(
185: JMConfig.OPTION_POINT_IDLETIME, pointIdletime);
186: }
187:
188: /**
189: * @return the workingpath
190: */
191: public final String getWorkingpath() {
192: return MeasureFactory.getConfig().getProperty(
193: JMConfig.OPTION_WORKINGPATH);
194: }
195:
196: /**
197: * @param workingpath
198: * the workingpath to set
199: */
200: public final void setWorkingpath(final String workingpath) {
201: MeasureFactory.getConfig().setProperty(
202: JMConfig.OPTION_WORKINGPATH, workingpath);
203: }
204:
205: /**
206: * @return String array with all snapshotnames.
207: */
208: public final String[] getSnapShotNames() {
209: return MeasureFactory.getSnapShotNames();
210: }
211:
212: /**
213: * taking a new shapshot with the given name.
214: *
215: * @param name
216: * name of the snapshot.
217: */
218: public final void takeSnapShot(final String name) {
219: MeasureFactory.takeSnapshot(name);
220: }
221:
222: /**
223: * @param name
224: * name of the snapshot
225: * @param filename
226: * save the snapshot to the desired filename.
227: * @throws IOException
228: * if someting goes wrong.
229: * @throws SAXException
230: * if someting goes wrong.
231: */
232: public final void saveSnapShot(final String name,
233: final String filename) throws SAXException, IOException {
234: MeasureFactory.saveSnapShot(MeasureFactory.getSnapShot(name),
235: new File(filename));
236: }
237:
238: /**
239: * @param filename
240: * save the html report to the desired filename.
241: * @throws IOException
242: * if someting goes wrong.
243: */
244: public final void saveHTMLReport(final String filename)
245: throws IOException {
246: try {
247: Writer writer = new FileWriter(filename);
248: MeasureFactory.getReport(null, new DefaultHTMLRenderer(),
249: writer);
250: writer.close();
251: } catch (RendererMustNotBeNullException e) {
252: e.printStackTrace();
253: }
254: }
255:
256: /**
257: * @return the actual application name.
258: */
259: public final String getApplicationName() {
260: return MeasureFactory.getApplicationName();
261: }
262: }
|