Search in sources :

Example 41 with ComplexEvent

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;
    }
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) ArrayList(java.util.ArrayList) Event(io.siddhi.core.event.Event) ComplexEvent(io.siddhi.core.event.ComplexEvent) StateEvent(io.siddhi.core.event.state.StateEvent) StreamEvent(io.siddhi.core.event.stream.StreamEvent)

Example 42 with ComplexEvent

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;
    }
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) StreamEvent(io.siddhi.core.event.stream.StreamEvent) StreamEvent(io.siddhi.core.event.stream.StreamEvent) ErroneousEvent(io.siddhi.core.util.error.handler.model.ErroneousEvent) Event(io.siddhi.core.event.Event) ComplexEvent(io.siddhi.core.event.ComplexEvent) LinkedList(java.util.LinkedList) List(java.util.List) ErroneousEvent(io.siddhi.core.util.error.handler.model.ErroneousEvent)

Example 43 with ComplexEvent

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);
        }
    }
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) EventExchangeHolder(io.siddhi.core.util.event.handler.EventExchangeHolder)

Example 44 with 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();
        }
    }
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) PartitionExecutor(io.siddhi.core.partition.executor.PartitionExecutor) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

Example 45 with ComplexEvent

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);
    }
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) StreamEvent(io.siddhi.core.event.stream.StreamEvent) Operation(io.siddhi.core.event.stream.Operation)

Aggregations

ComplexEvent (io.siddhi.core.event.ComplexEvent)75 ComplexEventChunk (io.siddhi.core.event.ComplexEventChunk)41 StreamEvent (io.siddhi.core.event.stream.StreamEvent)34 GroupedComplexEvent (io.siddhi.core.event.GroupedComplexEvent)19 Event (io.siddhi.core.event.Event)16 SiddhiAppRuntime (io.siddhi.core.SiddhiAppRuntime)13 SiddhiManager (io.siddhi.core.SiddhiManager)13 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)13 StreamCallback (io.siddhi.core.stream.output.StreamCallback)13 StateEvent (io.siddhi.core.event.state.StateEvent)12 InputHandler (io.siddhi.core.stream.input.InputHandler)12 Test (org.testng.annotations.Test)12 LinkedList (java.util.LinkedList)8 AttributeProcessor (io.siddhi.core.query.selector.attribute.processor.AttributeProcessor)4 ArrayList (java.util.ArrayList)4 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)3 Map (java.util.Map)3 SiddhiAppRuntimeException (io.siddhi.core.exception.SiddhiAppRuntimeException)2 Iterator (java.util.Iterator)2 Operation (io.siddhi.core.event.stream.Operation)1