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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations