001: /*
002: * <copyright>
003: *
004: * Copyright 1997-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026:
027: package org.cougaar.core.persist;
028:
029: import org.cougaar.core.service.PersistenceMetricsService;
030:
031: /**
032: * {@link org.cougaar.core.service.PersistenceMetricsService.Metric}
033: * implementation.
034: */
035: public class PersistenceMetricImpl implements
036: PersistenceMetricsService.Metric {
037: private String name;
038: private long startTime, endTime, cpuTime, size;
039: private boolean full;
040: private Throwable failed;
041: private PersistencePlugin plugin;
042: private int count;
043:
044: PersistenceMetricImpl(String name, long startTime, long endTime,
045: long cpuTime, long size, boolean full, Throwable failed,
046: PersistencePlugin plugin) {
047: this .name = name;
048: this .startTime = startTime;
049: this .endTime = endTime;
050: this .cpuTime = cpuTime;
051: this .size = size;
052: this .full = full;
053: this .failed = failed;
054: this .plugin = plugin;
055: this .count = 1;
056: }
057:
058: PersistenceMetricImpl() {
059: }
060:
061: void average(PersistenceMetricsService.Metric metric) {
062: startTime += metric.getStartTime();
063: endTime += metric.getEndTime();
064: cpuTime += metric.getCpuTime();
065: size += metric.getSize();
066: count += 1;
067: }
068:
069: public long getStartTime() {
070: return count == 0 ? startTime : startTime / count;
071: }
072:
073: public long getEndTime() {
074: return count == 0 ? endTime : endTime / count;
075: }
076:
077: public long getSize() {
078: return count == 0 ? size : size / count;
079: }
080:
081: public long getCpuTime() {
082: return count == 0 ? cpuTime : cpuTime / count;
083: }
084:
085: public boolean isFull() {
086: return full;
087: }
088:
089: public Throwable getException() {
090: return failed;
091: }
092:
093: public String getName() {
094: return name;
095: }
096:
097: public Class getPersistencePluginClass() {
098: return plugin.getClass();
099: }
100:
101: public String getPersistencePluginName() {
102: return plugin.getName();
103: }
104:
105: public int getPersistencePluginParamCount() {
106: return plugin.getParamCount();
107: }
108:
109: public String getPersistencePluginParam(int i) {
110: return plugin.getParam(i);
111: }
112:
113: public int getCount() {
114: return count;
115: }
116:
117: public String toString() {
118: return (failed == null ? "Persisted " : "Failed ")
119: + (full ? "full" : "delta") + name + ", " + size
120: + " bytes in " + (endTime - startTime) + " ms"
121: + ((cpuTime > 0L) ? (" using " + cpuTime) : "")
122: + " ms cpu";
123: }
124: }
|