Search in sources :

Example 26 with Event

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();
}
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) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback) Test(org.junit.Test)

Example 27 with Event

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();
}
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) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback) Test(org.junit.Test)

Example 28 with Event

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);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 29 with Event

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");
        }
    }
}
Also used : ApplicationEvent(org.wso2.carbon.apimgt.core.models.events.ApplicationEvent)

Example 30 with Event

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");
    }
}
Also used : SubscriptionEvent(org.wso2.carbon.apimgt.core.models.events.SubscriptionEvent)

Aggregations

APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)8 GatewayException (org.wso2.carbon.apimgt.core.exception.GatewayException)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)5 Event (org.wso2.carbon.apimgt.core.models.Event)5 Connection (java.sql.Connection)4 PreparedStatement (java.sql.PreparedStatement)4 SQLException (java.sql.SQLException)4 Test (org.testng.annotations.Test)4 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)4 Function (org.wso2.carbon.apimgt.core.models.Function)4 ZonedDateTime (java.time.ZonedDateTime)3 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)3 API (org.wso2.carbon.apimgt.core.models.API)3 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)3 ApplicationEvent (org.wso2.carbon.apimgt.core.models.events.ApplicationEvent)3 PolicyEvent (org.wso2.carbon.apimgt.core.models.events.PolicyEvent)3 ThreatProtectionEvent (org.wso2.carbon.apimgt.core.models.events.ThreatProtectionEvent)3 Gson (com.google.gson.Gson)2 URI (java.net.URI)2