Search in sources :

Example 1 with InputHandler

use of org.wso2.siddhi.core.stream.input.InputHandler in project siddhi by wso2.

the class InputManager method constructInputHandler.

public InputHandler constructInputHandler(String streamId) {
    InputHandler inputHandler = new InputHandler(streamId, inputHandlerMap.size(), inputEntryValve);
    StreamJunction streamJunction = streamJunctionMap.get(streamId);
    if (streamJunction == null) {
        throw new DefinitionNotExistException("Stream with stream ID " + streamId + " has not been defined");
    }
    inputDistributor.addInputProcessor(streamJunctionMap.get(streamId).constructPublisher());
    inputHandlerMap.put(streamId, inputHandler);
    return inputHandler;
}
Also used : StreamJunction(org.wso2.siddhi.core.stream.StreamJunction) DefinitionNotExistException(org.wso2.siddhi.core.exception.DefinitionNotExistException)

Example 2 with InputHandler

use of org.wso2.siddhi.core.stream.input.InputHandler in project siddhi by wso2.

the class SourceMapper method setInputHandler.

public final void setInputHandler(InputHandler inputHandler) {
    InputEventHandlerCallback inputEventHandlerCallback;
    if (sourceHandler != null) {
        sourceHandler.setInputHandler(inputHandler);
        inputEventHandlerCallback = sourceHandler;
    } else {
        inputEventHandlerCallback = new PassThroughSourceHandler(inputHandler);
    }
    LatencyTracker mapperLatencyTracker = null;
    this.inputEventHandler = new InputEventHandler(inputHandler, transportMappings, trpProperties, sourceType, mapperLatencyTracker, siddhiAppContext, inputEventHandlerCallback);
}
Also used : LatencyTracker(org.wso2.siddhi.core.util.statistics.LatencyTracker)

Example 3 with InputHandler

use of org.wso2.siddhi.core.stream.input.InputHandler in project siddhi by wso2.

the class PartitionTestCase1 method testPartitionQuery22.

@Test
public void testPartitionQuery22() throws InterruptedException {
    log.info("Partition test22");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "@app:name('PartitionTest10') " + "define stream cseEventStream (symbol string, price float,volume int);" + "define stream cseEventStream1 (symbol string, price float,volume int);" + "partition with (symbol of cseEventStream)" + "begin" + "@info(name = 'query') from cseEventStream#window.time(1 sec) " + "select symbol, avg(price) as avgPrice, volume " + "having avgPrice > 10" + "insert expired events into OutStockStream ;" + "end ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            for (Event event : events) {
                count.incrementAndGet();
                if (count.get() == 1) {
                    AssertJUnit.assertEquals(75.0, event.getData()[1]);
                }
                eventArrived = true;
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "IBM", 75f, 100 });
    inputHandler.send(new Object[] { "IBM", 75f, 100 });
    SiddhiTestHelper.waitForEvents(200, 1, count, 60000);
    AssertJUnit.assertTrue(1 <= count.get());
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) StreamCallback(org.wso2.siddhi.core.stream.output.StreamCallback) Test(org.testng.annotations.Test)

Example 4 with InputHandler

use of org.wso2.siddhi.core.stream.input.InputHandler in project siddhi by wso2.

the class PartitionTestCase1 method testDivideExpressionExecutorDoubleCase.

@Test
public void testDivideExpressionExecutorDoubleCase() throws InterruptedException {
    log.info("Partition testDivideExpressionExecutorDoubleCase");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "@app:name('testDivideExpressionExecutorDoubleCase') " + "define stream cseEventStream (atr1 string,  atr2 string, atr3 int, atr4 double, " + "atr5 long,  atr6 long,  atr7 double,  atr8 float , atr9 bool, atr10 bool,  atr11 int);" + "partition with (atr1 of cseEventStream) begin @info(name = 'query1') from " + "cseEventStream[atr5 < 700 ] select atr4/atr7 as dividedVal, atr5 as threshold,  atr1 as" + " symbol, " + "cast(atr2,  'double') as priceInDouble,  sum(atr7) as summedValue insert " + "into OutStockStream ; end ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            for (Event event : events) {
                count.incrementAndGet();
                if (count.get() == 1) {
                    AssertJUnit.assertEquals(8.836395450568679, event.getData(0));
                    eventArrived = true;
                }
                if (count.get() == 2) {
                    AssertJUnit.assertEquals(6.640368178829717, event.getData(0));
                    eventArrived = true;
                }
                if (count.get() == 3) {
                    AssertJUnit.assertEquals(2.255140393544108, event.getData(0));
                    eventArrived = true;
                }
                if (count.get() == 4) {
                    AssertJUnit.assertEquals(1.156400274788184, event.getData(0));
                    eventArrived = true;
                }
            }
            eventArrived = true;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "IBM", null, 100, 101.0, 500L, 200L, 11.43, 75.7f, false, true, 105 });
    inputHandler.send(new Object[] { "WSO2", "aa", 100, 101.0, 501L, 201L, 15.21, 76.7f, false, true, 106 });
    inputHandler.send(new Object[] { "IBM", null, 100, 102.0, 502L, 202L, 45.23, 77.7f, false, true, 107 });
    inputHandler.send(new Object[] { "ORACLE", null, 100, 101.0, 502L, 202L, 87.34, 77.7f, false, false, 108 });
    SiddhiTestHelper.waitForEvents(100, 4, count, 60000);
    AssertJUnit.assertEquals(4, count.get());
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) StreamCallback(org.wso2.siddhi.core.stream.output.StreamCallback) Test(org.testng.annotations.Test)

Example 5 with InputHandler

use of org.wso2.siddhi.core.stream.input.InputHandler in project siddhi by wso2.

the class PartitionTestCase1 method testPartitionQuery39.

@Test
public void testPartitionQuery39() throws InterruptedException {
    log.info("Partition test");
    SiddhiApp siddhiApp = SiddhiApp.siddhiApp("Test").defineStream(StreamDefinition.id("streamA").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT));
    Query query = Query.query();
    query.from(InputStream.stream("streamA"));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")));
    query.insertInto("StockQuote");
    Partition partition = Partition.partition().annotation(Annotation.annotation("info").element("name", "partitionA")).with("streamA", Expression.variable("symbol")).addQuery(query);
    siddhiApp.addPartition(partition);
    SiddhiManager siddhiManager = new SiddhiManager();
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    StreamCallback streamCallback = new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            AssertJUnit.assertTrue("IBM".equals(events[0].getData(0)) || "WSO2".equals(events[0].getData(0)));
            count.addAndGet(events.length);
            eventArrived = true;
        }
    };
    siddhiAppRuntime.addCallback("StockQuote", streamCallback);
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("streamA");
    siddhiAppRuntime.start();
    inputHandler.send(new Event(System.currentTimeMillis(), new Object[] { "IBM", 700 }));
    inputHandler.send(new Event(System.currentTimeMillis(), new Object[] { "WSO2", 60 }));
    inputHandler.send(new Event(System.currentTimeMillis(), new Object[] { "WSO2", 60 }));
    Thread.sleep(1000);
    AssertJUnit.assertEquals(3, count.get());
    siddhiAppRuntime.shutdown();
}
Also used : Partition(org.wso2.siddhi.query.api.execution.partition.Partition) InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiApp(org.wso2.siddhi.query.api.SiddhiApp) Query(org.wso2.siddhi.query.api.execution.query.Query) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) StreamCallback(org.wso2.siddhi.core.stream.output.StreamCallback) Test(org.testng.annotations.Test)

Aggregations

InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)1155 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)1151 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)1149 Test (org.testng.annotations.Test)1136 Event (org.wso2.siddhi.core.event.Event)800 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)201 SiddhiApp (org.wso2.siddhi.query.api.SiddhiApp)80 Query (org.wso2.siddhi.query.api.execution.query.Query)79 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)77 ArrayList (java.util.ArrayList)25 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)13 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)13 CannotRestoreSiddhiAppStateException (org.wso2.siddhi.core.exception.CannotRestoreSiddhiAppStateException)13 InMemoryPersistenceStore (org.wso2.siddhi.core.util.persistence.InMemoryPersistenceStore)13 PersistenceStore (org.wso2.siddhi.core.util.persistence.PersistenceStore)13 InMemoryBroker (org.wso2.siddhi.core.util.transport.InMemoryBroker)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 PrintStream (java.io.PrintStream)6