use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class AbsentStreamPreStateProcessor method process.
@Override
public void process(ComplexEventChunk complexEventChunk) {
LogicalStreamPreState state = (LogicalStreamPreState) stateHolder.getState();
try {
if (!state.active) {
// Every keyword is not used and already a pattern is processed
return;
}
boolean notProcessed = true;
long currentTime = complexEventChunk.getFirst().getTimestamp();
ComplexEventChunk<StateEvent> retEventChunk = new ComplexEventChunk<>();
lock.lock();
try {
// If the process method is called, it is guaranteed that the waitingTime is passed
boolean initialize = isStartState && state.getNewAndEveryStateEventList().isEmpty() && state.getPendingStateEventList().isEmpty();
if (initialize && stateType == StateInputStream.Type.SEQUENCE && thisStatePostProcessor.nextEveryStatePreProcessor == null && state.lastScheduledTime > 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 = stateEventFactory.newInstance();
addState(stateEvent);
} else if (stateType == StateInputStream.Type.SEQUENCE && !state.getNewAndEveryStateEventList().isEmpty()) {
this.resetState();
}
this.updateState();
Iterator<StateEvent> iterator = state.getPendingStateEventList().iterator();
while (iterator.hasNext()) {
StateEvent event = iterator.next();
// Remove expired events based on within
if (isExpired(event, currentTime)) {
iterator.remove();
if (withinEveryPreStateProcessor != null && thisStatePostProcessor.nextEveryStatePreProcessor != this) {
thisStatePostProcessor.nextEveryStatePreProcessor.addEveryState(event);
}
continue;
}
// Collect the events that came before the waiting time
if (event.getTimestamp() == -1 && currentTime >= state.lastScheduledTime || event.getTimestamp() != -1 && currentTime >= event.getTimestamp() + waitingTime) {
iterator.remove();
event.setTimestamp(currentTime);
retEventChunk.add(event);
}
}
if (withinEveryPreStateProcessor != null) {
withinEveryPreStateProcessor.updateState();
}
} finally {
lock.unlock();
}
notProcessed = retEventChunk.getFirst() == null;
while (retEventChunk.hasNext()) {
StateEvent stateEvent = retEventChunk.next();
retEventChunk.remove();
sendEvent(stateEvent, state);
}
long actualCurrentTime = siddhiQueryContext.getSiddhiAppContext().getTimestampGenerator().currentTime();
if (actualCurrentTime > waitingTime + currentTime) {
state.lastScheduledTime = actualCurrentTime + waitingTime;
}
if (notProcessed && state.lastScheduledTime < currentTime) {
state.lastScheduledTime = currentTime + waitingTime;
this.scheduler.notifyAt(state.lastScheduledTime);
}
} finally {
stateHolder.returnState(state);
}
}
use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class AbsentStreamPreStateProcessor method addEveryState.
@Override
public void addEveryState(StateEvent stateEvent) {
LogicalStreamPreState state = (LogicalStreamPreState) stateHolder.getState();
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);
}
state.getNewAndEveryStateEventList().add(clonedEvent);
// Start the scheduler
state.lastScheduledTime = stateEvent.getTimestamp() + waitingTime;
scheduler.notifyAt(state.lastScheduledTime);
} finally {
lock.unlock();
stateHolder.returnState(state);
}
}
use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class OnDemandQueryRuntime method execute.
/**
* This method initiates the execution of on-demand Query.
*
* @return an array of Events.
*/
public Event[] execute() {
try {
StateEvent stateEvent = new StateEvent(1, outputAttributes.length);
StreamEvent streamEvent = new StreamEvent(metaStreamEvent.getBeforeWindowData().size(), metaStreamEvent.getOnAfterWindowData().size(), metaStreamEvent.getOutputData().size());
stateEvent.addEvent(0, streamEvent);
ComplexEventChunk complexEventChunk = new ComplexEventChunk(stateEvent, stateEvent);
if (eventType == MetaStreamEvent.EventType.TABLE) {
selector.process(complexEventChunk);
} else {
throw new OnDemandQueryRuntimeException("DELETE, INSERT, UPDATE and UPDATE OR INSERT on-demand Query " + "operations consume only stream events of type \"TABLE\".");
}
return new Event[] {};
} catch (Throwable t) {
throw new OnDemandQueryRuntimeException("Error executing '" + queryName + "', " + t.getMessage(), t);
}
}
use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class MultiValueVariableFunctionExecutor method execute.
public Object execute(ComplexEvent event) {
List values = new LinkedList();
StreamEvent aEvent = ((StateEvent) event).getStreamEvent(position);
while (aEvent != null) {
values.add(aEvent.getAttribute(position));
aEvent = aEvent.getNext();
}
return values;
}
use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class AbstractQueryableRecordTable method updateStoreTableSize.
private void updateStoreTableSize() throws ConnectionUnavailableException {
if (cacheEnabled && !queryStoreWithoutCheckingCache.get()) {
readWriteLock.writeLock().lock();
try {
// check if we need to check the size of store
if (storeTableSize == -1 || (!cacheExpiryEnabled && storeSizeLastCheckedTime < siddhiAppContext.getTimestampGenerator().currentTime() - storeSizeCheckInterval)) {
StateEvent stateEventForCaching = new StateEvent(1, 0);
queryStoreWithoutCheckingCache.set(Boolean.TRUE);
try {
StreamEvent preLoadedData = query(stateEventForCaching, compiledConditionForCaching, compiledSelectionForCaching, outputAttributesForCaching);
storeTableSize = findEventChunkSize(preLoadedData);
storeSizeLastCheckedTime = siddhiAppContext.getTimestampGenerator().currentTime();
} finally {
queryStoreWithoutCheckingCache.set(Boolean.FALSE);
}
}
} finally {
readWriteLock.writeLock().unlock();
}
}
}
Aggregations