Search in sources :

Example 1 with IDataProcessorAsync

use of org.eclipse.ecf.examples.loadbalancing.IDataProcessorAsync in project ecf by eclipse.

the class DataProcessorClientComponent method bind.

public void bind(IDataProcessor dataProcessor) {
    System.out.println("Got data processor on client");
    final String data = "Here's some data from a client";
    // Use it
    System.out.println("Invoking data processor");
    String result = dataProcessor.processData(data);
    System.out.println("Sync result=" + result);
    System.out.println();
    // See if we've got an async interface and if so, use it
    if (dataProcessor instanceof IDataProcessorAsync) {
        IDataProcessorAsync dpAsync = (IDataProcessorAsync) dataProcessor;
        System.out.println("Got async data processor on client");
        IAsyncCallback<String> callback = new IAsyncCallback<String>() {

            public void onSuccess(String result) {
                System.out.println("Async result=" + result);
            }

            public void onFailure(Throwable exception) {
                System.out.println("Async invoke failed with exception");
                if (exception != null)
                    exception.printStackTrace();
            }
        };
        // Now invoke async
        dpAsync.processDataAsync(data, callback);
    }
}
Also used : IAsyncCallback(org.eclipse.ecf.remoteservice.IAsyncCallback) IDataProcessorAsync(org.eclipse.ecf.examples.loadbalancing.IDataProcessorAsync)

Aggregations

IDataProcessorAsync (org.eclipse.ecf.examples.loadbalancing.IDataProcessorAsync)1 IAsyncCallback (org.eclipse.ecf.remoteservice.IAsyncCallback)1