use of org.wso2.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class JoinProcessor method joinEventBuilder.
/**
* Join the given two event streams.
*
* @param leftStream event left stream
* @param rightStream event right stream
* @param type complex event type
* @return StateEvent state event
*/
public StateEvent joinEventBuilder(StreamEvent leftStream, StreamEvent rightStream, ComplexEvent.Type type) {
StateEvent returnEvent = stateEventPool.borrowEvent();
returnEvent.setEvent(0, leftStream);
returnEvent.setEvent(1, rightStream);
returnEvent.setType(type);
if (!leftJoinProcessor) {
returnEvent.setTimestamp(rightStream.getTimestamp());
} else {
returnEvent.setTimestamp(leftStream.getTimestamp());
}
return returnEvent;
}
use of org.wso2.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class AbsentLogicalPostStateProcessor method process.
protected void process(StateEvent stateEvent, ComplexEventChunk complexEventChunk) {
// Mark the state changed
thisStatePreProcessor.stateChanged();
// Update the timestamp
StreamEvent streamEvent = stateEvent.getStreamEvent(stateId);
// This is the notification to AbsentStreamPreStateProcessor that this event has been processed
this.isEventReturned = true;
((AbsentPreStateProcessor) thisStatePreProcessor).updateLastArrivalTime(streamEvent.getTimestamp());
}
use of org.wso2.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class AbsentLogicalPreStateProcessor method process.
@Override
public void process(ComplexEventChunk complexEventChunk) {
if (!this.active) {
return;
}
this.lock.lock();
boolean notProcessed = true;
try {
long currentTime = complexEventChunk.getFirst().getTimestamp();
if (currentTime >= this.lastArrivalTime + waitingTime) {
ComplexEventChunk<StateEvent> retEventChunk = new ComplexEventChunk<>(false);
Iterator<StateEvent> iterator;
if (isStartState && stateType == StateInputStream.Type.SEQUENCE && newAndEveryStateEventList.isEmpty() && pendingStateEventList.isEmpty()) {
StateEvent stateEvent = stateEventPool.borrowEvent();
addState(stateEvent);
} else if (stateType == StateInputStream.Type.SEQUENCE && !newAndEveryStateEventList.isEmpty()) {
this.resetState();
}
this.updateState();
iterator = pendingStateEventList.iterator();
while (iterator.hasNext()) {
StateEvent stateEvent = iterator.next();
// Remove expired events based on within
if (withinStates.size() > 0) {
if (isExpired(stateEvent, currentTime)) {
iterator.remove();
continue;
}
}
// Collect the events that came before the waiting time
if (waitingTimePassed(currentTime, stateEvent)) {
iterator.remove();
if (logicalType == LogicalStateElement.Type.OR && stateEvent.getStreamEvent(partnerStatePreProcessor.getStateId()) == null) {
// OR Partner not received
stateEvent.addEvent(stateId, streamEventPool.borrowEvent());
retEventChunk.add(stateEvent);
} else if (logicalType == LogicalStateElement.Type.AND && stateEvent.getStreamEvent(partnerStatePreProcessor.getStateId()) != null) {
// AND partner received but didn't send out
retEventChunk.add(stateEvent);
} else if (logicalType == LogicalStateElement.Type.AND && stateEvent.getStreamEvent(partnerStatePreProcessor.getStateId()) == null) {
// AND partner didn't receive
// Let the partner to process or not
stateEvent.addEvent(stateId, streamEventPool.borrowEvent());
}
}
}
retEventChunk.reset();
notProcessed = retEventChunk.getFirst() == null;
while (retEventChunk.hasNext()) {
StateEvent stateEvent = retEventChunk.next();
retEventChunk.remove();
sendEvent(stateEvent);
}
this.lastArrivalTime = 0;
}
} finally {
this.lock.unlock();
}
if (thisStatePostProcessor.nextEveryStatePerProcessor != null || (notProcessed && isStartState)) {
// If every or (notProcessed and startState), schedule again
long nextBreak;
if (lastArrivalTime == 0) {
nextBreak = siddhiAppContext.getTimestampGenerator().currentTime() + waitingTime;
} else {
nextBreak = lastArrivalTime + waitingTime;
}
this.scheduler.notifyAt(nextBreak);
}
}
use of org.wso2.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class AbsentLogicalPreStateProcessor method addEveryState.
@Override
public void addEveryState(StateEvent stateEvent) {
StateEvent clonedEvent = stateEventCloner.copyStateEvent(stateEvent);
if (clonedEvent.getStreamEvent(stateId) != null) {
// Set the timestamp of the last arrived event
clonedEvent.setTimestamp(clonedEvent.getStreamEvent(stateId).getTimestamp());
}
clonedEvent.setEvent(stateId, null);
clonedEvent.setEvent(partnerStatePreProcessor.stateId, null);
// Start state takes events from newAndEveryStateEventList
newAndEveryStateEventList.add(clonedEvent);
partnerStatePreProcessor.newAndEveryStateEventList.add(clonedEvent);
}
use of org.wso2.siddhi.core.event.state.StateEvent 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());
}
Aggregations