Java Code Examples for org.wso2.carbon.databridge.agent.DataPublisher#publish()

The following examples show how to use org.wso2.carbon.databridge.agent.DataPublisher#publish() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Client.java    From product-cep with Apache License 2.0 6 votes vote down vote up
private static void sendWarmUpEvents(DataPublisher dataPublisher, long warmUpCount) {
    long counter = 0;
    Random randomGenerator = new Random();
    String streamId = "org.wso2.event.sensor.stream:1.0.0";

    while (counter < warmUpCount) {
        boolean isPowerSaveEnabled = randomGenerator.nextBoolean();
        int sensorId = randomGenerator.nextInt();
        double longitude = randomGenerator.nextDouble();
        double latitude = randomGenerator.nextDouble();
        float humidity = randomGenerator.nextFloat();
        double sensorValue = randomGenerator.nextDouble();
        Event event = new Event(streamId, System.currentTimeMillis(),
                new Object[]{System.currentTimeMillis(), isPowerSaveEnabled, sensorId,
                        "warmup-" + counter},
                new Object[]{longitude, latitude},
                new Object[]{humidity, sensorValue});

        dataPublisher.publish(event);
        counter++;
    }
}
 
Example 2
Source File: HttpdLogAgent.java    From product-cep with Apache License 2.0 6 votes vote down vote up
private static void publishLogEvents(DataPublisher dataPublisher, String streamId) throws FileNotFoundException {
    Scanner scanner = new Scanner(new FileInputStream(SAMPLE_LOG_PATH));
    try {
        int i = 1;
        while (scanner.hasNextLine()) {
            System.out.println("Publish log event : " + i);
            String aLog = scanner.nextLine();
            Event event = new Event(streamId, System.currentTimeMillis(), new Object[]{"external"}, null,
                                    new Object[]{aLog});
            dataPublisher.publish(event);
            i++;
        }
    } finally {
        scanner.close();
    }
}
 
Example 3
Source File: StockQuoteClient.java    From product-cep with Apache License 2.0 5 votes vote down vote up
public static void publish(String host, String port, String username, String password, int events)
        throws MalformedStreamDefinitionException,
        StreamDefinitionException, DifferentStreamDefinitionAlreadyDefinedException,
        MalformedURLException,
        AuthenticationException, NoStreamDefinitionExistException,
        org.wso2.carbon.databridge.commons.exception.AuthenticationException,
        TransportException, SocketException, DataEndpointAgentConfigurationException, DataEndpointException, DataEndpointAuthenticationException, DataEndpointConfigurationException {
    System.out.println("Starting Stock quote Agent");

    KeyStoreUtil.setTrustStoreParams();

    //create data publisher
    DataPublisher dataPublisher = new DataPublisher("tcp://" + host + ":" + port, username, password);

    String streamId = DataBridgeCommonsUtils.generateStreamId(STREAM_NAME1, VERSION1);

    //Publish event for a valid stream
    if (!streamId.isEmpty()) {
        System.out.println("Stream ID: " + streamId);

        while (sentEventCount < events) {
            dataPublisher.publish(streamId, null, null, getPayload());
            sentEventCount++;
            System.out.println("Events published : " + sentEventCount);
        }
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            //ignore
        }

        dataPublisher.shutdown();
    }
}
 
Example 4
Source File: Client.java    From product-cep with Apache License 2.0 5 votes vote down vote up
private static void publishEvents(DataPublisher dataPublisher, long eventCount, long elapsedCount,
                                  long warmUpCount) {
    long counter = 0;
    Random randomGenerator = new Random();
    String streamId = "org.wso2.event.sensor.stream:1.0.0";
    long lastTime = System.currentTimeMillis();
    DecimalFormat decimalFormat = new DecimalFormat("#");

    while (counter < eventCount) {
        boolean isPowerSaveEnabled = randomGenerator.nextBoolean();
        int sensorId = randomGenerator.nextInt();
        double longitude = randomGenerator.nextDouble();
        double latitude = randomGenerator.nextDouble();
        float humidity = randomGenerator.nextFloat();
        double sensorValue = randomGenerator.nextDouble();
        Event event = new Event(streamId, System.currentTimeMillis(),
                new Object[]{System.currentTimeMillis(), isPowerSaveEnabled, sensorId,
                        "temperature-" + counter},
                new Object[]{longitude, latitude},
                new Object[]{humidity, sensorValue});

        dataPublisher.publish(event);

        if ((counter > warmUpCount) && ((counter + 1) % elapsedCount == 0)) {

            long currentTime = System.currentTimeMillis();
            long elapsedTime = currentTime - lastTime;
            double throughputPerSecond = (((double) elapsedCount) / elapsedTime) * 1000;
            lastTime = currentTime;
            log.info("Sent " + elapsedCount + " sensor events in " + elapsedTime
                    + " milliseconds with total throughput of " + decimalFormat.format(throughputPerSecond)
                    + " events per second.");
        }

        counter++;
    }
}
 
Example 5
Source File: Client.java    From product-cep with Apache License 2.0 5 votes vote down vote up
private static void publishEventsForLatency(DataPublisher dataPublisher, long eventCount, long elapsedCount,
                                            long warmUpCount) {
    sendWarmUpEvents(dataPublisher, warmUpCount);
    long counter = 0;
    Random randomGenerator = new Random();
    String streamId = "org.wso2.event.sensor.stream:1.0.0";

    while (counter < eventCount) {
        boolean isPowerSaveEnabled = randomGenerator.nextBoolean();
        int sensorId = randomGenerator.nextInt();
        double longitude = randomGenerator.nextDouble();
        double latitude = randomGenerator.nextDouble();
        float humidity = randomGenerator.nextFloat();
        double sensorValue = randomGenerator.nextDouble();
        Event event = new Event(streamId, System.currentTimeMillis(),
                new Object[]{System.currentTimeMillis(), isPowerSaveEnabled, sensorId,
                        "temperature-" + counter},
                new Object[]{longitude, latitude},
                new Object[]{humidity, sensorValue});

        dataPublisher.publish(event);
        log.info("Sent event " + counter + " at " + System.currentTimeMillis());

        if (elapsedCount > 0) {
            try {
                Thread.sleep(elapsedCount);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        counter++;
    }
}
 
Example 6
Source File: AnalyticStatClient.java    From product-cep with Apache License 2.0 4 votes vote down vote up
public static void publish(String host, String port, String username, String password, int events)
            throws  MalformedStreamDefinitionException,
            StreamDefinitionException, DifferentStreamDefinitionAlreadyDefinedException,
            MalformedURLException,
            AuthenticationException, NoStreamDefinitionExistException,
            org.wso2.carbon.databridge.commons.exception.AuthenticationException,
            TransportException, SocketException, DataEndpointAgentConfigurationException, DataEndpointException,
            DataEndpointAuthenticationException, DataEndpointConfigurationException {
        System.out.println("Starting Statistics Agent");
        KeyStoreUtil.setTrustStoreParams();

        //create data publisher
        DataPublisher dataPublisher = new DataPublisher("tcp://" + host + ":" + port, username, password);


//        StreamDefinition streamDefinition = new StreamDefinition(STREAM_NAME1, VERSION1);
//        streamDefinition.addMetaData("ipAdd", AttributeType.STRING);
//        streamDefinition.addMetaData("index", AttributeType.LONG);
//        streamDefinition.addMetaData("timestamp", AttributeType.LONG);
//        streamDefinition.addMetaData("nanoTime", AttributeType.LONG);
//        streamDefinition.addPayloadData("userID", AttributeType.STRING);
//        streamDefinition.addPayloadData("searchTerms", AttributeType.STRING);
//        String streamId = dataPublisher.defineStream(streamDefinition);

        String streamId = DataBridgeCommonsUtils.generateStreamId(STREAM_NAME1, VERSION1);
        //Publish event for a valid stream
        if (!streamId.isEmpty()) {
            System.out.println("Stream ID: " + streamId);

            while (sentEventCount < events) {
                dataPublisher.publish(streamId, getMeta(), null, getPayload());
                sentEventCount++;
                System.out.println("Events published : " + sentEventCount);
            }
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                //ignore
            }

            dataPublisher.shutdown();
        }
    }