Search in sources :

Example 31 with StateEvent

use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.

the class TestStoreContainingInMemoryTable method parameterMapToStateEvent.

private StateEvent parameterMapToStateEvent(Map<String, Object> parameterMap) {
    StateEvent stateEvent = new StateEvent(2, parameterMap.size());
    List<Object> outputData = new ArrayList<>();
    List<Attribute> attributeList = inMemoryTable.getTableDefinition().getAttributeList();
    for (int i = 0; i < attributeList.size(); i++) {
        if (parameterMap.get(attributeList.get(i).getName()) != null) {
            outputData.add(parameterMap.get(attributeList.get(i).getName()));
        } else {
            outputData.add(null);
        }
    }
    StreamEvent event = storeEventPool.newInstance();
    event.setOutputData(outputData.toArray());
    stateEvent.addEvent(0, event);
    return stateEvent;
}
Also used : Attribute(io.siddhi.query.api.definition.Attribute) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) ArrayList(java.util.ArrayList) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) StateEvent(io.siddhi.core.event.state.StateEvent)

Example 32 with StateEvent

use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.

the class CacheTable method updateOrAddAndTrimUptoMaxSize.

public void updateOrAddAndTrimUptoMaxSize(ComplexEventChunk<StateEvent> updateOrAddingEventChunk, CompiledCondition compiledCondition, CompiledUpdateSet compiledUpdateSet, AddingStreamEventExtractor addingStreamEventExtractor, int maxTableSize) {
    ComplexEventChunk<StateEvent> updateOrAddingEventChunkForCache = new ComplexEventChunk<>();
    updateOrAddingEventChunk.reset();
    while (updateOrAddingEventChunk.hasNext()) {
        StateEvent event = updateOrAddingEventChunk.next();
        updateOrAddingEventChunkForCache.add((StateEvent) generateEventWithRequiredFields(event, siddhiAppContext, cacheExpiryEnabled));
    }
    readWriteLock.writeLock().lock();
    TableState state = stateHolder.getState();
    try {
        InMemoryCompiledCondition inMemoryCompiledCondition = (InMemoryCompiledCondition) compiledCondition;
        ComplexEventChunk<StateEvent> failedEvents = ((Operator) inMemoryCompiledCondition.getOperatorCompiledCondition()).tryUpdate(updateOrAddingEventChunkForCache, state.getEventHolder(), (InMemoryCompiledUpdateSet) compiledUpdateSet, addingStreamEventExtractor);
        if (failedEvents != null && failedEvents.getFirst() != null) {
            state.getEventHolder().add(reduceEventsForUpdateOrInsert(addingStreamEventExtractor, inMemoryCompiledCondition, (InMemoryCompiledUpdateSet) compiledUpdateSet, failedEvents));
        }
        if (this.size() > maxSize) {
            this.deleteEntriesUsingCachePolicy(this.size() - maxSize);
        }
    } finally {
        stateHolder.returnState(state);
        readWriteLock.writeLock().unlock();
    }
}
Also used : Operator(io.siddhi.core.util.collection.operator.Operator) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) StateEvent(io.siddhi.core.event.state.StateEvent)

Example 33 with StateEvent

use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.

the class StateMultiProcessStreamReceiver method processAndClear.

protected void processAndClear(int processIndex, StreamEvent streamEvent) {
    ComplexEventChunk<StateEvent> retEventChunk = new ComplexEventChunk<StateEvent>();
    ComplexEventChunk<StreamEvent> currentStreamEventChunk = new ComplexEventChunk<StreamEvent>(streamEvent, streamEvent);
    ComplexEventChunk<StateEvent> eventChunk = ((StreamPreStateProcessor) nextProcessors[processIndex]).processAndReturn(currentStreamEventChunk);
    if (eventChunk.getFirst() != null) {
        retEventChunk.add(eventChunk.getFirst());
    }
    eventChunk.clear();
    if (querySelector != null) {
        while (retEventChunk.hasNext()) {
            StateEvent stateEvent = retEventChunk.next();
            retEventChunk.remove();
            querySelector.process(new ComplexEventChunk<StateEvent>(stateEvent, stateEvent));
        }
    }
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent) StateEvent(io.siddhi.core.event.state.StateEvent) StreamPreStateProcessor(io.siddhi.core.query.input.stream.state.StreamPreStateProcessor)

Example 34 with StateEvent

use of io.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 = stateEventFactory.newInstance();
    returnEvent.setEvent(0, leftStream);
    returnEvent.setEvent(1, rightStream);
    returnEvent.setType(type);
    if (!leftJoinProcessor) {
        returnEvent.setTimestamp(rightStream.getTimestamp());
    } else {
        returnEvent.setTimestamp(leftStream.getTimestamp());
    }
    return returnEvent;
}
Also used : StateEvent(io.siddhi.core.event.state.StateEvent)

Example 35 with StateEvent

use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.

the class AbsentStreamPreStateProcessor method processAndReturn.

@Override
public ComplexEventChunk<StateEvent> processAndReturn(ComplexEventChunk complexEventChunk) {
    LogicalStreamPreState state = (LogicalStreamPreState) stateHolder.getState();
    try {
        if (!state.active) {
            return new ComplexEventChunk<>();
        }
        ComplexEventChunk<StateEvent> event = super.processAndReturn(complexEventChunk);
        StateEvent firstEvent = event.getFirst();
        if (firstEvent != null) {
            event = new ComplexEventChunk<>();
        }
        // Always return an empty event
        return event;
    } finally {
        stateHolder.returnState(state);
    }
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) StateEvent(io.siddhi.core.event.state.StateEvent)

Aggregations

StateEvent (io.siddhi.core.event.state.StateEvent)70 StreamEvent (io.siddhi.core.event.stream.StreamEvent)48 ComplexEventChunk (io.siddhi.core.event.ComplexEventChunk)36 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)26 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)19 ComplexEvent (io.siddhi.core.event.ComplexEvent)13 ExpressionExecutor (io.siddhi.core.executor.ExpressionExecutor)11 Map (java.util.Map)10 ArrayList (java.util.ArrayList)7 LinkedList (java.util.LinkedList)6 ConnectionUnavailableException (io.siddhi.core.exception.ConnectionUnavailableException)5 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)5 HashMap (java.util.HashMap)5 Attribute (io.siddhi.query.api.definition.Attribute)4 Event (io.siddhi.core.event.Event)3 SnapshotableStreamEventQueue (io.siddhi.core.event.stream.holder.SnapshotableStreamEventQueue)3 DatabaseRuntimeException (io.siddhi.core.exception.DatabaseRuntimeException)3 OnDemandQueryRuntimeException (io.siddhi.core.exception.OnDemandQueryRuntimeException)3 OnDemandQueryRuntimeUtil.executeSelectorAndReturnStreamEvent (io.siddhi.core.util.OnDemandQueryRuntimeUtil.executeSelectorAndReturnStreamEvent)3 SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)2