Search in sources :

Example 51 with StateEvent

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

the class SnapshotableEventQueueOperator method tryUpdate.

@Override
public ComplexEventChunk<StateEvent> tryUpdate(ComplexEventChunk<StateEvent> updatingOrAddingEventChunk, Object storeEvents, InMemoryCompiledUpdateSet compiledUpdateSet, AddingStreamEventExtractor addingStreamEventExtractor) {
    SnapshotableStreamEventQueue storeEventQueue = (SnapshotableStreamEventQueue) storeEvents;
    updatingOrAddingEventChunk.reset();
    ComplexEventChunk<StateEvent> failedEventChunk = new ComplexEventChunk<>();
    while (updatingOrAddingEventChunk.hasNext()) {
        StateEvent overwritingOrAddingEvent = updatingOrAddingEventChunk.next();
        try {
            boolean updated = false;
            storeEventQueue.reset();
            while (storeEventQueue.hasNext()) {
                StreamEvent storeEvent = storeEventQueue.next();
                overwritingOrAddingEvent.setEvent(storeEventPosition, storeEvent);
                if ((Boolean) expressionExecutor.execute(overwritingOrAddingEvent)) {
                    for (Map.Entry<Integer, ExpressionExecutor> entry : compiledUpdateSet.getExpressionExecutorMap().entrySet()) {
                        storeEvent.setOutputData(entry.getValue().execute(overwritingOrAddingEvent), entry.getKey());
                    }
                    storeEventQueue.overwrite(storeEvent);
                    updated = true;
                }
            }
            if (!updated) {
                updatingOrAddingEventChunk.remove();
                failedEventChunk.add(overwritingOrAddingEvent);
            }
        } finally {
            overwritingOrAddingEvent.setEvent(storeEventPosition, null);
        }
    }
    return failedEventChunk;
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) ExpressionExecutor(io.siddhi.core.executor.ExpressionExecutor) StreamEvent(io.siddhi.core.event.stream.StreamEvent) StateEvent(io.siddhi.core.event.state.StateEvent) Map(java.util.Map) SnapshotableStreamEventQueue(io.siddhi.core.event.stream.holder.SnapshotableStreamEventQueue)

Example 52 with StateEvent

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

the class IndexOperator method update.

@Override
public void update(ComplexEventChunk<StateEvent> updatingEventChunk, Object storeEvents, InMemoryCompiledUpdateSet compiledUpdateSet) {
    updatingEventChunk.reset();
    while (updatingEventChunk.hasNext()) {
        StateEvent updatingEvent = updatingEventChunk.next();
        StreamEvent streamEvents = collectionExecutor.find(updatingEvent, (IndexedEventHolder) storeEvents, null);
        if (streamEvents != null) {
            ComplexEventChunk<StreamEvent> foundEventChunk = new ComplexEventChunk<>();
            foundEventChunk.add(streamEvents);
            update((IndexedEventHolder) storeEvents, compiledUpdateSet, updatingEvent, foundEventChunk);
        }
    }
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent) StateEvent(io.siddhi.core.event.state.StateEvent)

Example 53 with StateEvent

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

the class IndexOperator method tryUpdate.

@Override
public ComplexEventChunk<StateEvent> tryUpdate(ComplexEventChunk<StateEvent> updatingOrAddingEventChunk, Object storeEvents, InMemoryCompiledUpdateSet compiledUpdateSet, AddingStreamEventExtractor addingStreamEventExtractor) {
    ComplexEventChunk<StateEvent> failedEventChunk = new ComplexEventChunk<>();
    updatingOrAddingEventChunk.reset();
    while (updatingOrAddingEventChunk.hasNext()) {
        StateEvent overwritingOrAddingEvent = updatingOrAddingEventChunk.next();
        StreamEvent streamEvents = collectionExecutor.find(overwritingOrAddingEvent, (IndexedEventHolder) storeEvents, null);
        ComplexEventChunk<StreamEvent> foundEventChunk = new ComplexEventChunk<>();
        foundEventChunk.add(streamEvents);
        if (foundEventChunk.getFirst() != null) {
            // for cases when indexed attribute is also updated but that not changed
            // to reduce number of passes needed to update the events
            update((IndexedEventHolder) storeEvents, compiledUpdateSet, overwritingOrAddingEvent, foundEventChunk);
        } else {
            updatingOrAddingEventChunk.remove();
            failedEventChunk.add(overwritingOrAddingEvent);
        }
    }
    return failedEventChunk;
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent) StateEvent(io.siddhi.core.event.state.StateEvent)

Example 54 with StateEvent

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

the class IndexOperator method delete.

@Override
public void delete(ComplexEventChunk<StateEvent> deletingEventChunk, Object storeEvents) {
    deletingEventChunk.reset();
    while (deletingEventChunk.hasNext()) {
        StateEvent deletingEvent = deletingEventChunk.next();
        collectionExecutor.delete(deletingEvent, (IndexedEventHolder) storeEvents);
    }
}
Also used : StateEvent(io.siddhi.core.event.state.StateEvent)

Example 55 with StateEvent

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

the class ErrorHandlerUtils method constructErrorRecordString.

public static String constructErrorRecordString(ComplexEventChunk<StateEvent> eventChunk, boolean isObjectColumnPresent, TableDefinition tableDefinition, Exception e) {
    JsonObject payloadJson = new JsonObject();
    if (isObjectColumnPresent || e instanceof ConnectionUnavailableException) {
        payloadJson.addProperty("isEditable", false);
    } else {
        payloadJson.addProperty("isEditable", true);
    }
    JsonArray attributes = new JsonArray();
    JsonArray records = new JsonArray();
    for (Attribute attribute : tableDefinition.getAttributeList()) {
        JsonObject attributeJson = new JsonObject();
        attributeJson.add("name", new JsonPrimitive(attribute.getName()));
        attributeJson.add("type", new JsonPrimitive(String.valueOf(attribute.getType())));
        attributes.add(attributeJson);
    }
    payloadJson.add("attributes", attributes);
    while (eventChunk.hasNext()) {
        StateEvent stateEvent = eventChunk.next();
        for (StreamEvent streamEvent : stateEvent.getStreamEvents()) {
            if (streamEvent != null) {
                JsonArray record = new JsonArray();
                for (Object item : streamEvent.getOutputData()) {
                    if (item == null) {
                        record.add(JsonNull.INSTANCE);
                    } else {
                        record.add(String.valueOf(item));
                    }
                }
                records.add(record);
            }
        }
    }
    payloadJson.add("records", records);
    return payloadJson.toString();
}
Also used : JsonArray(com.google.gson.JsonArray) Attribute(io.siddhi.query.api.definition.Attribute) JsonPrimitive(com.google.gson.JsonPrimitive) StreamEvent(io.siddhi.core.event.stream.StreamEvent) JsonObject(com.google.gson.JsonObject) StateEvent(io.siddhi.core.event.state.StateEvent) JsonObject(com.google.gson.JsonObject) ConnectionUnavailableException(io.siddhi.core.exception.ConnectionUnavailableException)

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