001: /*
002: * MCS Media Computer Software Copyright (c) 2007 by MCS
003: * -------------------------------------- Created on 11.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.util.Date;
020:
021: import de.mcs.jmeasurement.DefaultMeasurePoint;
022: import de.mcs.jmeasurement.MeasureFactory;
023: import de.mcs.jmeasurement.MeasurePoint;
024:
025: /**
026: * Proxy class for accessing the real measure point data. Because of the
027: * autosaving feature we needed to determine the real measure point instance for
028: * every data access. So we only save the point name in this class and get the
029: * point by using <code>MeasureFactory.getMeasurePoint(pointName)</code>
030: * method.
031: *
032: * @author W.Klaas
033: *
034: */
035: public class JmxPoint {
036:
037: /** name of the point to use. */
038: private String pointName;
039:
040: /**
041: * Constructor of this proxy class. Only the name will be delivered.
042: *
043: * @param name
044: * name of the point to use.
045: */
046: public JmxPoint(final String name) {
047: this .pointName = name;
048: }
049:
050: /**
051: * getting the name of the point.
052: *
053: * @return name
054: */
055: public final String getName() {
056: return pointName;
057: }
058:
059: /**
060: * dynamic access to the measure point.
061: *
062: * @return MeasurePoint.
063: */
064: private MeasurePoint getPoint() {
065: return MeasureFactory.getMeasurePoint(pointName);
066: }
067:
068: /**
069: * @return the avverafe msec of all monitors of this measure point.
070: */
071: public final long getAverageMSec() {
072: try {
073: return getPoint().getData(
074: DefaultMeasurePoint.DATA_KEY_AVERAGE_MSEC)
075: .getAsLong();
076: } catch (Exception e) {
077: e.printStackTrace();
078: }
079: return 0;
080: }
081:
082: /**
083: * @return the minimum msec of a monitor of this measure point.
084: */
085: public final long getMinMSec() {
086: try {
087: return getPoint().getData(
088: DefaultMeasurePoint.DATA_KEY_MIN_MSEC).getAsLong();
089: } catch (Exception e) {
090: e.printStackTrace();
091: }
092: return 0;
093: }
094:
095: /**
096: * @return the maximum msec of a monitor of this measure point.
097: */
098: public final long getMaxMSec() {
099: try {
100: return getPoint().getData(
101: DefaultMeasurePoint.DATA_KEY_MAX_MSEC).getAsLong();
102: } catch (Exception e) {
103: e.printStackTrace();
104: }
105: return 0;
106: }
107:
108: /**
109: * @return the count of exception of this measure point.
110: */
111: public final String getExceptionList() {
112: try {
113: return getPoint().getData(
114: DefaultMeasurePoint.DATA_KEY_EXCEPTION_LIST)
115: .getAsString();
116: } catch (Exception e) {
117: e.printStackTrace();
118: }
119: return "";
120: }
121:
122: /**
123: * @return the count of exception of this measure point.
124: */
125: public final long getExceptionCount() {
126: try {
127: return getPoint().getData(
128: DefaultMeasurePoint.DATA_KEY_EXCEPTION_COUNT)
129: .getAsLong();
130: } catch (Exception e) {
131: e.printStackTrace();
132: }
133: return 0;
134: }
135:
136: /**
137: * @return the last activation of this measure point.
138: */
139: public final Date getLastActivation() {
140: try {
141: return getPoint().getData(
142: DefaultMeasurePoint.DATA_KEY_LAST_ACTIVATION)
143: .getAsDate();
144: } catch (Exception e) {
145: e.printStackTrace();
146: }
147: return new Date(0);
148: }
149:
150: /**
151: * @return the count of death monitors of this measure point.
152: */
153: public final long getDeathCount() {
154: try {
155: return getPoint().getData(
156: DefaultMeasurePoint.DATA_KEY_DEATH_COUNT)
157: .getAsLong();
158: } catch (Exception e) {
159: e.printStackTrace();
160: }
161: return 0;
162: }
163:
164: /**
165: * @return the maximum active monitors of this measure point.
166: */
167: public final long getMaxActive() {
168: try {
169: return getPoint().getData(
170: DefaultMeasurePoint.DATA_KEY_MAX_ACTIVE)
171: .getAsLong();
172: } catch (Exception e) {
173: e.printStackTrace();
174: }
175: return 0;
176: }
177:
178: /**
179: * @return the active monitors of this measure point.
180: */
181: public final long getActive() {
182: try {
183: return getPoint().getData(
184: DefaultMeasurePoint.DATA_KEY_ACTIVE).getAsLong();
185: } catch (Exception e) {
186: e.printStackTrace();
187: }
188: return 0;
189: }
190:
191: /**
192: * @return the total milli seconds of this measure point.
193: */
194: public final long getTotalMSec() {
195: try {
196: return getPoint().getData(
197: DefaultMeasurePoint.DATA_KEY_TOTAL_MSEC)
198: .getAsLong();
199: } catch (Exception e) {
200: e.printStackTrace();
201: }
202: return -1;
203: }
204:
205: /**
206: * @return the deviation of this measure point.
207: */
208: public final Float getDeviation() {
209: try {
210: return (Float) getPoint().getData(
211: DefaultMeasurePoint.DATA_KEY_DEVIATION).getValue();
212: } catch (Exception e) {
213: e.printStackTrace();
214: }
215: return new Float(0.0);
216: }
217:
218: /**
219: * @return the access count of this measure point.
220: */
221: public final long getAccessCount() {
222: try {
223: return getPoint().getData(
224: DefaultMeasurePoint.DATA_KEY_ACCESS_COUNT)
225: .getAsLong();
226: } catch (Exception e) {
227: e.printStackTrace();
228: }
229: return -1;
230: }
231:
232: /**
233: * @return the priority of this measure point.
234: */
235: public final int getPriority() {
236: try {
237: return getPoint().getData(
238: DefaultMeasurePoint.DATA_KEY_PRIORITY).getAsInt();
239: } catch (Exception e) {
240: e.printStackTrace();
241: }
242: return -1;
243: }
244: }
|