diff options
author | slewis | 2014-04-17 22:06:34 +0000 |
---|---|---|
committer | slewis | 2014-04-17 22:06:34 +0000 |
commit | c8712d0ea75759204058b8345369d09fad753363 (patch) | |
tree | 1363d6c2f1e9a6db6e8ead7821e0bc9ca6787ded /examples/bundles/com.mycorp.examples.timeservice.consumer.ds | |
parent | 5a45046034cd989f4e440c76b59b817b426ea3f0 (diff) | |
download | org.eclipse.ecf-c8712d0ea75759204058b8345369d09fad753363.tar.gz org.eclipse.ecf-c8712d0ea75759204058b8345369d09fad753363.tar.xz org.eclipse.ecf-c8712d0ea75759204058b8345369d09fad753363.zip |
Changes to timeservice example consumer to support changes to
asynchronous remote service tutorial
Change-Id: I3ae8ab9c6a09f9b0b7341fee46d8d891355207a4
Diffstat (limited to 'examples/bundles/com.mycorp.examples.timeservice.consumer.ds')
2 files changed, 23 insertions, 1 deletions
diff --git a/examples/bundles/com.mycorp.examples.timeservice.consumer.ds/META-INF/MANIFEST.MF b/examples/bundles/com.mycorp.examples.timeservice.consumer.ds/META-INF/MANIFEST.MF index 5b418d6df..b14a75ec1 100644 --- a/examples/bundles/com.mycorp.examples.timeservice.consumer.ds/META-INF/MANIFEST.MF +++ b/examples/bundles/com.mycorp.examples.timeservice.consumer.ds/META-INF/MANIFEST.MF @@ -6,4 +6,4 @@ Bundle-Version: 1.0.0.qualifier Bundle-Vendor: Eclipse.org - ECF Bundle-RequiredExecutionEnvironment: J2SE-1.5 Service-Component: OSGI-INF/timeservicecomponent.xml -Import-Package: com.mycorp.examples.timeservice;version="1.0.0" +Import-Package: com.mycorp.examples.timeservice;version="[1.0.0,2.0.0)" diff --git a/examples/bundles/com.mycorp.examples.timeservice.consumer.ds/src/com/mycorp/examples/timeservice/consumer/ds/TimeServiceComponent.java b/examples/bundles/com.mycorp.examples.timeservice.consumer.ds/src/com/mycorp/examples/timeservice/consumer/ds/TimeServiceComponent.java index cda94185a..2a0f55554 100644 --- a/examples/bundles/com.mycorp.examples.timeservice.consumer.ds/src/com/mycorp/examples/timeservice/consumer/ds/TimeServiceComponent.java +++ b/examples/bundles/com.mycorp.examples.timeservice.consumer.ds/src/com/mycorp/examples/timeservice/consumer/ds/TimeServiceComponent.java @@ -8,13 +8,35 @@ ******************************************************************************/ package com.mycorp.examples.timeservice.consumer.ds; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; + import com.mycorp.examples.timeservice.ITimeService; +import com.mycorp.examples.timeservice.ITimeServiceAsync; public class TimeServiceComponent { void bindTimeService(ITimeService timeService) { + // Invoke synchronously System.out.println("Discovered ITimeService via DS"); // Call the service and print out result! System.out.println("Current time is: " + timeService.getCurrentTime()); + + // Then invoke asynchronously + if (timeService instanceof ITimeServiceAsync) { + ITimeServiceAsync asyncTimeService = (ITimeServiceAsync) timeService; + System.out.println("Discovered ITimeServiceAsync via DS"); + // Call the asynchronous remote service. Unlike the synchronous getTimeService(), + // this method will not block + Future<Long> currentTimeFuture = asyncTimeService.getCurrentTimeAsync(); + // potentially do other operations here... + try { + System.out.println("Current time via future.get is: " + currentTimeFuture.get()); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (ExecutionException e) { + e.printStackTrace(); + } + } } } |