public void sampleOccurred(SampleEvent e) {
synchronized (sampleStore) {
// Locate the statistical sample colector
String key = StatisticalSampleResult.getKey(e);
StatisticalSampleResult statResult = (StatisticalSampleResult) sampleTable
.get(key);
if (statResult == null) {
statResult = new StatisticalSampleResult(e.getResult());
// store the new statistical result collector
sampleTable.put(key, statResult);
// add a new wrapper samplevent
sampleStore
.add(new SampleEvent(statResult, e.getThreadGroup()));
}
statResult.add(e.getResult());
sampleCount++;
if (numSamplesThreshold != -1) {
if (sampleCount >= numSamplesThreshold) {
try {
if (log.isDebugEnabled()) {
log.debug("Firing sample");
}
sendBatch();
} catch (RemoteException err) {
log.warn("sampleOccurred", err);
}
}
}
if (timeThreshold != -1) {
long now = System.currentTimeMillis();
// Checking for and creating initial timestamp to cheak against
if (batchSendTime == -1) {
this.batchSendTime = now + timeThreshold;
}
if (batchSendTime < now) {
try {
if (log.isDebugEnabled()) {
log.debug("Firing time");
}
sendBatch();
this.batchSendTime = now + timeThreshold;
} catch (RemoteException err) {
log.warn("sampleOccurred", err);
}
}
}
}
}
Stores sample events untill either a time or sample threshold is
breached. Both thresholds are reset if one fires. If only one threshold
is set it becomes the only value checked against. When a threhold is
breached the list of sample events is sent to a listener where the event
are fired locally. |