Search in sources :

Example 96 with StreamCallback

use of org.wso2.siddhi.core.stream.output.StreamCallback in project siddhi by wso2.

the class SimpleFilterMultipleQueryPerformance method main.

public static void main(String[] args) throws InterruptedException {
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "define stream cseEventStream (symbol string, price float, volume int, timestamp long);" + "" + "@info(name = 'query1') " + "from cseEventStream[70 > price] " + "select * " + "insert into outputStream ;" + "" + "@info(name = 'query2') " + "from cseEventStream[volume > 90] " + "select * " + "insert into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {

        public int eventCount = 0;

        public int timeSpent = 0;

        long startTime = System.currentTimeMillis();

        @Override
        public void receive(Event[] events) {
            for (Event event : events) {
                eventCount++;
                timeSpent += (System.currentTimeMillis() - (Long) event.getData(3));
                if (eventCount % 1000000 == 0) {
                    System.out.println("Throughput : " + (eventCount * 1000) / ((System.currentTimeMillis()) - startTime));
                    System.out.println("Time spent :  " + (timeSpent * 1.0 / eventCount));
                    startTime = System.currentTimeMillis();
                    eventCount = 0;
                    timeSpent = 0;
                }
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    for (int i = 0; i <= 100; i++) {
        EventPublisher eventPublisher = new EventPublisher(inputHandler);
        eventPublisher.run();
    }
// 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)

Example 97 with StreamCallback

use of org.wso2.siddhi.core.stream.output.StreamCallback in project siddhi by wso2.

the class SimpleFilterSingleQueryWithDisruptorPerformance method main.

public static void main(String[] args) throws InterruptedException {
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "@app:async " + "" + "define stream cseEventStream (symbol string, price float, volume long, timestamp long);" + "" + "@info(name = 'query1') " + "from cseEventStream[700 > price] " + "select * " + "insert into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {

        public int eventCount = 0;

        public int timeSpent = 0;

        long startTime = System.currentTimeMillis();

        @Override
        public void receive(Event[] events) {
            for (Event event : events) {
                eventCount++;
                timeSpent += (System.currentTimeMillis() - (Long) event.getData(3));
                if (eventCount % 1000000 == 0) {
                    System.out.println("Throughput : " + (eventCount * 1000) / ((System.currentTimeMillis()) - startTime));
                    System.out.println("Time spent :  " + (timeSpent * 1.0 / eventCount));
                    startTime = System.currentTimeMillis();
                    eventCount = 0;
                    timeSpent = 0;
                }
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    while (true) {
        inputHandler.send(new Object[] { "WSO2", 55.6f, 100, System.currentTimeMillis() });
        inputHandler.send(new Object[] { "IBM", 75.6f, 100, System.currentTimeMillis() });
        inputHandler.send(new Object[] { "WSO2", 100f, 80, System.currentTimeMillis() });
        inputHandler.send(new Object[] { "IBM", 75.6f, 100, System.currentTimeMillis() });
        inputHandler.send(new Object[] { "WSO2", 55.6f, 100, System.currentTimeMillis() });
        inputHandler.send(new Object[] { "IBM", 75.6f, 100, System.currentTimeMillis() });
        inputHandler.send(new Object[] { "WSO2", 100f, 80, System.currentTimeMillis() });
        inputHandler.send(new Object[] { "IBM", 75.6f, 100, System.currentTimeMillis() });
    }
// 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)

Example 98 with StreamCallback

use of org.wso2.siddhi.core.stream.output.StreamCallback in project siddhi by wso2.

the class SimpleFilterSyncPerformance method main.

public static void main(String[] args) throws InterruptedException {
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = " " + "define stream RequestStream (messageID string, app_key string, api_key string, app_tier string, " + "api_tier string, user_id string, properties string, timeNow long); " + "define stream EligibilityStream (rule string, messageID string, isEligible bool, isLocallyThrottled " + "bool, throttle_key string , timeNow long); ";
    String query = "" + "@info(name = 'query1') " + "FROM RequestStream " + "SELECT 'sub_gold' AS rule, messageID, ( api_tier == 'Gold') AS isEligible,false as " + "isLocallyThrottled,  'sub_gold_TEST1TEST1Test1_key' AS throttle_key , timeNow \n" + "INSERT INTO EligibilityStream; " + "@info(name = 'query2') " + "FROM EligibilityStream[isEligible==false]\n" + "\t\tSELECT rule, messageID, false AS isThrottled , timeNow\n" + "\t\tINSERT INTO ThrottleStream;\n" + "\n" + "@info(name = 'query3') " + "FROM EligibilityStream[isEligible==true AND isLocallyThrottled==true]\n" + "\t\tSELECT rule, messageID, true AS isThrottled , timeNow \n" + "\t\tINSERT INTO ThrottleStream; \n" + "\n" + "@info(name = 'query4') " + "FROM EligibilityStream[isEligible==true AND isLocallyThrottled==false]\n" + "\t\tSELECT rule, messageID, false AS isThrottled, timeNow \n" + "\t\tINSERT INTO ThrottleStream;  ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
    siddhiAppRuntime.addCallback("ThrottleStream", new StreamCallback() {

        public int eventCount = 0;

        public int timeSpent = 0;

        long startTime = System.currentTimeMillis();

        @Override
        public void receive(Event[] events) {
            for (Event event : events) {
                eventCount++;
                timeSpent += (System.currentTimeMillis() - (Long) event.getData(3));
                if (eventCount % 1000000 == 0) {
                    System.out.println("Throughput : " + (eventCount * 1000) / ((System.currentTimeMillis()) - startTime));
                    System.out.println("Time spent :  " + (timeSpent * 1.0 / eventCount));
                    startTime = System.currentTimeMillis();
                    eventCount = 0;
                    timeSpent = 0;
                }
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("RequestStream");
    siddhiAppRuntime.start();
    for (int i = 0; i <= 100; i++) {
        EventPublisher eventPublisher = new EventPublisher(inputHandler);
        eventPublisher.run();
    }
// 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)

Example 99 with StreamCallback

use of org.wso2.siddhi.core.stream.output.StreamCallback in project siddhi by wso2.

the class PartitionSample method main.

public static void main(String[] args) throws InterruptedException {
    // Creating Siddhi Manager
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "define stream cseEventStream (symbol string, price float,volume int);" + "" + "partition with (symbol of cseEventStream)" + "begin" + "   @info(name = 'query') " + "   from cseEventStream " + "   select symbol, sum(price) as price, volume " + "   insert into OutStockStream ;" + "end ";
    // Generating runtime
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    // Adding callback to retrieve output events from stream
    siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
        }
    });
    // Retrieving InputHandler to push events into Siddhi
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    // Starting event processing
    siddhiAppRuntime.start();
    // Sending events to Siddhi
    inputHandler.send(new Object[] { "IBM", 75f, 100 });
    inputHandler.send(new Object[] { "WSO2", 705f, 100 });
    inputHandler.send(new Object[] { "IBM", 35f, 100 });
    inputHandler.send(new Object[] { "ORACLE", 50.0f, 100 });
    Thread.sleep(1000);
    // Shutting down the runtime
    siddhiAppRuntime.shutdown();
    // Shutting down Siddhi
    siddhiManager.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)

Example 100 with StreamCallback

use of org.wso2.siddhi.core.stream.output.StreamCallback in project siddhi by wso2.

the class CallbackTestCase method callbackTest3.

@Test(expectedExceptions = DefinitionNotExistException.class)
public void callbackTest3() throws InterruptedException {
    log.info("callback test3");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "@app:name('callbackTest1') " + "" + "define stream StockStream (symbol string, price float, volume long);" + "" + "@info(name = 'query1') " + "from StockStream[70 > price] " + "select symbol, price " + "insert into outputStream;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("outputStream2", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
        }
    });
    siddhiAppRuntime.shutdown();
}
Also used : 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

StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)218 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)213 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)213 Event (org.wso2.siddhi.core.event.Event)213 Test (org.testng.annotations.Test)207 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)202 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)17 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)14 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 PrintStream (java.io.PrintStream)6 SiddhiApp (org.wso2.siddhi.query.api.SiddhiApp)6 Partition (org.wso2.siddhi.query.api.execution.partition.Partition)6 Query (org.wso2.siddhi.query.api.execution.query.Query)6 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)5 CannotRestoreSiddhiAppStateException (org.wso2.siddhi.core.exception.CannotRestoreSiddhiAppStateException)3 Map (java.util.Map)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 InMemoryPersistenceStore (org.wso2.siddhi.core.util.persistence.InMemoryPersistenceStore)2 PersistenceStore (org.wso2.siddhi.core.util.persistence.PersistenceStore)2