Search in sources :

Example 26 with IRemoteServiceContainerAdapter

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

the class SSLRemoteServiceTest 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 27 with IRemoteServiceContainerAdapter

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

the class SSLRemoteServiceTrackerTest method testRemoteServiceTracker.

public void testRemoteServiceTracker() 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);
    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) Hashtable(java.util.Hashtable) IConcatService(org.eclipse.ecf.tests.remoteservice.IConcatService) IRemoteServiceContainerAdapter(org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter) RemoteServiceTracker(org.eclipse.ecf.remoteservice.util.tracker.RemoteServiceTracker) IRemoteService(org.eclipse.ecf.remoteservice.IRemoteService)

Example 28 with IRemoteServiceContainerAdapter

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

the class SSLRemoteServiceTrackerTest 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 29 with IRemoteServiceContainerAdapter

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

the class GenericServerTest method testGetRemoteServiceContainerAdapter.

public void testGetRemoteServiceContainerAdapter() throws Exception {
    IContainer container = server.getFirstServerContainer();
    assertNotNull(container);
    IRemoteServiceContainerAdapter adapter = (IRemoteServiceContainerAdapter) container.getAdapter(IRemoteServiceContainerAdapter.class);
    assertNotNull(adapter);
}
Also used : IRemoteServiceContainerAdapter(org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter) IContainer(org.eclipse.ecf.core.IContainer)

Example 30 with IRemoteServiceContainerAdapter

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

the class AbstractConsumerContainerSelector method createContainer.

/**
 * @param containerTypeDescription containerTypeDescription
 * @param containerTypeDescriptionName containerTypeDescriptionName
 * @param properties properties
 * @return IRemoteServiceContainer created container.  Should not be <code>null</code>
 * @throws SelectContainerException thrown if container cannot be created or configured
 * @since 2.0
 */
protected IRemoteServiceContainer createContainer(ContainerTypeDescription containerTypeDescription, String containerTypeDescriptionName, Map properties) throws SelectContainerException {
    try {
        IContainer container = (properties == null) ? getContainerFactory().createContainer(containerTypeDescriptionName) : getContainerFactory().createContainer(containerTypeDescriptionName, properties);
        IRemoteServiceContainerAdapter adapter = (IRemoteServiceContainerAdapter) container.getAdapter(IRemoteServiceContainerAdapter.class);
        if (adapter == null)
            throw new SelectContainerException("Container config id=" + containerTypeDescriptionName + " does not implement IRemoteServiceContainerAdapter", null, // $NON-NLS-1$ //$NON-NLS-2$
            containerTypeDescription);
        return new RemoteServiceContainer(container);
    } catch (ContainerCreateException e) {
        String message = // $NON-NLS-1$
        "Cannot create container config id=" + containerTypeDescriptionName;
        logException(message, e);
        throw new SelectContainerException(message, e, containerTypeDescription);
    }
}
Also used : RemoteServiceContainer(org.eclipse.ecf.remoteservice.RemoteServiceContainer) IRemoteServiceContainer(org.eclipse.ecf.remoteservice.IRemoteServiceContainer) IRemoteServiceContainerAdapter(org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter) ContainerCreateException(org.eclipse.ecf.core.ContainerCreateException) IContainer(org.eclipse.ecf.core.IContainer)

Aggregations

IRemoteServiceContainerAdapter (org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter)35 IRemoteServiceReference (org.eclipse.ecf.remoteservice.IRemoteServiceReference)16 IConcatService (org.eclipse.ecf.tests.remoteservice.IConcatService)14 IRemoteService (org.eclipse.ecf.remoteservice.IRemoteService)9 IContainer (org.eclipse.ecf.core.IContainer)7 ID (org.eclipse.ecf.core.identity.ID)7 Dictionary (java.util.Dictionary)6 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 IRemoteServiceContainer (org.eclipse.ecf.remoteservice.IRemoteServiceContainer)5 RemoteServiceContainer (org.eclipse.ecf.remoteservice.RemoteServiceContainer)5 Hashtable (java.util.Hashtable)4 Properties (java.util.Properties)4 IRemoteServiceRegistration (org.eclipse.ecf.remoteservice.IRemoteServiceRegistration)4 RemoteServiceTracker (org.eclipse.ecf.remoteservice.util.tracker.RemoteServiceTracker)4 ArrayList (java.util.ArrayList)3 ContainerCreateException (org.eclipse.ecf.core.ContainerCreateException)3 IRemoteServiceID (org.eclipse.ecf.remoteservice.IRemoteServiceID)3