Search in sources :

Example 1 with AgentSession

use of org.wso2.carbon.databridge.core.Utils.AgentSession in project carbon-apimgt by wso2.

the class DASThriftTestServer method start.

public void start(int receiverPort) throws DataBridgeException {
    DataPublisherTestUtil.setKeyStoreParams();
    streamDefinitionStore = getStreamDefinitionStore();
    numberOfEventsReceived = new AtomicInteger(0);
    DataBridge databridge = new DataBridge(new AuthenticationHandler() {

        public boolean authenticate(String userName, String password) {
            // allays authenticate to true
            return true;
        }

        public void initContext(AgentSession agentSession) {
        // To change body of implemented methods use File | Settings |
        // File Templates.
        }

        public void destroyContext(AgentSession agentSession) {
        }
    }, streamDefinitionStore, DataPublisherTestUtil.getDataBridgeConfigPath());
    thriftDataReceiver = new ThriftDataReceiver(receiverPort, databridge);
    databridge.subscribe(new AgentCallback() {

        int totalSize = 0;

        @Override
        public void definedStream(StreamDefinition streamDefinition) {
            log.info("StreamDefinition " + streamDefinition);
        }

        @Override
        public void removeStream(StreamDefinition streamDefinition) {
            log.info("StreamDefinition remove " + streamDefinition);
        }

        /**
         * Retrving and handling all the events to DAS event receiver
         * @param eventList list of event it received
         * @param credentials client credentials
         */
        public void receive(List<Event> eventList, Credentials credentials) {
            for (Event event : eventList) {
                String streamKey = event.getStreamId();
                if (!dataTables.containsKey(streamKey)) {
                    dataTables.put(streamKey, new ArrayList<Event>());
                }
                dataTables.get(streamKey).add(event);
                log.info("===  " + event.toString());
            }
            numberOfEventsReceived.addAndGet(eventList.size());
            log.info("Received events : " + numberOfEventsReceived);
        }
    });
    String address = "localhost";
    log.info("DAS Test Thrift Server starting on " + address);
    thriftDataReceiver.start(address);
    log.info("DAS Test Thrift Server Started");
}
Also used : AgentSession(org.wso2.carbon.databridge.core.Utils.AgentSession) StreamDefinition(org.wso2.carbon.databridge.commons.StreamDefinition) ArrayList(java.util.ArrayList) AgentCallback(org.wso2.carbon.databridge.core.AgentCallback) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ThriftDataReceiver(org.wso2.carbon.databridge.receiver.thrift.ThriftDataReceiver) Event(org.wso2.carbon.databridge.commons.Event) AuthenticationHandler(org.wso2.carbon.databridge.core.internal.authentication.AuthenticationHandler) Credentials(org.wso2.carbon.databridge.commons.Credentials) DataBridge(org.wso2.carbon.databridge.core.DataBridge)

Aggregations

ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Credentials (org.wso2.carbon.databridge.commons.Credentials)1 Event (org.wso2.carbon.databridge.commons.Event)1 StreamDefinition (org.wso2.carbon.databridge.commons.StreamDefinition)1 AgentCallback (org.wso2.carbon.databridge.core.AgentCallback)1 DataBridge (org.wso2.carbon.databridge.core.DataBridge)1 AgentSession (org.wso2.carbon.databridge.core.Utils.AgentSession)1 AuthenticationHandler (org.wso2.carbon.databridge.core.internal.authentication.AuthenticationHandler)1 ThriftDataReceiver (org.wso2.carbon.databridge.receiver.thrift.ThriftDataReceiver)1