Search in sources :

Example 36 with Event

use of org.wso2.eventing.Event in project siddhi by wso2.

the class StreamJunction method sendEvent.

public void sendEvent(Event event) {
    if (throughputTracker != null && siddhiAppContext.isStatsEnabled()) {
        throughputTracker.eventIn();
    }
    if (isTraceEnabled) {
        log.trace(event + " event is received by streamJunction " + this);
    }
    if (disruptor != null) {
        long sequenceNo = ringBuffer.next();
        try {
            Event existingEvent = ringBuffer.get(sequenceNo);
            existingEvent.copyFrom(event);
        } finally {
            ringBuffer.publish(sequenceNo);
        }
    } else {
        for (Receiver receiver : receivers) {
            receiver.receive(event);
        }
    }
}
Also used : Event(org.wso2.siddhi.core.event.Event) ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent)

Example 37 with Event

use of org.wso2.eventing.Event in project siddhi by wso2.

the class StreamJunction method sendEvent.

private void sendEvent(Event[] events) {
    if (throughputTracker != null && siddhiAppContext.isStatsEnabled()) {
        throughputTracker.eventsIn(events.length);
    }
    if (isTraceEnabled) {
        log.trace("Event is received by streamJunction " + this);
    }
    if (disruptor != null) {
        for (Event event : events) {
            // Todo : optimize for arrays
            long sequenceNo = ringBuffer.next();
            try {
                Event existingEvent = ringBuffer.get(sequenceNo);
                existingEvent.copyFrom(event);
            } finally {
                ringBuffer.publish(sequenceNo);
            }
        }
    } else {
        for (Receiver receiver : receivers) {
            receiver.receive(events);
        }
    }
}
Also used : Event(org.wso2.siddhi.core.event.Event) ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent)

Example 38 with Event

use of org.wso2.eventing.Event in project siddhi by wso2.

the class QuerySelector method processInBatchNoGroupBy.

private ComplexEventChunk processInBatchNoGroupBy(ComplexEventChunk complexEventChunk) {
    complexEventChunk.reset();
    ComplexEvent lastEvent = null;
    synchronized (this) {
        while (complexEventChunk.hasNext()) {
            ComplexEvent event = complexEventChunk.next();
            switch(event.getType()) {
                case CURRENT:
                case EXPIRED:
                    eventPopulator.populateStateEvent(event);
                    for (AttributeProcessor attributeProcessor : attributeProcessorList) {
                        attributeProcessor.process(event);
                    }
                    if (!(havingConditionExecutor != null && !havingConditionExecutor.execute(event))) {
                        if ((event.getType() == StreamEvent.Type.CURRENT && currentOn) || (event.getType() == StreamEvent.Type.EXPIRED && expiredOn)) {
                            complexEventChunk.remove();
                            lastEvent = event;
                        }
                    }
                    break;
                case TIMER:
                    break;
                case RESET:
                    for (AttributeProcessor attributeProcessor : attributeProcessorList) {
                        attributeProcessor.process(event);
                    }
                    break;
            }
        }
    }
    if (lastEvent != null) {
        complexEventChunk.clear();
        if (limit == SiddhiConstants.UNKNOWN_STATE || limit > 0) {
            complexEventChunk.add(lastEvent);
        }
        return complexEventChunk;
    }
    return null;
}
Also used : GroupedComplexEvent(org.wso2.siddhi.core.event.GroupedComplexEvent) ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent) AttributeProcessor(org.wso2.siddhi.core.query.selector.attribute.processor.AttributeProcessor)

Example 39 with Event

use of org.wso2.eventing.Event in project siddhi by wso2.

the class QuerySelector method processGroupBy.

private ComplexEventChunk<ComplexEvent> processGroupBy(ComplexEventChunk complexEventChunk) {
    complexEventChunk.reset();
    ComplexEventChunk<ComplexEvent> currentComplexEventChunk = new ComplexEventChunk<ComplexEvent>(complexEventChunk.isBatch());
    synchronized (this) {
        int limitCount = 0;
        while (complexEventChunk.hasNext()) {
            ComplexEvent event = complexEventChunk.next();
            switch(event.getType()) {
                case CURRENT:
                case EXPIRED:
                    eventPopulator.populateStateEvent(event);
                    String groupedByKey = groupByKeyGenerator.constructEventKey(event);
                    GroupByAggregationAttributeExecutor.getKeyThreadLocal().set(groupedByKey);
                    for (AttributeProcessor attributeProcessor : attributeProcessorList) {
                        attributeProcessor.process(event);
                    }
                    if ((event.getType() == StreamEvent.Type.CURRENT && currentOn) || (event.getType() == StreamEvent.Type.EXPIRED && expiredOn)) {
                        if (!(havingConditionExecutor != null && !havingConditionExecutor.execute(event))) {
                            complexEventChunk.remove();
                            if (limit == SiddhiConstants.UNKNOWN_STATE) {
                                currentComplexEventChunk.add(new GroupedComplexEvent(groupedByKey, event));
                            } else {
                                if (limitCount < limit) {
                                    currentComplexEventChunk.add(new GroupedComplexEvent(groupedByKey, event));
                                    limitCount++;
                                }
                            }
                        }
                    }
                    GroupByAggregationAttributeExecutor.getKeyThreadLocal().remove();
                    break;
                case TIMER:
                    break;
                case RESET:
                    for (AttributeProcessor attributeProcessor : attributeProcessorList) {
                        attributeProcessor.process(event);
                    }
                    break;
            }
        }
    }
    if (isOrderBy) {
        orderEventChunk(complexEventChunk);
    }
    if (limit != SiddhiConstants.UNKNOWN_STATE) {
        limitEventChunk(complexEventChunk);
    }
    currentComplexEventChunk.reset();
    if (currentComplexEventChunk.hasNext()) {
        return currentComplexEventChunk;
    }
    return null;
}
Also used : GroupedComplexEvent(org.wso2.siddhi.core.event.GroupedComplexEvent) ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent) ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) GroupedComplexEvent(org.wso2.siddhi.core.event.GroupedComplexEvent) AttributeProcessor(org.wso2.siddhi.core.query.selector.attribute.processor.AttributeProcessor)

Example 40 with Event

use of org.wso2.eventing.Event in project siddhi by wso2.

the class QuerySelector method processNoGroupBy.

private ComplexEventChunk processNoGroupBy(ComplexEventChunk complexEventChunk) {
    complexEventChunk.reset();
    synchronized (this) {
        while (complexEventChunk.hasNext()) {
            ComplexEvent event = complexEventChunk.next();
            switch(event.getType()) {
                case CURRENT:
                case EXPIRED:
                    eventPopulator.populateStateEvent(event);
                    for (AttributeProcessor attributeProcessor : attributeProcessorList) {
                        attributeProcessor.process(event);
                    }
                    if (((event.getType() != StreamEvent.Type.CURRENT || !currentOn) && (event.getType() != StreamEvent.Type.EXPIRED || !expiredOn)) || ((havingConditionExecutor != null && !havingConditionExecutor.execute(event)))) {
                        complexEventChunk.remove();
                    }
                    break;
                case RESET:
                    for (AttributeProcessor attributeProcessor : attributeProcessorList) {
                        attributeProcessor.process(event);
                    }
                    break;
                case TIMER:
                    complexEventChunk.remove();
                    break;
            }
        }
    }
    if (isOrderBy) {
        orderEventChunk(complexEventChunk);
    }
    if (limit != SiddhiConstants.UNKNOWN_STATE) {
        limitEventChunk(complexEventChunk);
    }
    complexEventChunk.reset();
    if (complexEventChunk.hasNext()) {
        return complexEventChunk;
    }
    return null;
}
Also used : GroupedComplexEvent(org.wso2.siddhi.core.event.GroupedComplexEvent) ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent) AttributeProcessor(org.wso2.siddhi.core.query.selector.attribute.processor.AttributeProcessor)

Aggregations

Test (org.testng.annotations.Test)1150 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)1146 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)1145 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)1119 Event (org.wso2.siddhi.core.event.Event)855 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)587 TestUtil (org.wso2.siddhi.core.TestUtil)300 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)218 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)86 SiddhiApp (org.wso2.siddhi.query.api.SiddhiApp)79 Query (org.wso2.siddhi.query.api.execution.query.Query)79 ArrayList (java.util.ArrayList)68 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)63 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)58 ComplexEventChunk (org.wso2.siddhi.core.event.ComplexEventChunk)38 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)35 GroupedComplexEvent (org.wso2.siddhi.core.event.GroupedComplexEvent)16 InMemoryBroker (org.wso2.siddhi.core.util.transport.InMemoryBroker)16 HashMap (java.util.HashMap)14 CannotRestoreSiddhiAppStateException (org.wso2.siddhi.core.exception.CannotRestoreSiddhiAppStateException)13