Search in sources :

Example 21 with IRemoteServiceReference

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

the class AbstractRemoteServiceTest method testGetServiceReferencesWithFilterFail.

public void testGetServiceReferencesWithFilterFail() throws Exception {
    final IRemoteServiceContainerAdapter[] adapters = getRemoteServiceAdapters();
    final Properties props = new Properties();
    props.put("foo", "bar");
    props.put("foo1", "bar");
    registerService(adapters[0], IConcatService.class.getName(), createService(), customizeProperties(props), SLEEPTIME);
    // Create dictionary that is *not* the same as props, so the filter
    // should miss
    final Properties missProps = new Properties();
    missProps.put("bar", "foo");
    final String missFilter = getFilterFromServiceProperties(missProps);
    final IRemoteServiceReference[] refs = getRemoteServiceReferences(adapters[1], getConnectTargetID(), getIDFilter(), IConcatService.class.getName(), missFilter);
    assertTrue(refs == null);
    Thread.sleep(SLEEPTIME);
}
Also used : IRemoteServiceReference(org.eclipse.ecf.remoteservice.IRemoteServiceReference) IRemoteServiceContainerAdapter(org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter) Properties(java.util.Properties)

Example 22 with IRemoteServiceReference

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

the class RestRemoteServiceAdapterTest method testGetRemoteService.

public void testGetRemoteService() {
    IRemoteServiceRegistration registration = createRestRegistration("resourcePath");
    IRemoteServiceReference reference = registration.getReference();
    assertNotNull(reference);
    IRemoteService remoteService = getRemoteServiceClientContainerAdapter().getRemoteService(reference);
    assertNotNull(remoteService);
}
Also used : IRemoteServiceReference(org.eclipse.ecf.remoteservice.IRemoteServiceReference) IRemoteServiceRegistration(org.eclipse.ecf.remoteservice.IRemoteServiceRegistration) IRemoteService(org.eclipse.ecf.remoteservice.IRemoteService)

Example 23 with IRemoteServiceReference

use of org.eclipse.ecf.remoteservice.IRemoteServiceReference 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 24 with IRemoteServiceReference

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

the class RemoteServiceTest 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 25 with IRemoteServiceReference

use of org.eclipse.ecf.remoteservice.IRemoteServiceReference 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

IRemoteServiceReference (org.eclipse.ecf.remoteservice.IRemoteServiceReference)28 IRemoteServiceContainerAdapter (org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter)16 IConcatService (org.eclipse.ecf.tests.remoteservice.IConcatService)10 IRemoteService (org.eclipse.ecf.remoteservice.IRemoteService)8 IRemoteServiceRegistration (org.eclipse.ecf.remoteservice.IRemoteServiceRegistration)8 IRemoteServiceListener (org.eclipse.ecf.remoteservice.IRemoteServiceListener)6 IRemoteServiceEvent (org.eclipse.ecf.remoteservice.events.IRemoteServiceEvent)6 IRemoteServiceRegisteredEvent (org.eclipse.ecf.remoteservice.events.IRemoteServiceRegisteredEvent)6 IFuture (org.eclipse.equinox.concurrent.future.IFuture)6 ID (org.eclipse.ecf.core.identity.ID)4 IRemoteServiceID (org.eclipse.ecf.remoteservice.IRemoteServiceID)3 Dictionary (java.util.Dictionary)2 Hashtable (java.util.Hashtable)2 Properties (java.util.Properties)2 ContainerCreateException (org.eclipse.ecf.core.ContainerCreateException)2 IContainer (org.eclipse.ecf.core.IContainer)2 IRemoteServiceContainer (org.eclipse.ecf.remoteservice.IRemoteServiceContainer)2 IRemoteServiceProxy (org.eclipse.ecf.remoteservice.IRemoteServiceProxy)2 RemoteServiceContainer (org.eclipse.ecf.remoteservice.RemoteServiceContainer)2 RemoteServiceTracker (org.eclipse.ecf.remoteservice.util.tracker.RemoteServiceTracker)2