Repository: karaf-cellar Updated Branches: refs/heads/master 0ea53b51f -> 36efc8e27
Minor cleanup on the DOSGi sample Project: http://git-wip-us.apache.org/repos/asf/karaf-cellar/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf-cellar/commit/36efc8e2 Tree: http://git-wip-us.apache.org/repos/asf/karaf-cellar/tree/36efc8e2 Diff: http://git-wip-us.apache.org/repos/asf/karaf-cellar/diff/36efc8e2 Branch: refs/heads/master Commit: 36efc8e2754c1bd7c2841b58a25c98203a775ed2 Parents: 0ea53b5 Author: Jean-Baptiste Onofré <[email protected]> Authored: Wed Sep 16 07:50:03 2015 +0200 Committer: Jean-Baptiste Onofré <[email protected]> Committed: Wed Sep 16 07:50:03 2015 +0200 ---------------------------------------------------------------------- samples/dosgi-greeter/README | 30 ++++++++++---------- .../samples/dosgi/greeter/api/Greeter.java | 2 +- .../dosgi/greeter/service/Activator.java | 2 ++ 3 files changed, 18 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/36efc8e2/samples/dosgi-greeter/README ---------------------------------------------------------------------- diff --git a/samples/dosgi-greeter/README b/samples/dosgi-greeter/README index 24dbc80..e5d59f3 100644 --- a/samples/dosgi-greeter/README +++ b/samples/dosgi-greeter/README @@ -3,33 +3,33 @@ DOSGi Greeter is a sample application that demonstrates the DOSGi feature of Cel Use Case -------- A service bundle expose an OSGi service on the cluster using Cellar DOSGi. -On the other hand, a client bundle provides a shell command to call the service bundle. +On the other hand, a client bundle provides a shell command to call the service. The call is remote using DOSGi. Installation ------------- To show the remote service call, your Cellar cluster should contain at least two nodes. -NodeA ------ -On NodeA, we install the API bundle (providing the OSGi service description), and the service bundle (providing the -actual service implementation): +Install cellar and cellar-dosgi on the cluster: -karaf@root()> bundle:install -s mvn:org.apache.karaf.cellar.samples.dosgi.greeter/org.apache.karaf.cellar.samples.dosgi.greeter.api/3.0.0 -karaf@root()> bundle:install -s mvn:org.apache.karaf.cellar.samples.dosgi.greeter/org.apache.karaf.cellar.samples.dosgi.greeter.service/3.0.0 +karaf@root()> feature:repo-add cellar 4.0.0 +karaf@root()> feature:install cellar +karaf@root()> feature:install cellar-dosgi -We can see the service exposed on the cluster using the cluster:service-list command. +Install the api bundle on the cluster: -NodeB ------ -On NodeB, we install the API bundle (to get the description of the OSGi service), and the client bundle (providing a shell -command to call the service): +karaf@root()> cluster:bundle-install -s default mvn:org.apache.karaf.cellar.samples.dosgi.greeter/org.apache.karaf.cellar.samples.dosgi.greeter.api/4.0.0 -karaf@root()> bundle:install -s mvn:org.apache.karaf.cellar.samples.dosgi.greeter/org.apache.karaf.cellar.samples.dosgi.greeter.api/3.0.0 -karaf@root()> bundle:install -s mvn:org.apache.karaf.cellar.samples.dosgi.greeter/org.apache.karaf.cellar.samples.dosgi.greeter.client/3.0.0 +Install the service bundle only on one node (node1): + +karaf@root()> bundle:install -s mvn:org.apache.karaf.cellar.samples.dosgi.greeter/org.apache.karaf.cellar.samples.dosgi.greeter.service/4.0.0 + +On other nodes (node2), install the client bundle: + +karaf@root()> bundle:install -s mvn:org.apache.karaf.cellar.samples.dosgi.greeter/org.apache.karaf.cellar.samples.dosgi.greeter.client/4.0.0 The client bundle provides a new shell command that we can use to call the OSGi service (remotely): -karaf@root> dosgi-greeter:greet Hello 2 +karaf@root()> dosgi-greeter:greet Hello 2 Hello.Hello from node 192.168.1.101:5702 count 0. Hello.Hello from node 192.168.1.101:5702 count 1. http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/36efc8e2/samples/dosgi-greeter/api/src/main/java/org/apache/karaf/cellar/samples/dosgi/greeter/api/Greeter.java ---------------------------------------------------------------------- diff --git a/samples/dosgi-greeter/api/src/main/java/org/apache/karaf/cellar/samples/dosgi/greeter/api/Greeter.java b/samples/dosgi-greeter/api/src/main/java/org/apache/karaf/cellar/samples/dosgi/greeter/api/Greeter.java index 928bf34..d888a7d 100644 --- a/samples/dosgi-greeter/api/src/main/java/org/apache/karaf/cellar/samples/dosgi/greeter/api/Greeter.java +++ b/samples/dosgi-greeter/api/src/main/java/org/apache/karaf/cellar/samples/dosgi/greeter/api/Greeter.java @@ -22,6 +22,6 @@ public interface Greeter { * Returns a greet message. * @return */ - public GreetResponse greet(Greet greet); + GreetResponse greet(Greet greet); } http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/36efc8e2/samples/dosgi-greeter/service/src/main/java/org/apache/karaf/cellar/samples/dosgi/greeter/service/Activator.java ---------------------------------------------------------------------- diff --git a/samples/dosgi-greeter/service/src/main/java/org/apache/karaf/cellar/samples/dosgi/greeter/service/Activator.java b/samples/dosgi-greeter/service/src/main/java/org/apache/karaf/cellar/samples/dosgi/greeter/service/Activator.java index b092768..4a3c46c 100644 --- a/samples/dosgi-greeter/service/src/main/java/org/apache/karaf/cellar/samples/dosgi/greeter/service/Activator.java +++ b/samples/dosgi-greeter/service/src/main/java/org/apache/karaf/cellar/samples/dosgi/greeter/service/Activator.java @@ -36,6 +36,8 @@ public class Activator extends BaseActivator { public void doStart() throws Exception { ClusterManager clusterManager = getTrackedService(ClusterManager.class); + if (clusterManager == null) + return; String nodeId = clusterManager.getNode().getId(); GreeterImpl greeter = new GreeterImpl(nodeId);
