Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2014-03-30 19:40:15 +0000
committerslewis2014-03-30 19:40:15 +0000
commit4f51d8936db04c988aa3516c5da43472477cbf3c (patch)
tree73e7bb5e1e0d2977894a91f085d053516e1663be /examples/bundles/com.mycorp.examples.timeservice.host/src
parent9ea8e9999bfceaec9435025ad890189635aa39f8 (diff)
downloadorg.eclipse.ecf-4f51d8936db04c988aa3516c5da43472477cbf3c.tar.gz
org.eclipse.ecf-4f51d8936db04c988aa3516c5da43472477cbf3c.tar.xz
org.eclipse.ecf-4f51d8936db04c988aa3516c5da43472477cbf3c.zip
Changes to remote timeservice examples to support usage of
java8/completablefuture and use of no extension registry as per bug 421569. Also changed launch configs to product configs...to allow for easier/more flexible usage by consumers of these examples. Change-Id: I772ac9aa201af1e6e9c57bc08cfb88bc1b1334a8
Diffstat (limited to 'examples/bundles/com.mycorp.examples.timeservice.host/src')
-rw-r--r--examples/bundles/com.mycorp.examples.timeservice.host/src/com/mycorp/examples/timeservice/host/Activator.java65
1 files changed, 21 insertions, 44 deletions
diff --git a/examples/bundles/com.mycorp.examples.timeservice.host/src/com/mycorp/examples/timeservice/host/Activator.java b/examples/bundles/com.mycorp.examples.timeservice.host/src/com/mycorp/examples/timeservice/host/Activator.java
index d2e91848a..f18a9fd88 100644
--- a/examples/bundles/com.mycorp.examples.timeservice.host/src/com/mycorp/examples/timeservice/host/Activator.java
+++ b/examples/bundles/com.mycorp.examples.timeservice.host/src/com/mycorp/examples/timeservice/host/Activator.java
@@ -10,6 +10,7 @@ package com.mycorp.examples.timeservice.host;
import java.util.Dictionary;
import java.util.Hashtable;
+import java.util.Properties;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
@@ -21,36 +22,20 @@ import com.mycorp.examples.timeservice.ITimeService;
public class Activator implements BundleActivator {
- private static final String GENERIC_SERVER_CONFIG = "ecf.generic.server";
- private static final String GENERIC_SERVER_PORTPROP_NAME = GENERIC_SERVER_CONFIG+ ".port";
- private static final String GENERIC_SERVER_PORTPROP_VALUE = "3288";
- private static final String GENERIC_SERVER_HOSTPROP_NAME = GENERIC_SERVER_CONFIG+ ".hostname";
- private static final String GENERIC_SERVER_HOSTPROP_VALUE = "localhost";
-
- private static final String R_OSGI_SERVER_CONFIG = "ecf.r_osgi.peer";
-
- private static final String REST_SERVER_CONFIG = "com.mycorp.examples.timeservice.rest.host";
- private static final String REST_SERVER_IDPROP_NAME = REST_SERVER_CONFIG + ".id";
- private static final String REST_SERVER_IDPROP_VALUE = "http://localhost:8181";
-
public void start(BundleContext context) throws Exception {
// If the verboseRemoteServiceAdmin system property is set
// then register debug listener
if (Boolean.getBoolean("verboseRemoteServiceAdmin"))
registerDebugListener(context);
- // Create remote service properties...see createRemoteServiceProperties above
+ // Create remote service properties...see createRemoteServiceProperties()
Dictionary<String, Object> props = createRemoteServiceProperties();
- // Create MyTimeService impl and register as a remote service
- // register the remote service with the service registry. If ECF remote
- // services/RSA impl is installed and started, it will export this
- // service via the default distribution provider, which is
- // 'ecf.generic.server'
- // To change which provider is used (e.g.) r-OSGi:
- // props.put("service.exported.configs","ecf.r_osgi.peer");
+
+ // Create MyTimeService impl and register/export as a remote service
ServiceRegistration<ITimeService> timeServiceRegistration = context
.registerService(ITimeService.class, new TimeServiceImpl(),
props);
+
// Print out that ITimeService remote service registration
System.out.println("MyTimeService host registered with registration="
+ timeServiceRegistration);
@@ -61,31 +46,23 @@ public class Activator implements BundleActivator {
}
private Dictionary<String,Object> createRemoteServiceProperties() {
- Dictionary<String, Object> props = new Hashtable<String, Object>();
// This is the only required service property to trigger remote services
- props.put("service.exported.interfaces", "*");
- // set service.exported.configs
- String serviceExportedConfig = System.getProperty("service.exported.configs",GENERIC_SERVER_CONFIG);
- props.put("service.exported.configs",serviceExportedConfig);
- String propName = null;
- String propValue = null;
- if (GENERIC_SERVER_CONFIG.equals(serviceExportedConfig)) {
- propName = GENERIC_SERVER_PORTPROP_NAME;
- propValue = GENERIC_SERVER_PORTPROP_VALUE;
- props.put(GENERIC_SERVER_HOSTPROP_NAME, GENERIC_SERVER_HOSTPROP_VALUE);
- } else if (REST_SERVER_CONFIG.equals(serviceExportedConfig)) {
- propName = REST_SERVER_IDPROP_NAME;
- propValue = REST_SERVER_IDPROP_VALUE;
- } else if (R_OSGI_SERVER_CONFIG.equals(serviceExportedConfig)) {
- // r-osgi does not require the server to define its endpoint
- return props;
- } else throw new NullPointerException("Unsuppored value for service.exported.config="+serviceExportedConfig);
-
- // Set the propName and idPropValue
- props.put(propName,propValue);
- return props;
+ Dictionary<String,Object> result = new Hashtable<String,Object>();
+ result.put("service.exported.interfaces", "*");
+ Properties props = System.getProperties();
+ String config = props.getProperty("service.exported.configs");
+ if (config != null) {
+ result.put("service.exported.configs", config);
+ String configProps = config + ".";
+ for(Object k: props.keySet()) {
+ if (k instanceof String) {
+ String key = (String) k;
+ if (key.startsWith(configProps) || key.equals("ecf.exported.async.interfaces")) result.put(key, props.getProperty(key));
+ }
+ }
+ }
+ return result;
}
-
// Register a RemoteServiceAdminListener so we can report to sdtout
// when a remote service has actually been successfully exported by
@@ -104,7 +81,7 @@ public class Activator implements BundleActivator {
}
};
- // Register as service, and RemoteServiceAdmin will callback
+ // Register our listener as service via whiteboard pattern, and RemoteServiceAdmin will callback
context.registerService(RemoteServiceAdminListener.class.getName(),
rsaListener, null);
}

Back to the top