KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > objectserver > impl > GCStatsImpl


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.objectserver.impl;
5
6 import java.io.Serializable JavaDoc;
7
8 import com.tc.objectserver.api.GCStats;
9
10 public class GCStatsImpl implements GCStats, Serializable JavaDoc {
11   private static final long NOT_INITIALIZED = -1L;
12
13   private final int number;
14   private long startTime = NOT_INITIALIZED;
15   private long elapsedTime = NOT_INITIALIZED;
16   private long beginObjectCount = NOT_INITIALIZED;
17   private long candidateGarbageCount = NOT_INITIALIZED;
18   private long actualGarbageCount = NOT_INITIALIZED;
19
20   public GCStatsImpl(int number) {
21     this.number = number;
22   }
23
24   public int getIteration() {
25     return this.number;
26   }
27
28   public synchronized long getStartTime() {
29     if (this.startTime == NOT_INITIALIZED) {
30       errorNotInitialized();
31     }
32     return this.startTime;
33   }
34
35   public synchronized long getElapsedTime() {
36     if (this.elapsedTime == NOT_INITIALIZED) {
37       errorNotInitialized();
38     }
39     return this.elapsedTime;
40   }
41
42   public synchronized long getBeginObjectCount() {
43     if (this.beginObjectCount == NOT_INITIALIZED) {
44       errorNotInitialized();
45     }
46     return this.beginObjectCount;
47   }
48
49   public synchronized long getCandidateGarbageCount() {
50     if (this.candidateGarbageCount == NOT_INITIALIZED) {
51       errorNotInitialized();
52     }
53     return this.candidateGarbageCount;
54   }
55
56   public synchronized long getActualGarbageCount() {
57     if (this.actualGarbageCount == NOT_INITIALIZED) {
58       errorNotInitialized();
59     }
60     return this.actualGarbageCount;
61   }
62
63   public synchronized void setActualGarbageCount(long count) {
64     validate(count);
65     this.actualGarbageCount = count;
66   }
67
68   public synchronized void setBeginObjectCount(long count) {
69     validate(count);
70     this.beginObjectCount = count;
71   }
72
73   public synchronized void setCandidateGarbageCount(long count) {
74     validate(count);
75     this.candidateGarbageCount = count;
76   }
77
78   public synchronized void setElapsedTime(long time) {
79     validate(time);
80     this.elapsedTime = time;
81   }
82
83   public synchronized void setStartTime(long time) {
84     validate(time);
85     this.startTime = time;
86   }
87
88   private void validate(long value) {
89     if (value < 0L) { throw new IllegalArgumentException JavaDoc("Value must be greater than or equal to zero"); }
90   }
91
92   private void errorNotInitialized() {
93     throw new IllegalStateException JavaDoc("Value not initialized");
94   }
95
96   public String JavaDoc toString() {
97     return "iteration="+getIteration()+
98       "; startTime="+getStartTime()+
99       "; elapsedTime="+getElapsedTime()+
100       "; beginObjectCount="+getBeginObjectCount()+
101       "; candidateGarbageCount="+getCandidateGarbageCount()+
102       "; actualGarbageCount="+getActualGarbageCount();
103   }
104 }
105
Popular Tags