in drools-benchmarks-parent/drools-benchmarks/src/main/java/org/drools/benchmarks/turtle/runtime/common/SameJvmEventSender.java [74:105]
public void sendEvents() {
logger.debug("Event sender in same JVM started....");
if (streamName == null) {
String message = "Stream name must be specified in order to send events to it!";
logger.error(message);
throw new RuntimeException(message);
}
EntryPoint stream = ksession.getEntryPoint(streamName);
if (stream == null) {
String message = "Stream with name '" + streamName + "' does not exist!";
logger.error(message);
throw new RuntimeException(message);
}
SessionPseudoClock clock = ksession.getSessionClock();
// EventRecords are sorted by their timeValue attribute.
// So timeValue is the moment in time on which the event should occur.
// The cycle iterates through sorted EventRecords and on each iteration
// it inserts actual Event into the entry point and moves the clock to time
// of the event occurrence.
long startTime = clock.getCurrentTime();
for (EventRecord record : events) {
long currTime = clock.getCurrentTime();
long nextEventTime = startTime + record.getTimeUnit().toMillis(record.getTimeValue());
clock.advanceTime(nextEventTime - currTime, TimeUnit.MILLISECONDS);
final BasicEvent event = record.getEvent();
stream.insert(event);
fireEventInsertedListeners(event, startTime, currTime, nextEventTime);
}
}