Search in sources :

Example 16 with ComplexEvent

use of io.siddhi.core.event.ComplexEvent in project siddhi by wso2.

the class InsertIntoTableCallback method send.

@Override
public void send(ComplexEventChunk complexEventChunk, int noOfEvents) {
    if (getSiddhiDebugger() != null) {
        getSiddhiDebugger().checkBreakPoint(getQueryName(), SiddhiDebugger.QueryTerminal.OUT, complexEventChunk.getFirst());
    }
    if (convertToStreamEvent) {
        ComplexEventChunk<StreamEvent> streamEventChunk = new ComplexEventChunk<StreamEvent>();
        complexEventChunk.reset();
        while (complexEventChunk.hasNext()) {
            ComplexEvent complexEvent = complexEventChunk.next();
            StreamEvent borrowEvent = streamEventFactory.newInstance();
            streamEventConverter.convertData(complexEvent.getTimestamp(), complexEvent.getOutputData(), complexEvent.getType(), borrowEvent);
            streamEventChunk.add(borrowEvent);
        }
        table.addEvents(streamEventChunk, noOfEvents);
    } else {
        table.addEvents((ComplexEventChunk<StreamEvent>) complexEventChunk, noOfEvents);
    }
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent)

Example 17 with ComplexEvent

use of io.siddhi.core.event.ComplexEvent in project siddhi by wso2.

the class InsertIntoWindowEndPartitionCallback method send.

/**
 * Add the event into the {@link Window}
 *
 * @param complexEventChunk the event to add
 * @param noOfEvents        number of events
 */
@Override
public void send(ComplexEventChunk complexEventChunk, int noOfEvents) {
    if (getSiddhiDebugger() != null) {
        getSiddhiDebugger().checkBreakPoint(getQueryName(), SiddhiDebugger.QueryTerminal.OUT, complexEventChunk.getFirst());
    }
    // If events are inserted directly from another window, expired events can arrive
    complexEventChunk.reset();
    if (complexEventChunk.getFirst() != null) {
        String flowId = SiddhiAppContext.getCurrentFlowId();
        SiddhiAppContext.stopPartitionFlow();
        try {
            while (complexEventChunk.hasNext()) {
                ComplexEvent complexEvent = complexEventChunk.next();
                if (complexEvent.getType() == ComplexEvent.Type.EXPIRED) {
                    complexEvent.setType(ComplexEvent.Type.CURRENT);
                }
            }
            window.add(complexEventChunk);
        } finally {
            SiddhiAppContext.startPartitionFlow(flowId);
        }
    }
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent)

Example 18 with ComplexEvent

use of io.siddhi.core.event.ComplexEvent in project siddhi by wso2.

the class OutputRateLimiter method process.

public void process(List<ComplexEventChunk> complexEventChunks) {
    ComplexEventChunk<ComplexEvent> complexEventChunk = new ComplexEventChunk<>();
    for (ComplexEventChunk aComplexEventChunk : complexEventChunks) {
        complexEventChunk.addAll(aComplexEventChunk);
    }
    process(complexEventChunk);
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk)

Example 19 with ComplexEvent

use of io.siddhi.core.event.ComplexEvent in project siddhi by wso2.

the class OutputRateLimiter method sendToCallBacks.

public void sendToCallBacks(ComplexEventChunk complexEventChunk) {
    MultiProcessStreamReceiver.ReturnEventHolder returnEventHolder = MultiProcessStreamReceiver.getMultiProcessReturn().get();
    if (Level.BASIC.compareTo(siddhiQueryContext.getSiddhiAppContext().getRootMetricsLevel()) <= 0 && latencyTracker != null) {
        latencyTracker.markOut();
    }
    if (returnEventHolder != null) {
        returnEventHolder.setReturnEvents(complexEventChunk);
        return;
    } else if (lockWrapper != null) {
        lockWrapper.unlock();
    }
    if (Level.BASIC.compareTo(siddhiQueryContext.getSiddhiAppContext().getRootMetricsLevel()) <= 0 && latencyTracker != null) {
        latencyTracker.markOut();
    }
    if (lockWrapper != null) {
        lockWrapper.unlock();
    }
    if (!queryCallbacks.isEmpty()) {
        for (QueryCallback callback : queryCallbacks) {
            callback.receiveStreamEvent(complexEventChunk);
        }
    }
    if (outputCallback != null && complexEventChunk.getFirst() != null) {
        complexEventChunk.reset();
        int noOfEvents = 0;
        while (complexEventChunk.hasNext()) {
            ComplexEvent complexEvent = complexEventChunk.next();
            if (complexEvent.getType() == ComplexEvent.Type.EXPIRED) {
                complexEvent.setType(ComplexEvent.Type.CURRENT);
                noOfEvents++;
            } else if (complexEvent.getType() == ComplexEvent.Type.RESET) {
                complexEventChunk.remove();
            } else {
                noOfEvents++;
            }
        }
        if (complexEventChunk.getFirst() != null) {
            outputCallback.send(complexEventChunk, noOfEvents);
        }
    }
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) MultiProcessStreamReceiver(io.siddhi.core.query.input.MultiProcessStreamReceiver) QueryCallback(io.siddhi.core.query.output.callback.QueryCallback)

Example 20 with ComplexEvent

use of io.siddhi.core.event.ComplexEvent in project siddhi by wso2.

the class FirstPerEventOutputRateLimiter method process.

@Override
public void process(ComplexEventChunk complexEventChunk) {
    complexEventChunk.reset();
    ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<>();
    RateLimiterState state = stateHolder.getState();
    try {
        synchronized (state) {
            while (complexEventChunk.hasNext()) {
                ComplexEvent event = complexEventChunk.next();
                complexEventChunk.remove();
                state.counter++;
                if (state.counter == 1) {
                    outputEventChunk.add(event);
                } else if (state.counter == value) {
                    state.counter = 0;
                }
            }
        }
    } finally {
        stateHolder.returnState(state);
    }
    outputEventChunk.reset();
    if (outputEventChunk.hasNext()) {
        sendToCallBacks(outputEventChunk);
    }
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk)

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