use of io.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class IncrementalExecutor method execute.
@Override
public synchronized void execute(ComplexEventChunk streamEventChunk) {
if (LOG.isDebugEnabled()) {
LOG.debug("Event Chunk received by " + this.duration + " incremental executor: " + streamEventChunk.toString());
}
streamEventChunk.reset();
while (streamEventChunk.hasNext()) {
StreamEvent streamEvent = (StreamEvent) streamEventChunk.next();
streamEventChunk.remove();
ExecutorState executorState = stateHolder.getState();
try {
long timestamp = getTimestamp(streamEvent, executorState);
long startTime = executorState.startTimeOfAggregates;
executorState.startTimeOfAggregates = IncrementalTimeConverterUtil.getStartTimeOfAggregates(timestamp, duration, timeZone);
if (timestamp >= executorState.nextEmitTime) {
executorState.nextEmitTime = IncrementalTimeConverterUtil.getNextEmitTime(timestamp, duration, timeZone);
dispatchAggregateEvents(executorState.startTimeOfAggregates);
sendTimerEvent(executorState);
}
if (streamEvent.getType() == ComplexEvent.Type.CURRENT) {
processAggregates(streamEvent, executorState);
}
} finally {
stateHolder.returnState(executorState);
}
}
}
use of io.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class OutOfOrderEventsDataAggregator method aggregateData.
public ComplexEventChunk<StreamEvent> aggregateData(ComplexEventChunk<StreamEvent> retrievedData) {
Set<String> groupByKeys = new HashSet<>();
while (retrievedData.hasNext()) {
StreamEvent streamEvent = retrievedData.next();
String groupByKey = groupByKeyGenerator.constructEventKey(streamEvent);
groupByKeys.add(groupByKey);
SiddhiAppContext.startGroupByFlow(groupByKey);
synchronized (this) {
ValueState state = (ValueState) valueStateHolder.getState();
try {
boolean shouldUpdate = true;
if (shouldUpdateTimestamp != null) {
shouldUpdate = shouldUpdate(shouldUpdateTimestamp.execute(streamEvent), state);
}
for (int i = 0; i < baseExecutors.size(); i++) {
// keeping timestamp value location as null
ExpressionExecutor expressionExecutor = baseExecutors.get(i);
if (shouldUpdate) {
state.setValue(expressionExecutor.execute(streamEvent), i + 1);
} else if (!(expressionExecutor instanceof VariableExpressionExecutor)) {
state.setValue(expressionExecutor.execute(streamEvent), i + 1);
}
}
} finally {
valueStateHolder.returnState(state);
SiddhiAppContext.stopGroupByFlow();
}
}
}
// clean all executors
for (String groupByKey : groupByKeys) {
SiddhiAppContext.startGroupByFlow(groupByKey);
try {
for (ExpressionExecutor expressionExecutor : baseExecutors) {
expressionExecutor.execute(resetEvent);
}
} finally {
SiddhiAppContext.stopGroupByFlow();
}
}
return createEventChunkFromAggregatedData();
}
use of io.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class PersistedIncrementalExecutor method sendTimerEvent.
private void sendTimerEvent(ExecutorState executorState) {
if (getNextExecutor() != null) {
StreamEvent timerEvent = streamEventFactory.newInstance();
timerEvent.setType(ComplexEvent.Type.TIMER);
timerEvent.setTimestamp(executorState.startTimeOfAggregates);
ComplexEventChunk<StreamEvent> timerStreamEventChunk = new ComplexEventChunk<>();
timerStreamEventChunk.add(timerEvent);
next.execute(timerStreamEventChunk);
}
}
use of io.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class BaseIncrementalValueStore method process.
public synchronized void process(Map<String, StreamEvent> groupedByEvents) {
for (Map.Entry<String, StreamEvent> eventEntry : groupedByEvents.entrySet()) {
synchronized (this) {
SiddhiAppContext.startGroupByFlow(eventEntry.getKey() + "-" + eventEntry.getValue().getTimestamp());
ValueState state = valueStateHolder.getState();
try {
boolean shouldUpdate = true;
if (shouldUpdateTimestamp != null) {
shouldUpdate = shouldUpdate(shouldUpdateTimestamp.execute(eventEntry.getValue()), state);
}
for (int i = 0; i < expressionExecutors.size(); i++) {
// keeping timestamp value location as null
ExpressionExecutor expressionExecutor = expressionExecutors.get(i);
if (shouldUpdate) {
state.setValue(expressionExecutor.execute(eventEntry.getValue()), i + 1);
} else if (!(expressionExecutor instanceof VariableExpressionExecutor)) {
state.setValue(expressionExecutor.execute(eventEntry.getValue()), i + 1);
}
}
setProcessed(true);
} finally {
valueStateHolder.returnState(state);
SiddhiAppContext.stopGroupByFlow();
}
}
}
}
use of io.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class BaseIncrementalValueStore method getGroupedByEvents.
public synchronized Map<String, StreamEvent> getGroupedByEvents() {
Map<String, StreamEvent> groupedByEvents = new HashMap<>();
if (isProcessed()) {
Map<String, ValueState> baseIncrementalValueStoreMap = this.valueStateHolder.getAllGroupByStates();
try {
for (Map.Entry<String, ValueState> state : baseIncrementalValueStoreMap.entrySet()) {
StreamEvent streamEvent = streamEventFactory.newInstance();
long timestamp = getTimestamp();
streamEvent.setTimestamp(timestamp);
state.getValue().setValue(timestamp, 0);
streamEvent.setOutputData(state.getValue().values);
groupedByEvents.put(state.getKey(), streamEvent);
}
} finally {
this.valueStateHolder.returnGroupByStates(baseIncrementalValueStoreMap);
}
}
return groupedByEvents;
}
Aggregations