Search in sources :

Example 46 with StreamEvent

use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.

the class ExhaustiveCollectionExecutor method find.

public StreamEvent find(StateEvent matchingEvent, IndexedEventHolder indexedEventHolder, StreamEventCloner storeEventCloner) {
    ComplexEventChunk<StreamEvent> returnEventChunk = new ComplexEventChunk<StreamEvent>(false);
    Collection<StreamEvent> storeEvents = indexedEventHolder.getAllEvents();
    for (StreamEvent storeEvent : storeEvents) {
        matchingEvent.setEvent(storeEventIndex, storeEvent);
        if ((Boolean) expressionExecutor.execute(matchingEvent)) {
            if (storeEventCloner != null) {
                returnEventChunk.add(storeEventCloner.copyStreamEvent(storeEvent));
            } else {
                returnEventChunk.add(storeEvent);
            }
        }
        matchingEvent.setEvent(storeEventIndex, null);
    }
    return returnEventChunk.getFirst();
}
Also used : ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Example 47 with StreamEvent

use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.

the class ExhaustiveCollectionExecutor method findEvents.

public Collection<StreamEvent> findEvents(StateEvent matchingEvent, Collection<StreamEvent> preProcessedstoreEvents) {
    HashSet<StreamEvent> streamEvents = new HashSet<StreamEvent>();
    for (StreamEvent storeEvent : preProcessedstoreEvents) {
        matchingEvent.setEvent(storeEventIndex, storeEvent);
        if ((Boolean) expressionExecutor.execute(matchingEvent)) {
            streamEvents.add(storeEvent);
        }
        matchingEvent.setEvent(storeEventIndex, null);
    }
    return streamEvents;
}
Also used : StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) HashSet(java.util.HashSet)

Example 48 with StreamEvent

use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.

the class ExhaustiveCollectionExecutor method delete.

@Override
public void delete(StateEvent deletingEvent, IndexedEventHolder indexedEventHolder) {
    Collection<StreamEvent> storeEvents = indexedEventHolder.getAllEvents();
    Set<StreamEvent> toDeleteEvents = new HashSet<StreamEvent>();
    for (StreamEvent storeEvent : storeEvents) {
        deletingEvent.setEvent(storeEventIndex, storeEvent);
        if ((Boolean) expressionExecutor.execute(deletingEvent)) {
            toDeleteEvents.add(storeEvent);
        }
        deletingEvent.setEvent(storeEventIndex, null);
    }
    indexedEventHolder.deleteAll(toDeleteEvents);
}
Also used : StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) HashSet(java.util.HashSet)

Example 49 with StreamEvent

use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.

the class OverwriteTableIndexOperator method tryUpdate.

@Override
public ComplexEventChunk<StreamEvent> tryUpdate(ComplexEventChunk<StateEvent> updatingOrAddingEventChunk, Object storeEvents, InMemoryCompiledUpdateSet compiledUpdateSet, AddingStreamEventExtractor addingStreamEventExtractor) {
    updatingOrAddingEventChunk.reset();
    while (updatingOrAddingEventChunk.hasNext()) {
        StateEvent overwritingOrAddingEvent = updatingOrAddingEventChunk.next();
        ((IndexedEventHolder) storeEvents).overwrite(addingStreamEventExtractor.getAddingStreamEvent(overwritingOrAddingEvent));
    }
    return null;
}
Also used : IndexedEventHolder(org.wso2.siddhi.core.table.holder.IndexedEventHolder) StateEvent(org.wso2.siddhi.core.event.state.StateEvent)

Example 50 with StreamEvent

use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.

the class TestDebugger method testDebugger9.

@Test
public void testDebugger9() throws InterruptedException {
    log.info("Siddi Debugger Test 9: Test state traversal in a simple query");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "@config(async = 'true') define stream cseEventStream (symbol string, price float, " + "volume int);";
    final String query = "@info(name = 'query1')" + "from cseEventStream#window.length(3) " + "select symbol, price, sum(volume) as volume " + "insert into OutputStream; ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
    siddhiAppRuntime.addCallback("OutputStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            inEventCount.addAndGet(events.length);
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    SiddhiDebugger siddhiDebugger = siddhiAppRuntime.debug();
    siddhiDebugger.acquireBreakPoint("query1", SiddhiDebugger.QueryTerminal.IN);
    siddhiDebugger.setDebuggerCallback(new SiddhiDebuggerCallback() {

        @Override
        public void debugEvent(ComplexEvent event, String queryName, SiddhiDebugger.QueryTerminal queryTerminal, SiddhiDebugger debugger) {
            log.info("Query: " + queryName + ":" + queryTerminal);
            log.info(event);
            int count = debugEventCount.addAndGet(getCount(event));
            if (count == 2) {
                Map<String, Object> queryState = debugger.getQueryState(queryName);
                log.info(queryState);
                log.info(queryState.values().toArray()[0]);
                StreamEvent streamEvent = null;
                // Order of the query state items is unpredictable
                for (Map.Entry<String, Object> entry : queryState.entrySet()) {
                    if (entry.getKey().startsWith("AbstractStreamProcessor")) {
                        streamEvent = (StreamEvent) ((Map<String, Object>) entry.getValue()).get("ExpiredEventChunk");
                        break;
                    }
                }
                AssertJUnit.assertArrayEquals(streamEvent.getOutputData(), new Object[] { "WSO2", 50.0f, null });
            }
            debugger.next();
        }
    });
    inputHandler.send(new Object[] { "WSO2", 50f, 60 });
    inputHandler.send(new Object[] { "WSO2", 70f, 40 });
    Thread.sleep(100);
    AssertJUnit.assertEquals("Invalid number of output events", 2, inEventCount.get());
    AssertJUnit.assertEquals("Invalid number of debug events", 4, debugEventCount.get());
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) StreamCallback(org.wso2.siddhi.core.stream.output.StreamCallback) ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent) Event(org.wso2.siddhi.core.event.Event) Map(java.util.Map) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Aggregations

StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)121 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)42 ComplexEventChunk (org.wso2.siddhi.core.event.ComplexEventChunk)41 StateEvent (org.wso2.siddhi.core.event.state.StateEvent)23 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)20 Test (org.testng.annotations.Test)19 Event (org.wso2.siddhi.core.event.Event)16 StreamEventPool (org.wso2.siddhi.core.event.stream.StreamEventPool)16 ExpressionExecutor (org.wso2.siddhi.core.executor.ExpressionExecutor)14 ArrayList (java.util.ArrayList)13 Map (java.util.Map)10 ConstantExpressionExecutor (org.wso2.siddhi.core.executor.ConstantExpressionExecutor)9 HashSet (java.util.HashSet)8 StreamEventConverter (org.wso2.siddhi.core.event.stream.converter.StreamEventConverter)8 Attribute (org.wso2.siddhi.query.api.definition.Attribute)8 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)8 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)7 ConversionStreamEventChunk (org.wso2.siddhi.core.event.stream.converter.ConversionStreamEventChunk)6 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)6 HashMap (java.util.HashMap)5