Search in sources :

Example 46 with ComplexEvent

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

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.wso2.siddhi.core.event.ComplexEvent) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback)

Example 47 with ComplexEvent

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

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.wso2.siddhi.core.event.ComplexEvent) ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) ArrayList(java.util.ArrayList)

Example 48 with ComplexEvent

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

the class FirstGroupByPerEventOutputRateLimiter 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();
                GroupedComplexEvent groupedComplexEvent = ((GroupedComplexEvent) event);
                if (!groupByKeys.contains(groupedComplexEvent.getGroupKey())) {
                    groupByKeys.add(groupedComplexEvent.getGroupKey());
                    allComplexEventChunk.add(groupedComplexEvent.getComplexEvent());
                }
                if (++counter == value) {
                    if (allComplexEventChunk.getFirst() != null) {
                        ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<ComplexEvent>(complexEventChunk.isBatch());
                        outputEventChunk.add(allComplexEventChunk.getFirst());
                        outputEventChunks.add(outputEventChunk);
                        allComplexEventChunk.clear();
                        counter = 0;
                        groupByKeys.clear();
                    } else {
                        counter = 0;
                        groupByKeys.clear();
                    }
                }
            }
        }
    }
    for (ComplexEventChunk eventChunk : outputEventChunks) {
        sendToCallBacks(eventChunk);
    }
}
Also used : GroupedComplexEvent(org.wso2.siddhi.core.event.GroupedComplexEvent) ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent) ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) ArrayList(java.util.ArrayList) GroupedComplexEvent(org.wso2.siddhi.core.event.GroupedComplexEvent)

Example 49 with ComplexEvent

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

the class LogStreamProcessor method process.

@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner, ComplexEventPopulater complexEventPopulater) {
    while (streamEventChunk.hasNext()) {
        ComplexEvent complexEvent = streamEventChunk.next();
        switch(attributeExpressionLength) {
            case 0:
                log.info(logPrefix + complexEvent);
                break;
            case 1:
                if (isLogEventExpressionExecutor != null) {
                    if ((Boolean) isLogEventExpressionExecutor.execute(complexEvent)) {
                        log.info(logPrefix + complexEvent);
                    } else {
                        log.info(logPrefix + "Event Arrived");
                    }
                } else {
                    log.info(logPrefix + logMessageExpressionExecutor.execute(complexEvent) + ", " + complexEvent);
                }
                break;
            case 2:
                if (isLogEventExpressionExecutor != null) {
                    if ((Boolean) isLogEventExpressionExecutor.execute(complexEvent)) {
                        log.info(logPrefix + logMessageExpressionExecutor.execute(complexEvent) + ", " + complexEvent);
                    } else {
                        log.info(logPrefix + logMessageExpressionExecutor.execute(complexEvent));
                    }
                } else {
                    LogPriority tempLogPriority = logPriority;
                    if (logPriorityExpressionExecutor != null) {
                        tempLogPriority = LogPriority.valueOf((String) logPriorityExpressionExecutor.execute(complexEvent));
                    }
                    String message = logPrefix + logMessageExpressionExecutor.execute(complexEvent) + ", " + complexEvent;
                    logMessage(tempLogPriority, message);
                }
                break;
            default:
                String message;
                if ((Boolean) isLogEventExpressionExecutor.execute(complexEvent)) {
                    message = logPrefix + logMessageExpressionExecutor.execute(complexEvent) + ", " + complexEvent;
                } else {
                    message = logPrefix + logMessageExpressionExecutor.execute(complexEvent);
                }
                LogPriority tempLogPriority = logPriority;
                if (logPriorityExpressionExecutor != null) {
                    tempLogPriority = LogPriority.valueOf((String) logPriorityExpressionExecutor.execute(complexEvent));
                }
                logMessage(tempLogPriority, message);
        }
    }
    nextProcessor.process(streamEventChunk);
}
Also used : ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent)

Example 50 with ComplexEvent

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

the class StreamFunctionProcessor method processEventChunk.

@Override
protected void processEventChunk(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner, ComplexEventPopulater complexEventPopulater) {
    while (streamEventChunk.hasNext()) {
        ComplexEvent complexEvent = streamEventChunk.next();
        Object[] outputData;
        switch(attributeExpressionLength) {
            case 0:
                outputData = process((Object) null);
                complexEventPopulater.populateComplexEvent(complexEvent, outputData);
                break;
            case 1:
                outputData = process(attributeExpressionExecutors[0].execute(complexEvent));
                complexEventPopulater.populateComplexEvent(complexEvent, outputData);
                break;
            default:
                Object[] inputData = new Object[attributeExpressionLength];
                for (int i = 0; i < attributeExpressionLength; i++) {
                    inputData[i] = attributeExpressionExecutors[i].execute(complexEvent);
                }
                outputData = process(inputData);
                complexEventPopulater.populateComplexEvent(complexEvent, outputData);
        }
    }
    nextProcessor.process(streamEventChunk);
}
Also used : ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent)

Aggregations

ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)59 ComplexEventChunk (org.wso2.siddhi.core.event.ComplexEventChunk)29 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)26 ArrayList (java.util.ArrayList)21 GroupedComplexEvent (org.wso2.siddhi.core.event.GroupedComplexEvent)17 Event (org.wso2.siddhi.core.event.Event)16 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)13 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)13 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)13 Test (org.testng.annotations.Test)12 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)12 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)10 AttributeProcessor (org.wso2.siddhi.core.query.selector.attribute.processor.AttributeProcessor)5 Map (java.util.Map)4 StateEvent (org.wso2.siddhi.core.event.state.StateEvent)4 ExpressionExecutor (org.wso2.siddhi.core.executor.ExpressionExecutor)3 Iterator (java.util.Iterator)2 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)2 Attribute (org.wso2.siddhi.query.api.definition.Attribute)2 HashMap (java.util.HashMap)1