use of org.wso2.siddhi.core.event.stream.StreamEvent 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.stream.StreamEvent 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.stream.StreamEvent 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;
}
}
use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class SelectStoreQueryRuntime method execute.
public Event[] execute() {
try {
StateEvent stateEvent = new StateEvent(1, 0);
StreamEvent streamEvents = queryableProcessor.query(stateEvent, compiledCondition, compiledSelection);
if (streamEvents == null) {
return null;
} else {
List<Event> events = new ArrayList<Event>();
while (streamEvents != null) {
events.add(new Event(streamEvents.getTimestamp(), streamEvents.getOutputData()));
streamEvents = streamEvents.getNext();
}
return events.toArray(new Event[0]);
}
} catch (Throwable t) {
throw new StoreQueryRuntimeException("Error executing '" + queryName + "', " + t.getMessage(), t);
}
}
use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class MultiProcessStreamReceiver method receive.
@Override
public void receive(ComplexEvent complexEvent) {
ComplexEvent aComplexEvent = complexEvent;
while (aComplexEvent != null) {
synchronized (this) {
stabilizeStates();
for (int anEventSequence : eventSequence) {
StreamEventConverter aStreamEventConverter = streamEventConverters[anEventSequence];
StreamEventPool aStreamEventPool = streamEventPools[anEventSequence];
StreamEvent borrowedEvent = aStreamEventPool.borrowEvent();
aStreamEventConverter.convertComplexEvent(aComplexEvent, borrowedEvent);
process(anEventSequence, borrowedEvent);
}
}
aComplexEvent = aComplexEvent.getNext();
}
}
Aggregations