use of org.wso2.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.
the class IncrementalExecutor method dispatchEvents.
private void dispatchEvents(Map<String, BaseIncrementalValueStore> baseIncrementalValueGroupByStore) {
int noOfEvents = baseIncrementalValueGroupByStore.size();
if (noOfEvents > 0) {
ComplexEventChunk<StreamEvent> eventChunk = new ComplexEventChunk<>(true);
for (BaseIncrementalValueStore aBaseIncrementalValueStore : baseIncrementalValueGroupByStore.values()) {
StreamEvent streamEvent = aBaseIncrementalValueStore.createStreamEvent();
eventChunk.add(streamEvent);
}
LOG.debug("Event dispatched by " + this.duration + " incremental executor: " + eventChunk.toString());
table.addEvents(eventChunk, noOfEvents);
if (getNextExecutor() != null) {
next.execute(eventChunk);
}
}
baseIncrementalValueGroupByStore.clear();
}
use of org.wso2.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.
the class IncrementalExecutor method dispatchEvent.
private void dispatchEvent(long startTimeOfNewAggregates, BaseIncrementalValueStore aBaseIncrementalValueStore) {
if (aBaseIncrementalValueStore.isProcessed()) {
StreamEvent streamEvent = aBaseIncrementalValueStore.createStreamEvent();
ComplexEventChunk<StreamEvent> eventChunk = new ComplexEventChunk<>(true);
eventChunk.add(streamEvent);
LOG.debug("Event dispatched by " + this.duration + " incremental executor: " + eventChunk.toString());
table.addEvents(eventChunk, 1);
if (getNextExecutor() != null) {
next.execute(eventChunk);
}
}
cleanBaseIncrementalValueStore(startTimeOfNewAggregates, aBaseIncrementalValueStore);
}
use of org.wso2.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.
the class ExternalTimeBatchWindowProcessor method process.
/**
* Here an assumption is taken:
* Parameter: timestamp: The time which the window determines as current time and will act upon,
* the value of this parameter should be monotonically increasing.
* from https://docs.wso2.com/display/CEP400/Inbuilt+Windows#InbuiltWindows-externalTime
*/
@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner) {
// event incoming trigger process. No events means no action
if (streamEventChunk.getFirst() == null) {
return;
}
List<ComplexEventChunk<StreamEvent>> complexEventChunks = new ArrayList<ComplexEventChunk<StreamEvent>>();
synchronized (this) {
initTiming(streamEventChunk.getFirst());
StreamEvent nextStreamEvent = streamEventChunk.getFirst();
while (nextStreamEvent != null) {
StreamEvent currStreamEvent = nextStreamEvent;
nextStreamEvent = nextStreamEvent.getNext();
if (currStreamEvent.getType() == ComplexEvent.Type.TIMER) {
if (lastScheduledTime <= currStreamEvent.getTimestamp()) {
// implies that there have not been any more events after this schedule has been done.
if (!flushed) {
flushToOutputChunk(streamEventCloner, complexEventChunks, lastCurrentEventTime, true);
flushed = true;
} else {
if (currentEventChunk.getFirst() != null) {
appendToOutputChunk(streamEventCloner, complexEventChunks, lastCurrentEventTime, true);
}
}
// rescheduling to emit the current batch after expiring it if no further events arrive.
lastScheduledTime = siddhiAppContext.getTimestampGenerator().currentTime() + schedulerTimeout;
scheduler.notifyAt(lastScheduledTime);
}
continue;
} else if (currStreamEvent.getType() != ComplexEvent.Type.CURRENT) {
continue;
}
long currentEventTime = (Long) timestampExpressionExecutor.execute(currStreamEvent);
if (lastCurrentEventTime < currentEventTime) {
lastCurrentEventTime = currentEventTime;
}
if (currentEventTime < endTime) {
cloneAppend(streamEventCloner, currStreamEvent);
} else {
if (flushed) {
appendToOutputChunk(streamEventCloner, complexEventChunks, lastCurrentEventTime, false);
flushed = false;
} else {
flushToOutputChunk(streamEventCloner, complexEventChunks, lastCurrentEventTime, false);
}
// update timestamp, call next processor
endTime = findEndTime(lastCurrentEventTime, startTime, timeToKeep);
cloneAppend(streamEventCloner, currStreamEvent);
// triggering the last batch expiration.
if (schedulerTimeout > 0) {
lastScheduledTime = siddhiAppContext.getTimestampGenerator().currentTime() + schedulerTimeout;
scheduler.notifyAt(lastScheduledTime);
}
}
}
}
for (ComplexEventChunk<StreamEvent> complexEventChunk : complexEventChunks) {
nextProcessor.process(complexEventChunk);
}
}
use of org.wso2.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.
the class ExternalTimeBatchWindowProcessor method appendToOutputChunk.
private void appendToOutputChunk(StreamEventCloner streamEventCloner, List<ComplexEventChunk<StreamEvent>> complexEventChunks, long currentTime, boolean preserveCurrentEvents) {
ComplexEventChunk<StreamEvent> newEventChunk = new ComplexEventChunk<StreamEvent>(true);
ComplexEventChunk<StreamEvent> sentEventChunk = new ComplexEventChunk<StreamEvent>(true);
if (currentEventChunk.getFirst() != null) {
if (expiredEventChunk.getFirst() != null) {
// mark the timestamp for the expiredType event
expiredEventChunk.reset();
while (expiredEventChunk.hasNext()) {
StreamEvent expiredEvent = expiredEventChunk.next();
if (outputExpectsExpiredEvents) {
// add expired event to newEventChunk.
StreamEvent toExpireEvent = streamEventCloner.copyStreamEvent(expiredEvent);
toExpireEvent.setTimestamp(currentTime);
newEventChunk.add(toExpireEvent);
}
StreamEvent toSendEvent = streamEventCloner.copyStreamEvent(expiredEvent);
toSendEvent.setType(ComplexEvent.Type.CURRENT);
sentEventChunk.add(toSendEvent);
}
}
// add reset event in front of current events
StreamEvent toResetEvent = streamEventCloner.copyStreamEvent(resetEvent);
toResetEvent.setTimestamp(currentTime);
newEventChunk.add(toResetEvent);
// add old events
newEventChunk.add(sentEventChunk.getFirst());
// move to expired events
if (preserveCurrentEvents || storeExpiredEvents) {
currentEventChunk.reset();
while (currentEventChunk.hasNext()) {
StreamEvent currentEvent = currentEventChunk.next();
StreamEvent toExpireEvent = streamEventCloner.copyStreamEvent(currentEvent);
toExpireEvent.setType(StreamEvent.Type.EXPIRED);
expiredEventChunk.add(toExpireEvent);
}
}
// add current event chunk to next processor
newEventChunk.add(currentEventChunk.getFirst());
}
currentEventChunk.clear();
if (newEventChunk.getFirst() != null) {
complexEventChunks.add(newEventChunk);
}
}
use of org.wso2.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.
the class FindStoreQueryRuntime method executeSelector.
private Event[] executeSelector(StreamEvent streamEvents, MetaStreamEvent.EventType eventType) {
ComplexEventChunk<StateEvent> complexEventChunk = new ComplexEventChunk<>(true);
while (streamEvents != null) {
StreamEvent streamEvent = streamEvents;
streamEvents = streamEvents.getNext();
streamEvent.setNext(null);
StateEvent stateEvent = stateEventPool.borrowEvent();
if (eventType == MetaStreamEvent.EventType.AGGREGATE) {
stateEvent.addEvent(1, streamEvent);
} else {
stateEvent.addEvent(0, streamEvent);
}
complexEventChunk.add(stateEvent);
}
ComplexEventChunk outputComplexEventChunk = selector.execute(complexEventChunk);
if (outputComplexEventChunk != null) {
List<Event> events = new ArrayList<>();
outputComplexEventChunk.reset();
while (outputComplexEventChunk.hasNext()) {
ComplexEvent complexEvent = outputComplexEventChunk.next();
events.add(new Event(complexEvent.getTimestamp(), complexEvent.getOutputData()));
}
return events.toArray(new Event[0]);
} else {
return null;
}
}
Aggregations