org.wso2.carbon.databridge.commons.utils.DataBridgeCommonsUtils Java Examples

The following examples show how to use org.wso2.carbon.databridge.commons.utils.DataBridgeCommonsUtils. 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: 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 #2
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();
        }
    }
 
Example #3
Source File: HttpdLogAgent.java    From product-cep with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args)
            throws SocketException, MalformedURLException, AuthenticationException, TransportException, StreamDefinitionException, MalformedStreamDefinitionException, DifferentStreamDefinitionAlreadyDefinedException,
            FileNotFoundException, UnknownHostException, DataEndpointAuthenticationException, DataEndpointAgentConfigurationException, DataEndpointException, DataEndpointConfigurationException {
        System.out.println("Starting HttpLog Agent");

        DataPublisherUtil.setTrustStoreParams();

        AgentHolder.setConfigPath(DataPublisherUtil.getAgentConfigPath());

        String host = args[0];
        String port = args[1];
        String username = args[2];
        String password = args[3];

        //create data publisher

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

        String streamId = DataBridgeCommonsUtils.generateStreamId(HTTPD_LOG_STREAM,VERSION);

//        try {
//            streamId = dataPublisher.findStream(HTTPD_LOG_STREAM, VERSION);
//            System.out.println("Stream already defined");
//
//        } catch (NoStreamDefinitionExistException e) {
//            //Define event stream
//            streamId = dataPublisher.defineStream("{" +
//                                                  "  'name':'" + HTTPD_LOG_STREAM + "'," +
//                                                  "  'version':'" + VERSION + "'," +
//                                                  "  'nickName': 'Httpd_Log_Stream'," +
//                                                  "  'description': 'Sample of Httpd logs'," +
//                                                  "  'metaData':[" +
//                                                  "          {'name':'clientType','type':'STRING'}" +
//                                                  "  ]," +
//                                                  "  'payloadData':[" +
//                                                  "          {'name':'log','type':'STRING'}" +
//                                                  "  ]" +
//                                                  "}");
//
//        }
        if (null != streamId && !streamId.isEmpty()) {
            publishLogEvents(dataPublisher, streamId);
        }
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
        }

        dataPublisher.shutdownWithAgent();
    }