Search in sources :

Example 1 with IRemoteServiceProxy

use of org.eclipse.ecf.remoteservice.IRemoteServiceProxy in project ecf by eclipse.

the class AbstractRemoteServiceTest method testGetProxy.

public void testGetProxy() throws Exception {
    final IRemoteService service = registerAndGetRemoteService();
    assertNotNull(service);
    Object proxy = service.getProxy();
    assertTrue(proxy instanceof IRemoteServiceProxy);
    Thread.sleep(SLEEPTIME);
}
Also used : IRemoteServiceProxy(org.eclipse.ecf.remoteservice.IRemoteServiceProxy) IRemoteService(org.eclipse.ecf.remoteservice.IRemoteService)

Example 2 with IRemoteServiceProxy

use of org.eclipse.ecf.remoteservice.IRemoteServiceProxy in project ecf by eclipse.

the class HelloClientComponent method bindHello.

public void bindHello(IHello proxy) {
    // First print out on console that we got a proxy instance
    System.out.println("Got proxy IHello=" + proxy);
    // Call proxy synchronously.  Note that this call may block or fail due to
    // synchronous communication with remote service
    System.out.println("STARTING remote call via proxy...");
    proxy.hello(CONSUMER_NAME + " via proxy");
    System.out.println("COMPLETED remote call via proxy");
    System.out.println();
    // this asynchronous interface to invoke methods asynchronously
    if (proxy instanceof IHelloAsync) {
        IHelloAsync helloA = (IHelloAsync) proxy;
        // Create callback for use in IHelloAsync
        IAsyncCallback callback = new IAsyncCallback<String>() {

            public void onSuccess(String result) {
                System.out.println("COMPLETED remote call with callback SUCCESS with result=" + result);
                System.out.println();
            }

            public void onFailure(Throwable t) {
                System.out.println("COMPLETED remote call with callback FAILED with exception=" + t);
                System.out.println();
            }
        };
        // Call asynchronously with callback
        System.out.println("STARTING async remote call via callback...");
        helloA.helloAsync(CONSUMER_NAME + " via async proxy with listener", callback);
        System.out.println("LOCAL async invocation complete");
        System.out.println();
        // Call asynchronously with future
        System.out.println("STARTING async remote call via future...");
        Future<String> future = helloA.helloAsync(CONSUMER_NAME + " via async proxy with future");
        System.out.println("LOCAL async future invocation complete");
        System.out.println();
        try {
            while (!future.isDone()) {
                // do some other stuff
                System.out.println("LOCAL future not yet done...so we're doing other stuff while waiting for future to be done");
                Thread.sleep(200);
            }
            // Now it's done, so this will not block
            String result = future.get();
            System.out.println("COMPLETED remote call with future SUCCEEDED with result=" + result);
            System.out.println();
        } catch (OperationCanceledException e) {
            System.out.println("COMPLETED remote call with callback CANCELLED with exception=" + e);
            System.out.println();
            e.printStackTrace();
        } catch (InterruptedException e) {
            System.out.println("COMPLETED remote call with callback INTERRUPTED with exception=" + e);
            System.out.println();
            e.printStackTrace();
        } catch (ExecutionException e) {
            System.out.println("COMPLETED remote call with callback INTERRUPTED with exception=" + e);
            System.out.println();
            e.printStackTrace();
        }
    }
    // It's also possible to get the remote service directly from the proxy
    IRemoteService remoteService = ((IRemoteServiceProxy) proxy).getRemoteService();
    Assert.isNotNull(remoteService);
    // In this case, we will make an non-blocking call and immediately get a 'future'...which is
    // a placeholder for a result of the remote computation.  This will not block.
    System.out.println("STARTING async remote call via future...");
    IFuture future = RemoteServiceHelper.futureExec(remoteService, "hello", new Object[] { CONSUMER_NAME + " future" });
    System.out.println("LOCAL async future invocation complete");
    System.out.println();
    // Client can execute arbitrary code here...
    try {
        // This blocks until communication and computation have completed successfully
        while (!future.isDone()) {
            // do some other stuff
            System.out.println("LOCAL future not yet done...so we're doing other stuff while waiting for future to be done");
            Thread.sleep(200);
        }
        // Now it's done, so this will not block
        Object result = future.get();
        System.out.println("COMPLETED remote call with future SUCCEEDED with result=" + result);
        System.out.println();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : IHelloAsync(org.eclipse.ecf.examples.remoteservices.hello.IHelloAsync) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IFuture(org.eclipse.equinox.concurrent.future.IFuture) ExecutionException(java.util.concurrent.ExecutionException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IRemoteServiceProxy(org.eclipse.ecf.remoteservice.IRemoteServiceProxy) IAsyncCallback(org.eclipse.ecf.remoteservice.IAsyncCallback) ExecutionException(java.util.concurrent.ExecutionException) IRemoteService(org.eclipse.ecf.remoteservice.IRemoteService)

Example 3 with IRemoteServiceProxy

use of org.eclipse.ecf.remoteservice.IRemoteServiceProxy in project ecf by eclipse.

the class AbstractRemoteServiceTest method testGetProxyNoRemoteServiceProxy.

public void testGetProxyNoRemoteServiceProxy() throws Exception {
    final IRemoteServiceContainerAdapter[] adapters = getRemoteServiceAdapters();
    Properties props = new Properties();
    props.put(Constants.SERVICE_PREVENT_RSPROXY, "true");
    final IRemoteService service = registerAndGetRemoteService(adapters[0], adapters[1], getClient(0).getConnectedID(), getIDFilter(), IConcatService.class.getName(), customizeProperties(props), SLEEPTIME);
    assertNotNull(service);
    Object proxy = service.getProxy();
    assertTrue(!(proxy instanceof IRemoteServiceProxy));
    Thread.sleep(SLEEPTIME);
}
Also used : IRemoteServiceContainerAdapter(org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter) IRemoteServiceProxy(org.eclipse.ecf.remoteservice.IRemoteServiceProxy) Properties(java.util.Properties) IRemoteService(org.eclipse.ecf.remoteservice.IRemoteService)

Example 4 with IRemoteServiceProxy

use of org.eclipse.ecf.remoteservice.IRemoteServiceProxy in project ecf by eclipse.

the class RemoteServiceProxyTest method testRemoteServiceProxy.

public void testRemoteServiceProxy() throws Exception {
    final IRemoteServiceContainerAdapter[] adapters = getRemoteServiceAdapters();
    // client [0]/adapter[0] is the service 'server'
    // client [1]/adapter[1] is the service target (client)
    final Dictionary props = new Hashtable();
    // Register
    adapters[0].registerRemoteService(new String[] { IConcatService.class.getName() }, createService(), props);
    // Give some time for propagation
    sleep(3000);
    final RemoteServiceTracker st = new RemoteServiceTracker(adapters[1], null, IConcatService.class.getName(), null);
    assertNotNull(st);
    st.open();
    IRemoteService rs = st.getRemoteService();
    final IConcatService concatService = (IConcatService) rs.getProxy();
    assertNotNull(concatService);
    // test for proxy implementing IRemoteServiceProxy
    if (concatService instanceof IRemoteServiceProxy) {
        IRemoteService remoteService = ((IRemoteServiceProxy) concatService).getRemoteService();
        assertNotNull(remoteService);
        IRemoteServiceReference remoteServiceReference = ((IRemoteServiceProxy) concatService).getRemoteServiceReference();
        assertNotNull(remoteServiceReference);
        System.out.println("remote service reference found from proxy=" + remoteServiceReference);
        System.out.println("remoteserviceproxy call start");
        Object result = RemoteServiceHelper.syncExec(remoteService, "concat", new Object[] { "IRemoteServiceProxy ", "is very cool" }, 20000);
        System.out.println("remoteserviceproxy call end. result=" + result);
    } else {
        System.out.println("proxy call start");
        final String result = concatService.concat("OSGi ", "is cool");
        System.out.println("proxy call end. result=" + result);
    }
    sleep(3000);
    st.close();
    sleep(3000);
}
Also used : Dictionary(java.util.Dictionary) IRemoteServiceReference(org.eclipse.ecf.remoteservice.IRemoteServiceReference) Hashtable(java.util.Hashtable) IConcatService(org.eclipse.ecf.tests.remoteservice.IConcatService) IRemoteServiceContainerAdapter(org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter) IRemoteServiceProxy(org.eclipse.ecf.remoteservice.IRemoteServiceProxy) RemoteServiceTracker(org.eclipse.ecf.remoteservice.util.tracker.RemoteServiceTracker) IRemoteService(org.eclipse.ecf.remoteservice.IRemoteService)

Example 5 with IRemoteServiceProxy

use of org.eclipse.ecf.remoteservice.IRemoteServiceProxy in project ecf by eclipse.

the class SSLRemoteServiceProxyTest method testRemoteServiceProxy.

public void testRemoteServiceProxy() throws Exception {
    final IRemoteServiceContainerAdapter[] adapters = getRemoteServiceAdapters();
    // client [0]/adapter[0] is the service 'server'
    // client [1]/adapter[1] is the service target (client)
    final Dictionary props = new Hashtable();
    // Register
    adapters[0].registerRemoteService(new String[] { IConcatService.class.getName() }, createService(), props);
    // Give some time for propagation
    sleep(3000);
    final RemoteServiceTracker st = new RemoteServiceTracker(adapters[1], null, IConcatService.class.getName(), null);
    assertNotNull(st);
    st.open();
    IRemoteService rs = st.getRemoteService();
    final IConcatService concatService = (IConcatService) rs.getProxy();
    assertNotNull(concatService);
    // test for proxy implementing IRemoteServiceProxy
    if (concatService instanceof IRemoteServiceProxy) {
        IRemoteService remoteService = ((IRemoteServiceProxy) concatService).getRemoteService();
        assertNotNull(remoteService);
        IRemoteServiceReference remoteServiceReference = ((IRemoteServiceProxy) concatService).getRemoteServiceReference();
        assertNotNull(remoteServiceReference);
        System.out.println("remote service reference found from proxy=" + remoteServiceReference);
        System.out.println("remoteserviceproxy call start");
        Object result = RemoteServiceHelper.syncExec(remoteService, "concat", new Object[] { "IRemoteServiceProxy ", "is very cool" }, 20000);
        System.out.println("remoteserviceproxy call end. result=" + result);
    } else {
        System.out.println("proxy call start");
        final String result = concatService.concat("OSGi ", "is cool");
        System.out.println("proxy call end. result=" + result);
    }
    sleep(3000);
    st.close();
    sleep(3000);
}
Also used : Dictionary(java.util.Dictionary) IRemoteServiceReference(org.eclipse.ecf.remoteservice.IRemoteServiceReference) Hashtable(java.util.Hashtable) IConcatService(org.eclipse.ecf.tests.remoteservice.IConcatService) IRemoteServiceContainerAdapter(org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter) IRemoteServiceProxy(org.eclipse.ecf.remoteservice.IRemoteServiceProxy) RemoteServiceTracker(org.eclipse.ecf.remoteservice.util.tracker.RemoteServiceTracker) IRemoteService(org.eclipse.ecf.remoteservice.IRemoteService)

Aggregations

IRemoteService (org.eclipse.ecf.remoteservice.IRemoteService)5 IRemoteServiceProxy (org.eclipse.ecf.remoteservice.IRemoteServiceProxy)5 IRemoteServiceContainerAdapter (org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter)3 Dictionary (java.util.Dictionary)2 Hashtable (java.util.Hashtable)2 IRemoteServiceReference (org.eclipse.ecf.remoteservice.IRemoteServiceReference)2 RemoteServiceTracker (org.eclipse.ecf.remoteservice.util.tracker.RemoteServiceTracker)2 IConcatService (org.eclipse.ecf.tests.remoteservice.IConcatService)2 Properties (java.util.Properties)1 ExecutionException (java.util.concurrent.ExecutionException)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 IHelloAsync (org.eclipse.ecf.examples.remoteservices.hello.IHelloAsync)1 IAsyncCallback (org.eclipse.ecf.remoteservice.IAsyncCallback)1 IFuture (org.eclipse.equinox.concurrent.future.IFuture)1