public void sampleOccurred(SampleEvent e) {
synchronized (sampleStore) {
sampleStore.add(e);
if (numSamplesThreshold != -1) {
if (sampleStore.size() >= numSamplesThreshold) {
try {
log.debug("Firing sample");
listener.processBatch(sampleStore);
sampleStore.clear();
} catch (RemoteException err) {
log.error("sampleOccurred", err);
}
}
}
if (timeThreshold != -1) {
SampleResult sr = e.getResult();
long timestamp = sr.getTimeStamp();
// Checking for and creating initial timestamp to cheak against
if (batchSendTime == -1) {
this.batchSendTime = timestamp + timeThreshold;
}
if (batchSendTime < timestamp) {
try {
log.debug("Firing time");
if (sampleStore.size() > 0) {
listener.processBatch(sampleStore);
sampleStore.clear();
}
this.batchSendTime = timestamp + timeThreshold;
} catch (RemoteException err) {
log.error("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. |