use of org.wso2.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.
the class AbsentStreamPostStateProcessor method process.
/**
* This method just mark the state changed but does not send the stateEvent to the next processors.
*
* @param stateEvent the state event
* @param complexEventChunk the ComplexEventChunk
*/
protected void process(StateEvent stateEvent, ComplexEventChunk complexEventChunk) {
// Mark the state changed
thisStatePreProcessor.stateChanged();
// Update the timestamp
StreamEvent streamEvent = stateEvent.getStreamEvent(stateId);
stateEvent.setTimestamp(streamEvent.getTimestamp());
// This is the notification to AbsentStreamPreStateProcessor that this event has been processed
this.isEventReturned = true;
if (thisStatePreProcessor.isStartState) {
if (nextEveryStatePerProcessor != null && nextEveryStatePerProcessor == thisStatePreProcessor) {
// nextEveryStatePerProcessor refers the AbsentStreamPreStateProcessor
nextEveryStatePerProcessor.addEveryState(stateEvent);
}
}
((AbsentPreStateProcessor) thisStatePreProcessor).updateLastArrivalTime(streamEvent.getTimestamp());
}
use of org.wso2.siddhi.core.event.ComplexEventChunk 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.event.ComplexEventChunk in project siddhi by wso2.
the class AbsentStreamPreStateProcessor method processAndReturn.
@Override
public ComplexEventChunk<StateEvent> processAndReturn(ComplexEventChunk complexEventChunk) {
if (!this.active) {
return new ComplexEventChunk<>(false);
}
ComplexEventChunk<StateEvent> event = super.processAndReturn(complexEventChunk);
StateEvent firstEvent = event.getFirst();
if (firstEvent != null) {
event = new ComplexEventChunk<>(false);
}
// Always return an empty event
return event;
}
use of org.wso2.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.
the class InsertIntoStreamCallback method send.
@Override
public void send(ComplexEventChunk complexEventChunk, int noOfEvents) {
if (getSiddhiDebugger() != null) {
getSiddhiDebugger().checkBreakPoint(getQueryName(), SiddhiDebugger.QueryTerminal.OUT, complexEventChunk.getFirst());
}
complexEventChunk.reset();
while (complexEventChunk.hasNext()) {
ComplexEvent complexEvent = complexEventChunk.next();
if (complexEvent.getType() == ComplexEvent.Type.EXPIRED) {
complexEvent.setType(ComplexEvent.Type.CURRENT);
}
}
publisher.send(complexEventChunk.getFirst());
}
use of org.wso2.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.
the class OutputRateLimiter method sendToCallBacks.
protected void sendToCallBacks(ComplexEventChunk complexEventChunk) {
if (siddhiAppContext.isStatsEnabled() && latencyTracker != null) {
latencyTracker.markOut();
}
if (lockWrapper != null) {
lockWrapper.unlock();
}
if (!queryCallbacks.isEmpty()) {
for (QueryCallback callback : queryCallbacks) {
callback.receiveStreamEvent(complexEventChunk);
}
}
if (outputCallback != null && complexEventChunk.getFirst() != null) {
complexEventChunk.reset();
int noOfEvents = 0;
while (complexEventChunk.hasNext()) {
ComplexEvent complexEvent = complexEventChunk.next();
if (complexEvent.getType() == ComplexEvent.Type.EXPIRED) {
complexEvent.setType(ComplexEvent.Type.CURRENT);
noOfEvents++;
} else if (complexEvent.getType() == ComplexEvent.Type.RESET) {
complexEventChunk.remove();
} else {
noOfEvents++;
}
}
if (complexEventChunk.getFirst() != null) {
outputCallback.send(complexEventChunk, noOfEvents);
}
}
}
Aggregations