use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class StreamPreStateProcessor method addEveryState.
@Override
public void addEveryState(StateEvent stateEvent) {
lock.lock();
try {
StateEvent clonedEvent = stateEventCloner.copyStateEvent(stateEvent);
clonedEvent.setType(ComplexEvent.Type.CURRENT);
for (int i = stateId; i < clonedEvent.getStreamEvents().length; i++) {
clonedEvent.setEvent(i, null);
}
StreamPreState state = stateHolder.getState();
try {
state.newAndEveryStateEventList.add(clonedEvent);
} finally {
stateHolder.returnState(state);
}
} finally {
lock.unlock();
}
}
use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class AbsentLogicalPreStateProcessor method processAndReturn.
@Override
public ComplexEventChunk<StateEvent> processAndReturn(ComplexEventChunk complexEventChunk) {
ComplexEventChunk<StateEvent> returnEventChunk = new ComplexEventChunk<>();
StreamPreState state = stateHolder.getState();
try {
if (!((LogicalStreamPreState) state).active) {
return returnEventChunk;
}
complexEventChunk.reset();
// Sure only one will be sent
StreamEvent streamEvent = (StreamEvent) complexEventChunk.next();
this.lock.lock();
try {
for (Iterator<StateEvent> iterator = state.getPendingStateEventList().iterator(); iterator.hasNext(); ) {
StateEvent stateEvent = iterator.next();
if (logicalType == LogicalStateElement.Type.OR && stateEvent.getStreamEvent(partnerStatePreProcessor.getStateId()) != null) {
iterator.remove();
continue;
}
StreamEvent currentStreamEvent = stateEvent.getStreamEvent(stateId);
stateEvent.setEvent(stateId, streamEventCloner.copyStreamEvent(streamEvent));
process(stateEvent);
if (waitingTime != -1 || (stateType == StateInputStream.Type.SEQUENCE && logicalType == LogicalStateElement.Type.AND && thisStatePostProcessor.nextEveryStatePreProcessor != null)) {
// Reset to the original state after processing
stateEvent.setEvent(stateId, currentStreamEvent);
}
if (this.thisLastProcessor.isEventReturned()) {
this.thisLastProcessor.clearProcessedEvent();
// The event has passed the filter condition. So remove from being an absent candidate.
iterator.remove();
if (stateType == StateInputStream.Type.SEQUENCE) {
partnerStatePreProcessor.getPendingStateEventList().remove(stateEvent);
}
}
if (!state.isStateChanged()) {
switch(stateType) {
case PATTERN:
stateEvent.setEvent(stateId, currentStreamEvent);
break;
case SEQUENCE:
stateEvent.setEvent(stateId, currentStreamEvent);
iterator.remove();
break;
}
}
}
} finally {
this.lock.unlock();
}
return returnEventChunk;
} finally {
stateHolder.returnState(state);
}
}
use of io.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);
clonedEvent.setType(ComplexEvent.Type.CURRENT);
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);
StreamPreState state = stateHolder.getState();
try {
// Start state takes events from newAndEveryStateEventList
state.getNewAndEveryStateEventList().add(clonedEvent);
partnerStatePreProcessor.addEventToNewAndEveryStateEventList(clonedEvent);
} finally {
stateHolder.returnState(state);
}
}
use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class LogicalPreStateProcessor method processAndReturn.
@Override
public ComplexEventChunk<StateEvent> processAndReturn(ComplexEventChunk complexEventChunk) {
ComplexEventChunk<StateEvent> returnEventChunk = new ComplexEventChunk<StateEvent>();
complexEventChunk.reset();
// Sure only one will be sent
StreamEvent streamEvent = (StreamEvent) complexEventChunk.next();
StreamPreState state = stateHolder.getState();
lock.lock();
try {
for (Iterator<StateEvent> iterator = state.getPendingStateEventList().iterator(); iterator.hasNext(); ) {
StateEvent stateEvent = iterator.next();
if (logicalType == LogicalStateElement.Type.OR && stateEvent.getStreamEvent(partnerStatePreProcessor.getStateId()) != null) {
iterator.remove();
continue;
}
stateEvent.setEvent(stateId, streamEventCloner.copyStreamEvent(streamEvent));
process(stateEvent);
if (this.thisLastProcessor.isEventReturned()) {
this.thisLastProcessor.clearProcessedEvent();
returnEventChunk.add(stateEvent);
}
if (state.isStateChanged()) {
iterator.remove();
} else {
switch(stateType) {
case PATTERN:
stateEvent.setEvent(stateId, null);
break;
case SEQUENCE:
stateEvent.setEvent(stateId, null);
iterator.remove();
break;
}
}
}
} finally {
lock.unlock();
stateHolder.returnState(state);
}
return returnEventChunk;
}
use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class StreamPostStateProcessor method process.
/**
* Process the handed StreamEvent
*
* @param complexEventChunk event chunk to be processed
*/
@Override
public void process(ComplexEventChunk complexEventChunk) {
complexEventChunk.reset();
if (complexEventChunk.hasNext()) {
// one one event will be coming
StateEvent stateEvent = (StateEvent) complexEventChunk.next();
process(stateEvent, complexEventChunk);
}
complexEventChunk.clear();
}
Aggregations