Search in sources :

Example 26 with IRemoteServiceReference

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

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

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

the class ReflectiveRemoteServiceHandler method execute.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.
	 * commands .ExecutionEvent)
	 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    final String clazz = event.getParameter(// $NON-NLS-1$
    "org.eclipse.ecf.remoteservices.ui.commands.reflectiveMethodDialogParameter");
    final IRemoteServiceContainerAdapter adapter = RemoteServiceHandlerUtil.getActiveIRemoteServiceContainerAdapterChecked(event);
    if (adapter == null) {
        // $NON-NLS-1$
        MessageDialog.openError(// $NON-NLS-1$
        null, // $NON-NLS-1$
        "Handler invocation failed", // $NON-NLS-1$
        "No container found");
        return null;
    }
    final IRemoteServiceReference[] references = RemoteServiceHandlerUtil.getActiveIRemoteServiceReferencesChecked(event);
    if (references == null || references.length == 0) {
        // $NON-NLS-1$
        MessageDialog.openError(// $NON-NLS-1$
        null, // $NON-NLS-1$
        "Handler invocation failed", // $NON-NLS-1$
        "No remote service reference found");
        return null;
    }
    final IRemoteService remoteService = adapter.getRemoteService(references[0]);
    if (remoteService == null) {
        // $NON-NLS-1$
        MessageDialog.openError(// $NON-NLS-1$
        null, // $NON-NLS-1$
        "Handler invocation failed", // $NON-NLS-1$
        "No remote service found");
        return null;
    }
    try {
        executeMethodInvocationDialog(Class.forName(clazz), remoteService);
    } catch (ClassNotFoundException e) {
        // $NON-NLS-1$
        MessageDialog.openError(// $NON-NLS-1$
        null, // $NON-NLS-1$
        "Handler invocation failed", e.getLocalizedMessage());
        throw new ExecutionException(e.getMessage(), e);
    }
    return null;
}
Also used : IRemoteServiceReference(org.eclipse.ecf.remoteservice.IRemoteServiceReference) IRemoteServiceContainerAdapter(org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter) IRemoteService(org.eclipse.ecf.remoteservice.IRemoteService) ExecutionException(org.eclipse.core.commands.ExecutionException)

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