Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwjongman2010-05-18 23:11:41 +0000
committerwjongman2010-05-18 23:11:41 +0000
commit30e8a4368e78a4bbd1171c2363a4ddc2e2fa67be (patch)
tree2636b0ad8d6fff849f9ca660036cf86dd65fa4a3
parent9927ec40c1844cea91b0094f99fc6db76c84b249 (diff)
downloadorg.eclipse.ecf-30e8a4368e78a4bbd1171c2363a4ddc2e2fa67be.tar.gz
org.eclipse.ecf-30e8a4368e78a4bbd1171c2363a4ddc2e2fa67be.tar.xz
org.eclipse.ecf-30e8a4368e78a4bbd1171c2363a4ddc2e2fa67be.zip
ASSIGNED - bug 310643: [zookeeper][remoteservices] add usage of zookeeper discovery to hello world examples
https://bugs.eclipse.org/bugs/show_bug.cgi?id=310643 Signed-off by wim.jongman@remainsoftware.com
-rw-r--r--examples/bundles/org.eclipse.ecf.examples.remoteservices.hello.host/.project5
-rw-r--r--examples/bundles/org.eclipse.ecf.examples.remoteservices.hello.host/META-INF/MANIFEST.MF1
-rw-r--r--examples/bundles/org.eclipse.ecf.examples.remoteservices.hello.host/build.properties3
-rw-r--r--examples/bundles/org.eclipse.ecf.examples.remoteservices.hello.host/products/Hello Service Host (zookeeper,rosgi).product61
-rw-r--r--examples/bundles/org.eclipse.ecf.examples.remoteservices.hello.host/src/org/eclipse/ecf/internal/examples/remoteservices/hello/host/HelloCommand.java82
-rw-r--r--examples/bundles/org.eclipse.ecf.examples.remoteservices.hello.host/src/org/eclipse/ecf/internal/examples/remoteservices/hello/host/HelloHostApplication.java38
6 files changed, 177 insertions, 13 deletions
diff --git a/examples/bundles/org.eclipse.ecf.examples.remoteservices.hello.host/.project b/examples/bundles/org.eclipse.ecf.examples.remoteservices.hello.host/.project
index c04e96804..3963caa59 100644
--- a/examples/bundles/org.eclipse.ecf.examples.remoteservices.hello.host/.project
+++ b/examples/bundles/org.eclipse.ecf.examples.remoteservices.hello.host/.project
@@ -25,6 +25,11 @@
<arguments>
</arguments>
</buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ds.core.builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
diff --git a/examples/bundles/org.eclipse.ecf.examples.remoteservices.hello.host/META-INF/MANIFEST.MF b/examples/bundles/org.eclipse.ecf.examples.remoteservices.hello.host/META-INF/MANIFEST.MF
index b5ece7c2a..11e5b3678 100644
--- a/examples/bundles/org.eclipse.ecf.examples.remoteservices.hello.host/META-INF/MANIFEST.MF
+++ b/examples/bundles/org.eclipse.ecf.examples.remoteservices.hello.host/META-INF/MANIFEST.MF
@@ -14,6 +14,7 @@ Import-Package: org.eclipse.ecf.core;version="3.0.0",
org.eclipse.ecf.osgi.services.discovery;version="1.1.0",
org.eclipse.ecf.osgi.services.distribution;version="1.0.0",
org.eclipse.equinox.app;version="1.0.0",
+ org.eclipse.osgi.framework.console,
org.osgi.framework,
org.osgi.util.tracker;version="1.4.2"
Bundle-ActivationPolicy: lazy
diff --git a/examples/bundles/org.eclipse.ecf.examples.remoteservices.hello.host/build.properties b/examples/bundles/org.eclipse.ecf.examples.remoteservices.hello.host/build.properties
index 5bd94f200..8015ab317 100644
--- a/examples/bundles/org.eclipse.ecf.examples.remoteservices.hello.host/build.properties
+++ b/examples/bundles/org.eclipse.ecf.examples.remoteservices.hello.host/build.properties
@@ -5,7 +5,8 @@ bin.includes = META-INF/,\
about.html,\
bundle.properties,\
plugin.xml,\
- products/
+ products/,\
+ OSGI-INF/
src.includes = about.html,\
bundle.properties,\
products/
diff --git a/examples/bundles/org.eclipse.ecf.examples.remoteservices.hello.host/products/Hello Service Host (zookeeper,rosgi).product b/examples/bundles/org.eclipse.ecf.examples.remoteservices.hello.host/products/Hello Service Host (zookeeper,rosgi).product
new file mode 100644
index 000000000..f1ef026b7
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.examples.remoteservices.hello.host/products/Hello Service Host (zookeeper,rosgi).product
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?pde version="3.5"?>
+
+<product name="R-OSGI Zookeeper Hello Host" uid="org.eclipse.ecf.examples.remoteservices.rosgizookeeperhellohost" application="org.eclipse.ecf.examples.remoteservices.hello.host.HelloHost" version="1.0.0" useFeatures="false" includeLaunchers="false">
+
+ <configIni use="default">
+ </configIni>
+
+ <launcherArgs>
+ <programArgs>-console -consoleLog</programArgs>
+ <vmArgs>-Dzoodiscovery.dataDir=zookeeperdata2
+-Dzoodiscovery.clientPort=2001
+-Dzoodiscovery.flavor=zoodiscovery.flavor.standalone=localhost:2002
+-Xms40m
+-Xmx512m</vmArgs>
+ <vmArgsMac>-XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts</vmArgsMac>
+ </launcherArgs>
+
+ <windowImages/>
+
+ <launcher>
+ <solaris/>
+ <win useIco="false">
+ <bmp/>
+ </win>
+ </launcher>
+
+ <vm>
+ </vm>
+
+ <plugins>
+ <plugin id="ch.ethz.iks.r_osgi.remote"/>
+ <plugin id="org.apache.log4j"/>
+ <plugin id="org.apache.zookeeper"/>
+ <plugin id="org.eclipse.core.contenttype"/>
+ <plugin id="org.eclipse.core.jobs"/>
+ <plugin id="org.eclipse.core.runtime"/>
+ <plugin id="org.eclipse.ecf"/>
+ <plugin id="org.eclipse.ecf.discovery"/>
+ <plugin id="org.eclipse.ecf.examples.remoteservices.hello"/>
+ <plugin id="org.eclipse.ecf.examples.remoteservices.hello.host"/>
+ <plugin id="org.eclipse.ecf.identity"/>
+ <plugin id="org.eclipse.ecf.osgi.services.discovery"/>
+ <plugin id="org.eclipse.ecf.osgi.services.distribution"/>
+ <plugin id="org.eclipse.ecf.provider"/>
+ <plugin id="org.eclipse.ecf.provider.r_osgi"/>
+ <plugin id="org.eclipse.ecf.provider.zookeeper"/>
+ <plugin id="org.eclipse.ecf.remoteservice"/>
+ <plugin id="org.eclipse.ecf.sharedobject"/>
+ <plugin id="org.eclipse.equinox.app"/>
+ <plugin id="org.eclipse.equinox.common"/>
+ <plugin id="org.eclipse.equinox.concurrent"/>
+ <plugin id="org.eclipse.equinox.preferences"/>
+ <plugin id="org.eclipse.equinox.registry"/>
+ <plugin id="org.eclipse.osgi"/>
+ <plugin id="org.eclipse.osgi.services"/>
+ <plugin id="org.objectweb.asm"/>
+ </plugins>
+
+
+</product>
diff --git a/examples/bundles/org.eclipse.ecf.examples.remoteservices.hello.host/src/org/eclipse/ecf/internal/examples/remoteservices/hello/host/HelloCommand.java b/examples/bundles/org.eclipse.ecf.examples.remoteservices.hello.host/src/org/eclipse/ecf/internal/examples/remoteservices/hello/host/HelloCommand.java
new file mode 100644
index 000000000..b0ee37e14
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.examples.remoteservices.hello.host/src/org/eclipse/ecf/internal/examples/remoteservices/hello/host/HelloCommand.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c)2010 REMAIN B.V. (http://www.remainsoftware.com).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Wim Jongman - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.examples.remoteservices.hello.host;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.eclipse.osgi.framework.console.CommandInterpreter;
+import org.eclipse.osgi.framework.console.CommandProvider;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+// referenced in component.xml
+public class HelloCommand implements CommandProvider {
+
+ private ServiceRegistration helloRegistration;
+ private String containerType;
+ private String containerId;
+ private BundleContext context;
+
+ public HelloCommand(BundleContext context,
+ ServiceRegistration helloRegistration, String containerType,
+ String containerId) {
+ this.context = context;
+ this.helloRegistration = helloRegistration;
+ this.containerType = containerType;
+ this.containerId = containerId;
+
+ Dictionary props = new Hashtable();
+ props.put(org.osgi.framework.Constants.SERVICE_RANKING, new Integer(
+ Integer.MAX_VALUE - 100));
+
+ context.registerService(CommandProvider.class.getName(), this, props);
+ }
+
+ public void _hello(CommandInterpreter ci) {
+ String arg = ci.nextArgument();
+
+ if (arg == null) {
+ return;
+ }
+
+ if (arg.equalsIgnoreCase("stop")) {
+ stopService();
+ }
+ if (arg.equalsIgnoreCase("start")) {
+ startService();
+ }
+ }
+
+ private void startService() {
+ if (helloRegistration == null) {
+ helloRegistration = HelloHostApplication.startService(context,
+ containerType, containerId);
+ System.out.println("Service started");
+ }
+ }
+
+ private void stopService() {
+ if (helloRegistration != null) {
+ helloRegistration = HelloHostApplication
+ .stopService(helloRegistration);
+ System.out.println("Service stopped");
+ }
+ }
+
+ public String getHelp() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("---ECF Example Command---\n");
+ buffer.append("\thello stop - stop the service. It should be undiscovered remote\n");
+ buffer.append("\thello start - start the service. It should be discovered remote\n");
+ return buffer.toString();
+ }
+} \ No newline at end of file
diff --git a/examples/bundles/org.eclipse.ecf.examples.remoteservices.hello.host/src/org/eclipse/ecf/internal/examples/remoteservices/hello/host/HelloHostApplication.java b/examples/bundles/org.eclipse.ecf.examples.remoteservices.hello.host/src/org/eclipse/ecf/internal/examples/remoteservices/hello/host/HelloHostApplication.java
index 5beeeef57..696ebeb59 100644
--- a/examples/bundles/org.eclipse.ecf.examples.remoteservices.hello.host/src/org/eclipse/ecf/internal/examples/remoteservices/hello/host/HelloHostApplication.java
+++ b/examples/bundles/org.eclipse.ecf.examples.remoteservices.hello.host/src/org/eclipse/ecf/internal/examples/remoteservices/hello/host/HelloHostApplication.java
@@ -42,7 +42,10 @@ public class HelloHostApplication implements IApplication,
//private ServiceRegistration helloRegistration2;
public Object start(IApplicationContext appContext) throws Exception {
+
bundleContext = Activator.getContext();
+
+
// Process Arguments
processArgs(appContext);
@@ -60,6 +63,18 @@ public class HelloHostApplication implements IApplication,
// all will be notified of register/unregister events
bundleContext.registerService(IHostDistributionListener.class.getName(), new LoggingHostDistributionListener(), null);
+ helloRegistration = startService(bundleContext, containerType, containerId);
+
+ // Register the console command
+ new HelloCommand(bundleContext, helloRegistration, containerType, containerId);
+
+ // wait until stopped
+ waitForDone();
+
+ return IApplication.EXIT_OK;
+ }
+
+ public static ServiceRegistration startService(BundleContext bundleContext, String containerType, String containerId) {
// Setup properties for remote service distribution, as per OSGi 4.2 remote services
// specification (chap 13 in compendium spec)
Properties props = new Properties();
@@ -70,24 +85,23 @@ public class HelloHostApplication implements IApplication,
// add ECF service property specifying container factory args
props.put(IDistributionConstants.SERVICE_EXPORTED_CONTAINER_FACTORY_ARGUMENTS, containerId);
// register remote service
- helloRegistration = bundleContext.registerService(IHello.class
+ ServiceRegistration reg = bundleContext.registerService(IHello.class
.getName(), new Hello(), props);
// tell everyone
System.out.println("Host: Hello Service Registered");
+
+ return reg;
+ }
- // register remote service
-// helloRegistration2 = bundleContext.registerService(IHello.class
-// .getName(), new Hello(), props);
-
- // tell everyone again
-// System.out.println("Host: Hello2 Service Registered");
+ public static ServiceRegistration stopService(ServiceRegistration helloRegistration)
+ {
+ helloRegistration.unregister();
- // wait until stopped
- waitForDone();
-
- return IApplication.EXIT_OK;
+ // tell everyone
+ System.out.println("Host: Hello Service Unregistered");
+
+ return null;
}
-
public void stop() {
if (helloRegistration != null) {
helloRegistration.unregister();

Back to the top