use of io.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class OnDemandQueryRuntimeUtil method executeSelector.
public static Event[] executeSelector(StateEventFactory stateEventFactory, StreamEvent streamEvent, StreamEvent storeEvents, int storeEventIndex, QuerySelector selector) {
ComplexEventChunk outputComplexEventChunk = executeSelectorAndReturnChunk(stateEventFactory, streamEvent, storeEvents, storeEventIndex, selector);
if (outputComplexEventChunk != null) {
List<Event> events = new ArrayList<>();
outputComplexEventChunk.reset();
while (outputComplexEventChunk.hasNext()) {
ComplexEvent complexEvent = outputComplexEventChunk.next();
events.add(new Event(complexEvent.getTimestamp(), complexEvent.getOutputData()));
}
return events.toArray(new Event[0]);
} else {
return null;
}
}
use of io.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class StreamJunction method handleError.
public void handleError(Object event, Exception e) {
if (exceptionListener != null) {
exceptionListener.exceptionThrown(e);
}
switch(onErrorAction) {
case LOG:
log.error("Error in '" + siddhiAppContext.getName() + "' after consuming events " + "from Stream '" + streamDefinition.getId() + "', " + e.getMessage() + ". Hence, dropping event '" + event.toString() + "'", e);
break;
case STREAM:
if (faultStreamJunction != null) {
StreamEvent streamEvent = null;
if (event instanceof ComplexEvent) {
streamEvent = faultStreamEventConverter.convert((ComplexEvent) event, e);
faultStreamJunction.sendEvent(streamEvent);
} else if (event instanceof Event) {
streamEvent = faultStreamEventConverter.convert((Event) event, e);
faultStreamJunction.sendEvent(streamEvent);
} else if (event instanceof Event[]) {
streamEvent = faultStreamEventConverter.convert((Event[]) event, e);
faultStreamJunction.sendEvent(streamEvent);
} else if (event instanceof List) {
streamEvent = faultStreamEventConverter.convert((List<Event>) event, e);
faultStreamJunction.sendEvent(streamEvent);
}
} else {
log.error("Error in SiddhiApp '" + siddhiAppContext.getName() + "' after consuming events from Stream '" + streamDefinition.getId() + "', " + e.getMessage() + ". Siddhi Fault Stream for '" + streamDefinition.getId() + "' is not defined. " + "Hence, dropping event '" + event.toString() + "'", e);
}
break;
case STORE:
ErroneousEvent erroneousEvent = new ErroneousEvent(event, e, "Error in SiddhiApp '" + siddhiAppContext.getName() + "' after consuming events from Stream '" + streamDefinition.getId() + "', " + e.getMessage() + ". Siddhi Fault Stream for '" + streamDefinition.getId() + "' is not defined. " + "Hence, dropping event '" + event.toString() + "'");
ErrorStoreHelper.storeErroneousEvent(siddhiAppContext.getSiddhiContext().getErrorStore(), ErrorOccurrence.STORE_ON_STREAM_ERROR, siddhiAppContext.getName(), erroneousEvent, streamDefinition.getId());
break;
default:
break;
}
}
use of io.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class StreamJunction method sendEvent.
public void sendEvent(ComplexEvent complexEvent) {
if (isTraceEnabled) {
log.trace("Event is received by streamJunction " + this);
}
ComplexEvent complexEventList = complexEvent;
if (disruptor != null) {
while (complexEventList != null) {
if (throughputTracker != null && Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
throughputTracker.eventIn();
}
long sequenceNo = ringBuffer.next();
try {
EventExchangeHolder eventExchangeHolder = ringBuffer.get(sequenceNo);
eventExchangeHolder.getEvent().copyFrom(complexEventList);
eventExchangeHolder.getAndSetIsProcessed(false);
} finally {
ringBuffer.publish(sequenceNo);
}
complexEventList = complexEventList.getNext();
}
} else {
if (throughputTracker != null && Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
int messageCount = 0;
while (complexEventList != null) {
messageCount++;
complexEventList = complexEventList.getNext();
}
throughputTracker.eventsIn(messageCount);
}
for (Receiver receiver : receivers) {
receiver.receive(complexEvent);
}
}
}
use of io.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class PartitionStreamReceiver method receive.
@Override
public void receive(ComplexEvent complexEvent) {
if (partitionExecutors.size() == 0) {
ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<ComplexEvent>();
ComplexEvent aComplexEvent = complexEvent;
while (aComplexEvent != null) {
StreamEvent newEvent = streamEventFactory.newInstance();
streamEventConverter.convertComplexEvent(aComplexEvent, newEvent);
outputEventChunk.add(newEvent);
aComplexEvent = aComplexEvent.getNext();
}
send(outputEventChunk.getFirst());
} else {
if (complexEvent.getNext() == null) {
for (PartitionExecutor partitionExecutor : partitionExecutors) {
StreamEvent newEvent = streamEventFactory.newInstance();
streamEventConverter.convertComplexEvent(complexEvent, newEvent);
String key = partitionExecutor.execute(newEvent);
send(key, newEvent);
}
} else {
ComplexEventChunk<ComplexEvent> complexEventChunk = new ComplexEventChunk<ComplexEvent>();
complexEventChunk.add(complexEvent);
ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<ComplexEvent>();
String currentKey = null;
while (complexEventChunk.hasNext()) {
ComplexEvent aEvent = complexEventChunk.next();
complexEventChunk.remove();
StreamEvent newEvent = streamEventFactory.newInstance();
streamEventConverter.convertComplexEvent(aEvent, newEvent);
boolean currentEventMatchedPrevPartitionExecutor = false;
for (PartitionExecutor partitionExecutor : partitionExecutors) {
String key = partitionExecutor.execute(newEvent);
if (key != null) {
if (currentKey == null) {
currentKey = key;
} else if (!currentKey.equals(key)) {
if (!currentEventMatchedPrevPartitionExecutor) {
ComplexEvent firstEvent = outputEventChunk.getFirst();
send(currentKey, firstEvent);
currentKey = key;
outputEventChunk.clear();
} else {
ComplexEvent firstEvent = outputEventChunk.getFirst();
send(currentKey, firstEvent);
currentKey = key;
outputEventChunk.clear();
StreamEvent cloneEvent = streamEventFactory.newInstance();
streamEventConverter.convertComplexEvent(aEvent, cloneEvent);
outputEventChunk.add(cloneEvent);
}
}
if (!currentEventMatchedPrevPartitionExecutor) {
outputEventChunk.add(newEvent);
}
currentEventMatchedPrevPartitionExecutor = true;
}
}
}
send(currentKey, outputEventChunk.getFirst());
outputEventChunk.clear();
}
}
}
use of io.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class IndexEventHolder method add.
@Override
public void add(ComplexEventChunk<StreamEvent> addingEventChunk) {
addingEventChunk.reset();
while (addingEventChunk.hasNext()) {
ComplexEvent complexEvent = addingEventChunk.next();
StreamEvent streamEvent = tableStreamEventFactory.newInstance();
eventConverter.convertComplexEvent(complexEvent, streamEvent);
eventsCount++;
if (isOperationLogEnabled) {
if (!isFullSnapshot()) {
StreamEvent streamEvent2 = tableStreamEventFactory.newInstance();
eventConverter.convertComplexEvent(complexEvent, streamEvent2);
operationChangeLog.add(new Operation(ADD, streamEvent2));
} else {
operationChangeLog.clear();
forceFullSnapshot = true;
}
}
add(streamEvent);
}
}
Aggregations