diff options
author | Ade Lee <alee@redhat.com> | 2011-12-07 16:58:12 -0500 |
---|---|---|
committer | Ade Lee <alee@redhat.com> | 2011-12-07 16:58:12 -0500 |
commit | 32150d3ee32f8ac27118af7c792794b538c78a2f (patch) | |
tree | 52dd96f664a6fa51be25b28b6f10adc5f2c9f660 /pki/base/common/src/com/netscape/cmscore/util/StatsSubsystem.java | |
parent | f05d58a46795553beb8881039cc922974b40db34 (diff) | |
download | pki-32150d3ee32f8ac27118af7c792794b538c78a2f.tar.gz pki-32150d3ee32f8ac27118af7c792794b538c78a2f.tar.xz pki-32150d3ee32f8ac27118af7c792794b538c78a2f.zip |
Formatting
Formatted project according to eclipse project settings
Diffstat (limited to 'pki/base/common/src/com/netscape/cmscore/util/StatsSubsystem.java')
-rw-r--r-- | pki/base/common/src/com/netscape/cmscore/util/StatsSubsystem.java | 226 |
1 files changed, 103 insertions, 123 deletions
diff --git a/pki/base/common/src/com/netscape/cmscore/util/StatsSubsystem.java b/pki/base/common/src/com/netscape/cmscore/util/StatsSubsystem.java index 4cc393e06..809415ffb 100644 --- a/pki/base/common/src/com/netscape/cmscore/util/StatsSubsystem.java +++ b/pki/base/common/src/com/netscape/cmscore/util/StatsSubsystem.java @@ -17,7 +17,6 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.util; - import java.util.Date; import java.util.Hashtable; import java.util.Vector; @@ -30,16 +29,14 @@ import com.netscape.certsrv.util.IStatsSubsystem; import com.netscape.certsrv.util.StatsEvent; /** - * A class represents a internal subsystem. This subsystem - * can be loaded into cert server kernel to perform - * statistics collection. + * A class represents a internal subsystem. This subsystem can be loaded into + * cert server kernel to perform statistics collection. * <P> * * @author thomask * @version $Revision$, $Date$ */ -public class StatsSubsystem implements IStatsSubsystem -{ +public class StatsSubsystem implements IStatsSubsystem { private String mId = null; private StatsEvent mAllTrans = new StatsEvent(null); private Date mStartTime = new Date(); @@ -64,101 +61,90 @@ public class StatsSubsystem implements IStatsSubsystem } /** - * Initializes this subsystem with the given - * configuration store. - * It first initializes resident subsystems, - * and it loads and initializes loadable - * subsystem specified in the configuration - * store. + * Initializes this subsystem with the given configuration store. It first + * initializes resident subsystems, and it loads and initializes loadable + * subsystem specified in the configuration store. * <P> - * Note that individual subsystem should be - * initialized in a separated thread if - * it has dependency on the initialization - * of other subsystems. + * Note that individual subsystem should be initialized in a separated + * thread if it has dependency on the initialization of other subsystems. * <P> - * + * * @param owner owner of this subsystem * @param config configuration store */ public synchronized void init(ISubsystem owner, IConfigStore config) - throws EBaseException - { - } - - public Date getStartTime() - { - return mStartTime; - } - - public void startTiming(String id) - { - startTiming(id, false /* not the main */); - } - - public void startTiming(String id, boolean mainAction) - { - Thread t = Thread.currentThread(); - Vector milestones = null; - if (mHashtable.containsKey(t.toString())) { - milestones = (Vector)mHashtable.get(t.toString()); - } else { - milestones = new Vector(); - mHashtable.put(t.toString(), milestones); - } - long startTime = CMS.getCurrentDate().getTime(); - StatsEvent currentST = null; - for (int i = 0; i < milestones.size(); i++) { - StatsMilestone se = (StatsMilestone)milestones.elementAt(i); - if (currentST == null) { - currentST = mAllTrans.getSubEvent(se.getId()); + throws EBaseException { + } + + public Date getStartTime() { + return mStartTime; + } + + public void startTiming(String id) { + startTiming(id, false /* not the main */); + } + + public void startTiming(String id, boolean mainAction) { + Thread t = Thread.currentThread(); + Vector milestones = null; + if (mHashtable.containsKey(t.toString())) { + milestones = (Vector) mHashtable.get(t.toString()); } else { - currentST = currentST.getSubEvent(se.getId()); + milestones = new Vector(); + mHashtable.put(t.toString(), milestones); + } + long startTime = CMS.getCurrentDate().getTime(); + StatsEvent currentST = null; + for (int i = 0; i < milestones.size(); i++) { + StatsMilestone se = (StatsMilestone) milestones.elementAt(i); + if (currentST == null) { + currentST = mAllTrans.getSubEvent(se.getId()); + } else { + currentST = currentST.getSubEvent(se.getId()); + } + } + if (currentST == null) { + if (!mainAction) { + return; /* ignore none main action */ + } + currentST = mAllTrans; + } + StatsEvent newST = currentST.getSubEvent(id); + if (newST == null) { + newST = new StatsEvent(currentST); + newST.setName(id); + currentST.addSubEvent(newST); + } + milestones.addElement(new StatsMilestone(id, startTime, newST)); + } + + public void endTiming(String id) { + long endTime = CMS.getCurrentDate().getTime(); + Thread t = Thread.currentThread(); + if (!mHashtable.containsKey(t.toString())) { + return; /* error */ + } + Vector milestones = (Vector) mHashtable.get(t.toString()); + if (milestones.size() == 0) { + return; /* error */ + } + StatsMilestone last = (StatsMilestone) milestones.remove(milestones + .size() - 1); + StatsEvent st = last.getStatsEvent(); + st.incNoOfOperations(1); + st.incTimeTaken(endTime - last.getStartTime()); + if (milestones.size() == 0) { + mHashtable.remove(t.toString()); } - } - if (currentST == null) { - if (!mainAction) { - return; /* ignore none main action */ - } - currentST = mAllTrans; - } - StatsEvent newST = currentST.getSubEvent(id); - if (newST == null) { - newST = new StatsEvent(currentST); - newST.setName(id); - currentST.addSubEvent(newST); - } - milestones.addElement(new StatsMilestone(id, startTime, newST)); - } - - public void endTiming(String id) - { - long endTime = CMS.getCurrentDate().getTime(); - Thread t = Thread.currentThread(); - if (!mHashtable.containsKey(t.toString())) { - return; /* error */ - } - Vector milestones = (Vector)mHashtable.get(t.toString()); - if (milestones.size() == 0) { - return; /* error */ - } - StatsMilestone last = (StatsMilestone)milestones.remove(milestones.size() - 1); - StatsEvent st = last.getStatsEvent(); - st.incNoOfOperations(1); - st.incTimeTaken(endTime - last.getStartTime()); - if (milestones.size() == 0) { - mHashtable.remove(t.toString()); - } - } - - public void resetCounters() - { - mStartTime = CMS.getCurrentDate(); - mAllTrans.resetCounters(); - } - - public StatsEvent getMainStatsEvent() - { - return mAllTrans; + } + + public void resetCounters() { + mStartTime = CMS.getCurrentDate(); + mAllTrans.resetCounters(); + } + + public StatsEvent getMainStatsEvent() { + return mAllTrans; } public void startup() throws EBaseException { @@ -171,9 +157,8 @@ public class StatsSubsystem implements IStatsSubsystem } /* - * Returns the root configuration storage of this system. - * <P> - * + * Returns the root configuration storage of this system. <P> + * * @return configuration store of this subsystem */ public IConfigStore getConfigStore() { @@ -181,31 +166,26 @@ public class StatsSubsystem implements IStatsSubsystem } } -class StatsMilestone -{ - private String mId = null; - private long mStartTime = 0; - private StatsEvent mST = null; - - public StatsMilestone(String id, long startTime, StatsEvent st) - { - mId = id; - mStartTime = startTime; - mST = st; - } - - public String getId() - { - return mId; - } - - public long getStartTime() - { - return mStartTime; - } - - public StatsEvent getStatsEvent() - { - return mST; - } +class StatsMilestone { + private String mId = null; + private long mStartTime = 0; + private StatsEvent mST = null; + + public StatsMilestone(String id, long startTime, StatsEvent st) { + mId = id; + mStartTime = startTime; + mST = st; + } + + public String getId() { + return mId; + } + + public long getStartTime() { + return mStartTime; + } + + public StatsEvent getStatsEvent() { + return mST; + } } |