001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tc.objectserver.impl;
006:
007: import com.tc.logging.TCLogger;
008: import com.tc.logging.TCLogging;
009: import com.tc.objectserver.api.GCStats;
010:
011: import java.io.Serializable;
012:
013: public class GCStatsImpl implements GCStats, Serializable {
014: private static final long serialVersionUID = -4177683133067698672L;
015: private static final TCLogger logger = TCLogging
016: .getLogger(GCStatsImpl.class);
017: private static final long NOT_INITIALIZED = -1L;
018:
019: private final int number;
020: private long startTime = NOT_INITIALIZED;
021: private long elapsedTime = NOT_INITIALIZED;
022: private long beginObjectCount = NOT_INITIALIZED;
023: private long candidateGarbageCount = NOT_INITIALIZED;
024: private long actualGarbageCount = NOT_INITIALIZED;
025:
026: public GCStatsImpl(int number) {
027: this .number = number;
028: }
029:
030: public int getIteration() {
031: return this .number;
032: }
033:
034: public synchronized long getStartTime() {
035: if (this .startTime == NOT_INITIALIZED) {
036: errorNotInitialized();
037: }
038: return this .startTime;
039: }
040:
041: public synchronized long getElapsedTime() {
042: if (this .elapsedTime == NOT_INITIALIZED) {
043: errorNotInitialized();
044: }
045: return this .elapsedTime;
046: }
047:
048: public synchronized long getBeginObjectCount() {
049: if (this .beginObjectCount == NOT_INITIALIZED) {
050: errorNotInitialized();
051: }
052: return this .beginObjectCount;
053: }
054:
055: public synchronized long getCandidateGarbageCount() {
056: if (this .candidateGarbageCount == NOT_INITIALIZED) {
057: errorNotInitialized();
058: }
059: return this .candidateGarbageCount;
060: }
061:
062: public synchronized long getActualGarbageCount() {
063: if (this .actualGarbageCount == NOT_INITIALIZED) {
064: errorNotInitialized();
065: }
066: return this .actualGarbageCount;
067: }
068:
069: public synchronized void setActualGarbageCount(long count) {
070: validate(count);
071: this .actualGarbageCount = count;
072: }
073:
074: public synchronized void setBeginObjectCount(long count) {
075: validate(count);
076: this .beginObjectCount = count;
077: }
078:
079: public synchronized void setCandidateGarbageCount(long count) {
080: validate(count);
081: this .candidateGarbageCount = count;
082: }
083:
084: public synchronized void setElapsedTime(long time) {
085: if (time < 0L) {
086: // System timer moved backward.
087: logger
088: .warn("Ssyetm timer moved backward, set GC ElapsedTime to 0");
089: time = 0;
090: }
091: this .elapsedTime = time;
092: }
093:
094: public synchronized void setStartTime(long time) {
095: validate(time);
096: this .startTime = time;
097: }
098:
099: private void validate(long value) {
100: if (value < 0L) {
101: throw new IllegalArgumentException(
102: "Value must be greater than or equal to zero");
103: }
104: }
105:
106: private void errorNotInitialized() {
107: throw new IllegalStateException("Value not initialized");
108: }
109:
110: public String toString() {
111: return "iteration=" + getIteration() + "; startTime="
112: + getStartTime() + "; elapsedTime=" + getElapsedTime()
113: + "; beginObjectCount=" + getBeginObjectCount()
114: + "; candidateGarbageCount="
115: + getCandidateGarbageCount() + "; actualGarbageCount="
116: + getActualGarbageCount();
117: }
118: }
|