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;
}
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);
}
}
}
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;
}
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);
}
}
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();
}
Aggregations