use of org.wso2.siddhi.core.event.Event in project carbon-apimgt by wso2.
the class ThrottleTimeBatchWindowTestCase method throttleTimeWindowBatchTest1.
@Test
public void throttleTimeWindowBatchTest1() throws InterruptedException {
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "" + "define stream cseEventStream (symbol string, price float, volume int);";
String query = "" + "@info(name = 'query1') " + "from cseEventStream#throttler:timeBatch(5 sec) " + "select symbol,sum(price) as sumPrice,volume, expiryTimeStamp " + "insert all events into outputStream ;";
SiddhiAppRuntime executionPlanRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
executionPlanRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
if (inEvents != null) {
inEventCount = inEventCount + inEvents.length;
} else if (removeEvents != null) {
removeEventCount = removeEventCount + removeEvents.length;
}
eventArrived = true;
}
});
InputHandler inputHandler = executionPlanRuntime.getInputHandler("cseEventStream");
executionPlanRuntime.start();
inputHandler.send(new Object[] { "IBM", 700f, 0 });
Thread.sleep(500);
inputHandler.send(new Object[] { "WSO2", 60.5f, 1 });
Thread.sleep(6000);
inputHandler.send(new Object[] { "IBM", 700f, 0 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 1 });
Thread.sleep(6000);
Assert.assertEquals(4, inEventCount);
Assert.assertEquals(2, removeEventCount);
Assert.assertTrue(eventArrived);
executionPlanRuntime.shutdown();
}
use of org.wso2.siddhi.core.event.Event in project carbon-apimgt by wso2.
the class ThrottleTimeBatchWindowTestCase method throttleTimeWindowBatchTest2.
@Test
public void throttleTimeWindowBatchTest2() throws InterruptedException {
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "" + "define stream cseEventStream (symbol string, price float, volume int);";
String query = "" + "@info(name = 'query1') " + "from cseEventStream#throttler:timeBatch(5 sec , 0) " + "select symbol,sum(price) as sumPrice,volume, expiryTimeStamp " + "insert all events into outputStream ;";
SiddhiAppRuntime executionPlanRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
executionPlanRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
if (inEvents != null) {
inEventCount = inEventCount + inEvents.length;
} else if (removeEvents != null) {
removeEventCount = removeEventCount + removeEvents.length;
lastRemoveEvent = removeEvents[removeEvents.length - 1];
}
eventArrived = true;
}
});
InputHandler inputHandler = executionPlanRuntime.getInputHandler("cseEventStream");
executionPlanRuntime.start();
inputHandler.send(new Object[] { "IBM", 700f, 0 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 1 });
Thread.sleep(10000);
Assert.assertEquals(2, inEventCount);
Assert.assertEquals("WSO2", lastRemoveEvent.getData()[0]);
Assert.assertTrue(eventArrived);
executionPlanRuntime.shutdown();
}
use of org.wso2.siddhi.core.event.Event in project carbon-apimgt by wso2.
the class FunctionDAOImpl method addEventFunctionMapping.
/**
* {@inheritDoc}
*/
@Override
public void addEventFunctionMapping(String userName, Event event, String functionName) throws APIMgtDAOException {
if (userName == null) {
throw new IllegalArgumentException("Username must not be null");
}
if (event == null) {
throw new IllegalArgumentException("Event must not be null");
}
if (functionName == null) {
throw new IllegalArgumentException("Function name must not be null");
}
final String sqlQuery = "INSERT INTO AM_EVENT_FUNCTION_MAPPING(EVENT, FUNCTION_ID) " + "SELECT ?, FUNCTION_ID " + "FROM AM_LAMBDA_FUNCTION " + "WHERE USER_NAME = ? AND FUNCTION_NAME = ?";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(sqlQuery)) {
preparedStatement.setString(1, event.getEventAsString());
preparedStatement.setString(2, userName);
preparedStatement.setString(3, functionName);
preparedStatement.executeUpdate();
} catch (SQLException e) {
throw new APIMgtDAOException("Error adding new event function mapping for user: " + userName, e);
}
}
use of org.wso2.siddhi.core.event.Event in project carbon-apimgt by wso2.
the class APIGatewayPublisherImpl method deleteApplication.
@Override
public void deleteApplication(String applicationId) throws GatewayException {
if (applicationId != null) {
ApplicationEvent applicationEvent = new ApplicationEvent(APIMgtConstants.GatewayEventTypes.APPLICATION_DELETE);
applicationEvent.setApplicationId(applicationId);
publishToStoreTopic(applicationEvent);
if (log.isDebugEnabled()) {
log.debug("Application : " + applicationId + " deleted event has been successfully published " + "to broker");
}
}
}
use of org.wso2.siddhi.core.event.Event in project carbon-apimgt by wso2.
the class APIGatewayPublisherImpl method updateAPISubscriptionStatus.
@Override
public void updateAPISubscriptionStatus(List<SubscriptionValidationData> subscriptionValidationDataList) throws GatewayException {
SubscriptionEvent subscriptionBlockEvent = new SubscriptionEvent(APIMgtConstants.GatewayEventTypes.SUBSCRIPTION_STATUS_CHANGE);
subscriptionBlockEvent.setSubscriptionsList(subscriptionValidationDataList);
publishToStoreTopic(subscriptionBlockEvent);
if (log.isDebugEnabled()) {
log.debug("Subscription updated event has been successfully published to broker");
}
}
Aggregations