Search in sources :

Example 41 with ComplexEvent

use of org.ballerinalang.siddhi.core.event.ComplexEvent in project ballerina by ballerina-lang.

the class InsertIntoWindowCallback 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();
    while (complexEventChunk.hasNext()) {
        ComplexEvent complexEvent = complexEventChunk.next();
        if (complexEvent.getType() == ComplexEvent.Type.EXPIRED) {
            complexEvent.setType(ComplexEvent.Type.CURRENT);
        }
    }
    window.add(complexEventChunk);
}
Also used : ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent)

Example 42 with ComplexEvent

use of org.ballerinalang.siddhi.core.event.ComplexEvent in project ballerina by ballerina-lang.

the class OutputCallback method constructMatchingStateEventChunk.

protected ComplexEventChunk<StateEvent> constructMatchingStateEventChunk(ComplexEventChunk matchingComplexEventChunk, boolean convertToStreamEvent, StateEventPool stateEventPool, int matchingStreamIndex, StreamEventPool streamEventPool, StreamEventConverter streamEventConverter) {
    ComplexEventChunk<StateEvent> stateEventChunk = new ComplexEventChunk<StateEvent>(matchingComplexEventChunk.isBatch());
    while (matchingComplexEventChunk.hasNext()) {
        ComplexEvent matchingComplexEvent = matchingComplexEventChunk.next();
        matchingComplexEventChunk.remove();
        StateEvent stateEvent = stateEventPool.borrowEvent();
        if (convertToStreamEvent) {
            StreamEvent borrowEvent = streamEventPool.borrowEvent();
            streamEventConverter.convertData(matchingComplexEvent.getTimestamp(), matchingComplexEvent.getOutputData(), matchingComplexEvent.getType() == ComplexEvent.Type.EXPIRED ? ComplexEvent.Type.CURRENT : matchingComplexEvent.getType(), borrowEvent);
            stateEvent.addEvent(matchingStreamIndex, borrowEvent);
        } else {
            stateEvent.addEvent(matchingStreamIndex, (StreamEvent) matchingComplexEvent);
        }
        stateEventChunk.add(stateEvent);
    }
    return stateEventChunk;
}
Also used : ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) ComplexEventChunk(org.ballerinalang.siddhi.core.event.ComplexEventChunk) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) StateEvent(org.ballerinalang.siddhi.core.event.state.StateEvent)

Example 43 with ComplexEvent

use of org.ballerinalang.siddhi.core.event.ComplexEvent in project ballerina by ballerina-lang.

the class QueryCallback method receiveStreamEvent.

public void receiveStreamEvent(ComplexEventChunk complexEventChunk) {
    Event[] currentEvents = null;
    Event[] expiredEvents = null;
    long timestamp = -1;
    List<Event> currentEventBuffer = new ArrayList<Event>();
    List<Event> expiredEventBuffer = new ArrayList<Event>();
    complexEventChunk.reset();
    while (complexEventChunk.hasNext()) {
        ComplexEvent streamEvent = complexEventChunk.next();
        if (streamEvent.getType() == StreamEvent.Type.EXPIRED) {
            bufferEvent(streamEvent, expiredEventBuffer);
        } else if (streamEvent.getType() == StreamEvent.Type.CURRENT) {
            bufferEvent(streamEvent, currentEventBuffer);
        }
        timestamp = streamEvent.getTimestamp();
    }
    if (!currentEventBuffer.isEmpty()) {
        currentEvents = currentEventBuffer.toArray(new Event[currentEventBuffer.size()]);
        currentEventBuffer.clear();
    }
    if (!expiredEventBuffer.isEmpty()) {
        expiredEvents = expiredEventBuffer.toArray(new Event[expiredEventBuffer.size()]);
        expiredEventBuffer.clear();
    }
    send(timestamp, currentEvents, expiredEvents);
}
Also used : ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) ArrayList(java.util.ArrayList) ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) Event(org.ballerinalang.siddhi.core.event.Event)

Example 44 with ComplexEvent

use of org.ballerinalang.siddhi.core.event.ComplexEvent in project ballerina by ballerina-lang.

the class OutputRateLimiter method sendToCallBacks.

protected void sendToCallBacks(ComplexEventChunk complexEventChunk) {
    if (siddhiAppContext.isStatsEnabled() && 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(org.ballerinalang.siddhi.core.event.ComplexEvent) QueryCallback(org.ballerinalang.siddhi.core.query.output.callback.QueryCallback)

Example 45 with ComplexEvent

use of org.ballerinalang.siddhi.core.event.ComplexEvent in project ballerina by ballerina-lang.

the class AllPerEventOutputRateLimiter method process.

@Override
public void process(ComplexEventChunk complexEventChunk) {
    complexEventChunk.reset();
    ArrayList<ComplexEventChunk<ComplexEvent>> outputEventChunks = new ArrayList<ComplexEventChunk<ComplexEvent>>();
    synchronized (this) {
        while (complexEventChunk.hasNext()) {
            ComplexEvent event = complexEventChunk.next();
            if (event.getType() == ComplexEvent.Type.CURRENT || event.getType() == ComplexEvent.Type.EXPIRED) {
                complexEventChunk.remove();
                allComplexEventChunk.add(event);
                counter++;
                if (counter == value) {
                    ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<ComplexEvent>(complexEventChunk.isBatch());
                    outputEventChunk.add(allComplexEventChunk.getFirst());
                    allComplexEventChunk.clear();
                    counter = 0;
                    outputEventChunks.add(outputEventChunk);
                }
            }
        }
    }
    for (ComplexEventChunk eventChunk : outputEventChunks) {
        sendToCallBacks(eventChunk);
    }
}
Also used : ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) ComplexEventChunk(org.ballerinalang.siddhi.core.event.ComplexEventChunk) ArrayList(java.util.ArrayList)

Aggregations

ComplexEvent (org.ballerinalang.siddhi.core.event.ComplexEvent)58 ComplexEventChunk (org.ballerinalang.siddhi.core.event.ComplexEventChunk)29 ArrayList (java.util.ArrayList)20 GroupedComplexEvent (org.ballerinalang.siddhi.core.event.GroupedComplexEvent)17 Event (org.ballerinalang.siddhi.core.event.Event)15 SiddhiAppRuntime (org.ballerinalang.siddhi.core.SiddhiAppRuntime)12 SiddhiManager (org.ballerinalang.siddhi.core.SiddhiManager)12 StreamEvent (org.ballerinalang.siddhi.core.event.stream.StreamEvent)12 StreamCallback (org.ballerinalang.siddhi.core.stream.output.StreamCallback)12 InputHandler (org.ballerinalang.siddhi.core.stream.input.InputHandler)11 Test (org.testng.annotations.Test)11 MetaStreamEvent (org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)7 AttributeProcessor (org.ballerinalang.siddhi.core.query.selector.attribute.processor.AttributeProcessor)4 StateEvent (org.ballerinalang.siddhi.core.event.state.StateEvent)3 Iterator (java.util.Iterator)2 Map (java.util.Map)2 LinkedHashMap (java.util.LinkedHashMap)1 Scanner (java.util.Scanner)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 StreamEventPool (org.ballerinalang.siddhi.core.event.stream.StreamEventPool)1