Search in sources :

Example 1 with RemoteServiceTracker

use of org.eclipse.ecf.remoteservice.util.tracker.RemoteServiceTracker in project ecf by eclipse.

the class DataProcessorConsumerApplication method start.

public Object start(IApplicationContext appContext) throws Exception {
    bundleContext = Activator.getContext();
    // Process Arguments...i.e. set queueId and topicId if specified
    processArgs(appContext);
    // Create container of appropriate type
    container = getContainerManagerService().getContainerFactory().createContainer(containerType);
    // Get appropriate adapter
    remoteServiceAdapter = (IRemoteServiceContainerAdapter) container.getAdapter(IRemoteServiceContainerAdapter.class);
    // Create remote service tracker, and then open it
    RemoteServiceTracker tracker = new RemoteServiceTracker(remoteServiceAdapter, null, IDataProcessor.class.getName(), new RemoteServiceTrackerCustomizer());
    // Open it
    tracker.open();
    // Connect to topic.  This should trigger remote service registration to be asynchronously
    // added, and in turn call RemoteServiceTrackerCustomizer.addingService (see impl of that
    // method above
    container.connect(IDFactory.getDefault().createID(container.getConnectNamespace(), topicId), null);
    // Wait for remote service tracker to receive proxy and execute.   See
    // RemoteServiceTrackerCustomizer.addingService above
    waitForRemoteService();
    return IApplication.EXIT_OK;
}
Also used : RemoteServiceTracker(org.eclipse.ecf.remoteservice.util.tracker.RemoteServiceTracker) IDataProcessor(org.eclipse.ecf.examples.loadbalancing.IDataProcessor) IRemoteServiceTrackerCustomizer(org.eclipse.ecf.remoteservice.util.tracker.IRemoteServiceTrackerCustomizer)

Example 2 with RemoteServiceTracker

use of org.eclipse.ecf.remoteservice.util.tracker.RemoteServiceTracker in project ecf by eclipse.

the class RemoteServiceProxyTest method getRemoteService.

protected IRemoteService getRemoteService(IRemoteServiceContainerAdapter adapter, String clazz, String filter) {
    remoteServiceTracker = new RemoteServiceTracker(adapter, null, clazz, null);
    assertNotNull(remoteServiceTracker);
    remoteServiceTracker.open();
    return remoteServiceTracker.getRemoteService();
}
Also used : RemoteServiceTracker(org.eclipse.ecf.remoteservice.util.tracker.RemoteServiceTracker)

Example 3 with RemoteServiceTracker

use of org.eclipse.ecf.remoteservice.util.tracker.RemoteServiceTracker 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 4 with RemoteServiceTracker

use of org.eclipse.ecf.remoteservice.util.tracker.RemoteServiceTracker in project ecf by eclipse.

the class RemoteServiceTrackerTest method getRemoteService.

protected IRemoteService getRemoteService(IRemoteServiceContainerAdapter adapter, String clazz, String filter) {
    remoteServiceTracker = new RemoteServiceTracker(adapter, null, clazz, null);
    assertNotNull(remoteServiceTracker);
    remoteServiceTracker.open();
    return remoteServiceTracker.getRemoteService();
}
Also used : RemoteServiceTracker(org.eclipse.ecf.remoteservice.util.tracker.RemoteServiceTracker)

Example 5 with RemoteServiceTracker

use of org.eclipse.ecf.remoteservice.util.tracker.RemoteServiceTracker in project ecf by eclipse.

the class RemoteServiceTrackerTest 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)

Aggregations

RemoteServiceTracker (org.eclipse.ecf.remoteservice.util.tracker.RemoteServiceTracker)9 Dictionary (java.util.Dictionary)4 Hashtable (java.util.Hashtable)4 IRemoteService (org.eclipse.ecf.remoteservice.IRemoteService)4 IRemoteServiceContainerAdapter (org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter)4 IConcatService (org.eclipse.ecf.tests.remoteservice.IConcatService)4 IRemoteServiceProxy (org.eclipse.ecf.remoteservice.IRemoteServiceProxy)2 IRemoteServiceReference (org.eclipse.ecf.remoteservice.IRemoteServiceReference)2 IDataProcessor (org.eclipse.ecf.examples.loadbalancing.IDataProcessor)1 IRemoteServiceTrackerCustomizer (org.eclipse.ecf.remoteservice.util.tracker.IRemoteServiceTrackerCustomizer)1