use of org.wso2.siddhi.core.query.processor.Processor in project siddhi by wso2.
the class AbsentStreamPreStateProcessor method process.
@Override
public void process(ComplexEventChunk complexEventChunk) {
if (!this.active) {
// Every keyword is not used and already a pattern is processed
return;
}
boolean notProcessed = true;
long currentTime = complexEventChunk.getFirst().getTimestamp();
if (currentTime >= this.lastArrivalTime + waitingTime) {
synchronized (this) {
// If the process method is called, it is guaranteed that the waitingTime is passed
boolean initialize;
initialize = isStartState && newAndEveryStateEventList.isEmpty() && pendingStateEventList.isEmpty();
if (initialize && stateType == StateInputStream.Type.SEQUENCE && thisStatePostProcessor.nextEveryStatePerProcessor == null && this.lastArrivalTime > 0) {
// Sequence with no every but an event arrived
initialize = false;
}
if (initialize) {
// This is the first processor and no events received so far
StateEvent stateEvent = stateEventPool.borrowEvent();
addState(stateEvent);
} else if (stateType == StateInputStream.Type.SEQUENCE && !newAndEveryStateEventList.isEmpty()) {
this.resetState();
}
this.updateState();
ComplexEventChunk<StateEvent> retEventChunk = new ComplexEventChunk<>(false);
Iterator<StateEvent> iterator = pendingStateEventList.iterator();
while (iterator.hasNext()) {
StateEvent event = iterator.next();
// Remove expired events based on within
if (withinStates.size() > 0) {
if (isExpired(event, currentTime)) {
iterator.remove();
continue;
}
}
// Collect the events that came before the waiting time
if (currentTime >= event.getTimestamp() + waitingTime) {
iterator.remove();
event.setTimestamp(currentTime);
retEventChunk.add(event);
}
}
notProcessed = retEventChunk.getFirst() == null;
while (retEventChunk.hasNext()) {
StateEvent stateEvent = retEventChunk.next();
retEventChunk.remove();
sendEvent(stateEvent);
}
}
this.lastArrivalTime = 0;
}
if (thisStatePostProcessor.nextEveryStatePerProcessor == this || (notProcessed && isStartState)) {
// If every or (notProcessed and startState), schedule again
long nextBreak;
if (lastArrivalTime == 0) {
nextBreak = currentTime + waitingTime;
} else {
nextBreak = lastArrivalTime + waitingTime;
}
this.scheduler.notifyAt(nextBreak);
}
}
use of org.wso2.siddhi.core.query.processor.Processor in project siddhi by wso2.
the class LogStreamProcessor method process.
@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner, ComplexEventPopulater complexEventPopulater) {
while (streamEventChunk.hasNext()) {
ComplexEvent complexEvent = streamEventChunk.next();
switch(attributeExpressionLength) {
case 0:
log.info(logPrefix + complexEvent);
break;
case 1:
if (isLogEventExpressionExecutor != null) {
if ((Boolean) isLogEventExpressionExecutor.execute(complexEvent)) {
log.info(logPrefix + complexEvent);
} else {
log.info(logPrefix + "Event Arrived");
}
} else {
log.info(logPrefix + logMessageExpressionExecutor.execute(complexEvent) + ", " + complexEvent);
}
break;
case 2:
if (isLogEventExpressionExecutor != null) {
if ((Boolean) isLogEventExpressionExecutor.execute(complexEvent)) {
log.info(logPrefix + logMessageExpressionExecutor.execute(complexEvent) + ", " + complexEvent);
} else {
log.info(logPrefix + logMessageExpressionExecutor.execute(complexEvent));
}
} else {
LogPriority tempLogPriority = logPriority;
if (logPriorityExpressionExecutor != null) {
tempLogPriority = LogPriority.valueOf((String) logPriorityExpressionExecutor.execute(complexEvent));
}
String message = logPrefix + logMessageExpressionExecutor.execute(complexEvent) + ", " + complexEvent;
logMessage(tempLogPriority, message);
}
break;
default:
String message;
if ((Boolean) isLogEventExpressionExecutor.execute(complexEvent)) {
message = logPrefix + logMessageExpressionExecutor.execute(complexEvent) + ", " + complexEvent;
} else {
message = logPrefix + logMessageExpressionExecutor.execute(complexEvent);
}
LogPriority tempLogPriority = logPriority;
if (logPriorityExpressionExecutor != null) {
tempLogPriority = LogPriority.valueOf((String) logPriorityExpressionExecutor.execute(complexEvent));
}
logMessage(tempLogPriority, message);
}
}
nextProcessor.process(streamEventChunk);
}
use of org.wso2.siddhi.core.query.processor.Processor in project siddhi by wso2.
the class StreamFunctionProcessor method processEventChunk.
@Override
protected void processEventChunk(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner, ComplexEventPopulater complexEventPopulater) {
while (streamEventChunk.hasNext()) {
ComplexEvent complexEvent = streamEventChunk.next();
Object[] outputData;
switch(attributeExpressionLength) {
case 0:
outputData = process((Object) null);
complexEventPopulater.populateComplexEvent(complexEvent, outputData);
break;
case 1:
outputData = process(attributeExpressionExecutors[0].execute(complexEvent));
complexEventPopulater.populateComplexEvent(complexEvent, outputData);
break;
default:
Object[] inputData = new Object[attributeExpressionLength];
for (int i = 0; i < attributeExpressionLength; i++) {
inputData[i] = attributeExpressionExecutors[i].execute(complexEvent);
}
outputData = process(inputData);
complexEventPopulater.populateComplexEvent(complexEvent, outputData);
}
}
nextProcessor.process(streamEventChunk);
}
use of org.wso2.siddhi.core.query.processor.Processor in project siddhi by wso2.
the class CronWindowProcessor method process.
@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner) {
synchronized (this) {
while (streamEventChunk.hasNext()) {
StreamEvent streamEvent = streamEventChunk.next();
StreamEvent clonedStreamEvent = streamEventCloner.copyStreamEvent(streamEvent);
currentEventChunk.add(clonedStreamEvent);
streamEventChunk.remove();
}
}
}
use of org.wso2.siddhi.core.query.processor.Processor in project siddhi by wso2.
the class ExternalTimeBatchWindowProcessor method flushToOutputChunk.
private void flushToOutputChunk(StreamEventCloner streamEventCloner, List<ComplexEventChunk<StreamEvent>> complexEventChunks, long currentTime, boolean preserveCurrentEvents) {
ComplexEventChunk<StreamEvent> newEventChunk = new ComplexEventChunk<StreamEvent>(true);
if (outputExpectsExpiredEvents) {
if (expiredEventChunk.getFirst() != null) {
// mark the timestamp for the expiredType event
expiredEventChunk.reset();
while (expiredEventChunk.hasNext()) {
StreamEvent expiredEvent = expiredEventChunk.next();
expiredEvent.setTimestamp(currentTime);
}
// add expired event to newEventChunk.
newEventChunk.add(expiredEventChunk.getFirst());
}
}
if (expiredEventChunk != null) {
expiredEventChunk.clear();
}
if (currentEventChunk.getFirst() != null) {
// add reset event in front of current events
resetEvent.setTimestamp(currentTime);
newEventChunk.add(resetEvent);
resetEvent = null;
// 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);
}
}
Aggregations