Search in sources :

Example 61 with IRemoteService

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

the class AbstractRemoteServiceAccessTest method testCallAsync.

public void testCallAsync() throws Exception {
    startTest("testCallAsync");
    createServiceTrackerAndRegister();
    // Client - Get service references from service tracker
    final ServiceReference[] remoteReferences = st.getServiceReferences();
    assertReferencesValid(remoteReferences);
    final Object o = remoteReferences[0].getProperty(SERVICE_IMPORTED);
    assertNotNull(o);
    assertTrue(o instanceof IRemoteService);
    final IRemoteService rs = (IRemoteService) o;
    // Call asynchronously
    rs.callAsync(createRemoteCall(), new IRemoteCallListener() {

        public void handleEvent(final IRemoteCallEvent event) {
            if (event instanceof IRemoteCallCompleteEvent) {
                final Object result = ((IRemoteCallCompleteEvent) event).getResponse();
                Trace.trace(Activator.PLUGIN_ID, "callSync.doStuff1 result=" + result);
                assertStringResultValid(result, TestServiceInterface1.TEST_SERVICE_STRING1);
                syncNotify();
            }
        }
    });
    syncWaitForNotify(REGISTER_WAIT);
    endTest("testCallAsync");
}
Also used : IRemoteCallEvent(org.eclipse.ecf.remoteservice.events.IRemoteCallEvent) IRemoteService(org.eclipse.ecf.remoteservice.IRemoteService) IRemoteCallListener(org.eclipse.ecf.remoteservice.IRemoteCallListener) IRemoteCallCompleteEvent(org.eclipse.ecf.remoteservice.events.IRemoteCallCompleteEvent) ServiceReference(org.osgi.framework.ServiceReference)

Example 62 with IRemoteService

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

the class AbstractRemoteServiceAccessTest method testCallSyncFromProxy.

public void testCallSyncFromProxy() throws Exception {
    startTest("testCallSyncFromProxy");
    createServiceTrackerAndRegister();
    // Client - Get service references from service tracker
    final ServiceReference[] remoteReferences = st.getServiceReferences();
    assertReferencesValidAndFirstHasCorrectType(remoteReferences, classname);
    // Get proxy
    final TestServiceInterface1 proxy = (TestServiceInterface1) getContext().getService(remoteReferences[0]);
    assertProxyValid(proxy);
    // Get IRemoteService from proxy
    final IRemoteService remoteService = getRemoteServiceFromProxy(proxy);
    // Call remote service synchronously
    final Object result = remoteService.callSync(createRemoteCall());
    Trace.trace(Activator.PLUGIN_ID, "proxy.doStuff1 result=" + result);
    assertStringResultValid(result, TestServiceInterface1.TEST_SERVICE_STRING1);
    endTest("testCallSyncFromProxy");
}
Also used : IRemoteService(org.eclipse.ecf.remoteservice.IRemoteService) ServiceReference(org.osgi.framework.ServiceReference)

Example 63 with IRemoteService

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

Example 64 with IRemoteService

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

the class RemoteServiceAdmin method createAndRegisterProxy.

private ImportEndpoint createAndRegisterProxy(final EndpointDescription endpointDescription, final IRemoteServiceContainer rsContainer, final IRemoteServiceReference selectedRsReference) throws Exception {
    final BundleContext proxyServiceFactoryContext = getProxyServiceFactoryContext(endpointDescription);
    if (proxyServiceFactoryContext == null)
        throw new NullPointerException(// $NON-NLS-1$
        "getProxyServiceFactoryContext returned null.  Cannot register proxy service factory");
    final IRemoteServiceContainerAdapter containerAdapter = rsContainer.getContainerAdapter();
    ID rsContainerID = rsContainer.getContainer().getID();
    // First get IRemoteService for selectedRsReference
    final IRemoteService rs = containerAdapter.getRemoteService(selectedRsReference);
    if (rs == null)
        throw new NullPointerException(// $NON-NLS-1$
        "getRemoteService returned null for selectedRsReference=" + selectedRsReference + // $NON-NLS-1$
        ",rsContainerID=" + rsContainerID);
    final Map proxyProperties = createProxyProperties(rsContainerID, endpointDescription, selectedRsReference, rs);
    // sync sref props with endpoint props
    endpointDescription.setPropertiesOverrides(proxyProperties);
    final List<String> originalTypes = endpointDescription.getInterfaces();
    final List<String> asyncServiceTypes = endpointDescription.getAsyncInterfaces();
    final List<String> serviceTypes = new ArrayList<String>(originalTypes);
    if (asyncServiceTypes != null)
        for (String ast : asyncServiceTypes) if (ast != null && !serviceTypes.contains(ast))
            serviceTypes.add(ast);
    ServiceRegistration proxyRegistration = AccessController.doPrivileged(new PrivilegedAction<ServiceRegistration>() {

        public ServiceRegistration run() {
            return proxyServiceFactoryContext.registerService((String[]) serviceTypes.toArray(new String[serviceTypes.size()]), createProxyServiceFactory(endpointDescription, containerAdapter, selectedRsReference, rs), (Dictionary) PropertiesUtil.createDictionaryFromMap(proxyProperties));
        }
    });
    return new ImportEndpoint(rsContainer, selectedRsReference, rs, proxyRegistration, endpointDescription);
}
Also used : Dictionary(java.util.Dictionary) IRemoteServiceContainerAdapter(org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter) ArrayList(java.util.ArrayList) ID(org.eclipse.ecf.core.identity.ID) IRemoteServiceID(org.eclipse.ecf.remoteservice.IRemoteServiceID) UUID(java.util.UUID) StringID(org.eclipse.ecf.core.identity.StringID) IRemoteService(org.eclipse.ecf.remoteservice.IRemoteService) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) BundleContext(org.osgi.framework.BundleContext) IExtendedRemoteServiceRegistration(org.eclipse.ecf.remoteservice.IExtendedRemoteServiceRegistration) IRemoteServiceRegistration(org.eclipse.ecf.remoteservice.IRemoteServiceRegistration) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Aggregations

IRemoteService (org.eclipse.ecf.remoteservice.IRemoteService)64 ServiceReference (org.osgi.framework.ServiceReference)11 IFuture (org.eclipse.equinox.concurrent.future.IFuture)10 ECFException (org.eclipse.ecf.core.util.ECFException)9 IRemoteServiceContainerAdapter (org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter)9 IRemoteServiceReference (org.eclipse.ecf.remoteservice.IRemoteServiceReference)8 IRemoteCallListener (org.eclipse.ecf.remoteservice.IRemoteCallListener)6 IRemoteCallCompleteEvent (org.eclipse.ecf.remoteservice.events.IRemoteCallCompleteEvent)6 IRemoteCallEvent (org.eclipse.ecf.remoteservice.events.IRemoteCallEvent)6 IConcatService (org.eclipse.ecf.tests.remoteservice.IConcatService)6 Dictionary (java.util.Dictionary)5 IRemoteServiceProxy (org.eclipse.ecf.remoteservice.IRemoteServiceProxy)5 JSONObject (org.json.JSONObject)5 Hashtable (java.util.Hashtable)4 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)4 RemoteServiceTracker (org.eclipse.ecf.remoteservice.util.tracker.RemoteServiceTracker)4 IRemoteServiceRegistration (org.eclipse.ecf.remoteservice.IRemoteServiceRegistration)3 ExecutionException (java.util.concurrent.ExecutionException)2 ExecutionException (org.eclipse.core.commands.ExecutionException)2 IContainerManager (org.eclipse.ecf.core.IContainerManager)2