Search in sources :

Example 1 with IFuture

use of org.eclipse.equinox.concurrent.future.IFuture in project ecf by eclipse.

the class RpcRemoteServiceTest method testAsynCall.

public void testAsynCall() {
    IRemoteService rpcClientService = getRemoteServiceClientContainerAdapter(container).getRemoteService(registrationCalc.getReference());
    IFuture future = rpcClientService.callAsync(getCalcPlusCall());
    try {
        Object response = future.get();
        assertTrue(response instanceof Integer);
    } catch (OperationCanceledException e) {
        fail(e.getMessage());
    } catch (InterruptedException e) {
        fail(e.getMessage());
    }
}
Also used : OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IRemoteService(org.eclipse.ecf.remoteservice.IRemoteService) IFuture(org.eclipse.equinox.concurrent.future.IFuture)

Example 2 with IFuture

use of org.eclipse.equinox.concurrent.future.IFuture in project ecf by eclipse.

the class RemoteServiceProxyTest method testServiceListener.

public void testServiceListener() throws Exception {
    final IRemoteServiceContainerAdapter[] adapters = getRemoteServiceAdapters();
    done = false;
    final Object lock = new Object();
    adapters[1].addRemoteServiceListener(new IRemoteServiceListener() {

        public void handleServiceEvent(IRemoteServiceEvent event) {
            if (event instanceof IRemoteServiceRegisteredEvent) {
                IRemoteServiceRegisteredEvent e = (IRemoteServiceRegisteredEvent) event;
                IRemoteServiceReference ref = e.getReference();
                remoteService = adapters[1].getRemoteService(ref);
                assertNotNull(remoteService);
                synchronized (lock) {
                    done = true;
                    lock.notify();
                }
            }
        }
    });
    // Now register service on server (adapters[0]).  This should result in notification on client (adapters[1])
    // in above handleServiceEvent
    adapters[0].registerRemoteService(new String[] { IConcatService.class.getName() }, createService(), customizeProperties(null));
    // wait until block above called asynchronously
    int count = 0;
    synchronized (lock) {
        while (!done && count++ < 10) {
            try {
                lock.wait(1000);
            } catch (InterruptedException e) {
                fail();
            }
        }
    }
    assertTrue(done);
    if (remoteService == null)
        return;
    // We've got the remote service, so we're good to go
    assertTrue(remoteService != null);
    traceCallStart("callAsynchResult");
    final IFuture result = remoteService.callAsync(createRemoteConcat("ECF AsynchResults ", "are cool"));
    traceCallEnd("callAsynch");
    assertNotNull(result);
    Thread.sleep(SLEEPTIME);
}
Also used : IRemoteServiceReference(org.eclipse.ecf.remoteservice.IRemoteServiceReference) IConcatService(org.eclipse.ecf.tests.remoteservice.IConcatService) IRemoteServiceContainerAdapter(org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter) IRemoteServiceListener(org.eclipse.ecf.remoteservice.IRemoteServiceListener) IRemoteServiceEvent(org.eclipse.ecf.remoteservice.events.IRemoteServiceEvent) IFuture(org.eclipse.equinox.concurrent.future.IFuture) IRemoteServiceRegisteredEvent(org.eclipse.ecf.remoteservice.events.IRemoteServiceRegisteredEvent)

Example 3 with IFuture

use of org.eclipse.equinox.concurrent.future.IFuture in project ecf by eclipse.

the class RemoteServiceTrackerTest method testServiceListener.

public void testServiceListener() throws Exception {
    final IRemoteServiceContainerAdapter[] adapters = getRemoteServiceAdapters();
    done = false;
    final Object lock = new Object();
    adapters[1].addRemoteServiceListener(new IRemoteServiceListener() {

        public void handleServiceEvent(IRemoteServiceEvent event) {
            if (event instanceof IRemoteServiceRegisteredEvent) {
                IRemoteServiceRegisteredEvent e = (IRemoteServiceRegisteredEvent) event;
                IRemoteServiceReference ref = e.getReference();
                remoteService = adapters[1].getRemoteService(ref);
                assertNotNull(remoteService);
                synchronized (lock) {
                    done = true;
                    lock.notify();
                }
            }
        }
    });
    // Now register service on server (adapters[0]).  This should result in notification on client (adapters[1])
    // in above handleServiceEvent
    adapters[0].registerRemoteService(new String[] { IConcatService.class.getName() }, createService(), customizeProperties(null));
    // wait until block above called asynchronously
    int count = 0;
    synchronized (lock) {
        while (!done && count++ < 10) {
            try {
                lock.wait(1000);
            } catch (InterruptedException e) {
                fail();
            }
        }
    }
    assertTrue(done);
    if (remoteService == null)
        return;
    // We've got the remote service, so we're good to go
    assertTrue(remoteService != null);
    traceCallStart("callAsynchResult");
    final IFuture result = remoteService.callAsync(createRemoteConcat("ECF AsynchResults ", "are cool"));
    traceCallEnd("callAsynch");
    assertNotNull(result);
    Thread.sleep(SLEEPTIME);
}
Also used : IRemoteServiceReference(org.eclipse.ecf.remoteservice.IRemoteServiceReference) IConcatService(org.eclipse.ecf.tests.remoteservice.IConcatService) IRemoteServiceContainerAdapter(org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter) IRemoteServiceListener(org.eclipse.ecf.remoteservice.IRemoteServiceListener) IRemoteServiceEvent(org.eclipse.ecf.remoteservice.events.IRemoteServiceEvent) IFuture(org.eclipse.equinox.concurrent.future.IFuture) IRemoteServiceRegisteredEvent(org.eclipse.ecf.remoteservice.events.IRemoteServiceRegisteredEvent)

Example 4 with IFuture

use of org.eclipse.equinox.concurrent.future.IFuture in project ecf by eclipse.

the class SimpleTest method testSimpleClientAndServerWithFuture.

public void testSimpleClientAndServerWithFuture() throws Exception {
    IRemoteService remoteService = client.getRemoteService();
    assertNotNull(remoteService);
    // Use callSync
    IFuture future = remoteService.callAsync(getRemoteConcatCall(TEST_STRING_2, TEST_STRING_1));
    assertNotNull(future);
    String result = (String) future.get();
    assertTrue(result.equals(TEST_STRING_2 + TEST_STRING_1));
}
Also used : IRemoteService(org.eclipse.ecf.remoteservice.IRemoteService) IFuture(org.eclipse.equinox.concurrent.future.IFuture)

Example 5 with IFuture

use of org.eclipse.equinox.concurrent.future.IFuture in project ecf by eclipse.

the class AbstractRemoteServiceTest method testAsyncResult.

public void testAsyncResult() throws Exception {
    final IRemoteService service = registerAndGetRemoteService();
    if (service == null)
        return;
    traceCallStart("callAsynchResult");
    final IFuture result = service.callAsync(createRemoteConcat("ECF AsynchResults ", "are cool"));
    traceCallEnd("callAsynchResult", result);
    assertNotNull(result);
    Thread.sleep(SLEEPTIME);
}
Also used : IRemoteService(org.eclipse.ecf.remoteservice.IRemoteService) IFuture(org.eclipse.equinox.concurrent.future.IFuture)

Aggregations

IFuture (org.eclipse.equinox.concurrent.future.IFuture)21 IRemoteService (org.eclipse.ecf.remoteservice.IRemoteService)10 IRemoteServiceContainerAdapter (org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter)6 IRemoteServiceListener (org.eclipse.ecf.remoteservice.IRemoteServiceListener)6 IRemoteServiceReference (org.eclipse.ecf.remoteservice.IRemoteServiceReference)6 IRemoteServiceEvent (org.eclipse.ecf.remoteservice.events.IRemoteServiceEvent)6 IRemoteServiceRegisteredEvent (org.eclipse.ecf.remoteservice.events.IRemoteServiceRegisteredEvent)6 IConcatService (org.eclipse.ecf.tests.remoteservice.IConcatService)6 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)4 IServiceInfo (org.eclipse.ecf.discovery.IServiceInfo)3 ExecutionException (java.util.concurrent.ExecutionException)2 IHelloAsync (org.eclipse.ecf.examples.remoteservices.hello.IHelloAsync)2 IAsyncCallback (org.eclipse.ecf.remoteservice.IAsyncCallback)2 ServiceReference (org.osgi.framework.ServiceReference)2 IServiceTypeID (org.eclipse.ecf.discovery.identity.IServiceTypeID)1 HelloMessage (org.eclipse.ecf.examples.remoteservices.hello.HelloMessage)1 IHello (org.eclipse.ecf.examples.remoteservices.hello.IHello)1 IRemoteServiceProxy (org.eclipse.ecf.remoteservice.IRemoteServiceProxy)1 JSONObject (org.json.JSONObject)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1