karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject [28/35] karaf-boot git commit: Add config support for service provider and remove config module
Date Mon, 09 May 2016 14:48:47 GMT
Add config support for service provider and remove config module


Project: http://git-wip-us.apache.org/repos/asf/karaf-boot/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf-boot/commit/c615578e
Tree: http://git-wip-us.apache.org/repos/asf/karaf-boot/tree/c615578e
Diff: http://git-wip-us.apache.org/repos/asf/karaf-boot/diff/c615578e

Branch: refs/heads/master
Commit: c615578e45a5e70e6a60efedc547d021346a1681
Parents: 1d8892a
Author: Christian Schneider <chris@die-schneider.net>
Authored: Mon Apr 25 13:03:42 2016 +0200
Committer: Christian Schneider <chris@die-schneider.net>
Committed: Mon Apr 25 13:03:42 2016 +0200

----------------------------------------------------------------------
 samples/ds/config/README.md                     | 31 -------------
 samples/ds/config/pom.xml                       | 47 --------------------
 .../java/sample/config/ConfigComponent.java     | 43 ------------------
 samples/ds/pom.xml                              |  3 +-
 samples/ds/service-consumer/README.md           | 25 +++--------
 samples/ds/service-consumer/pom.xml             |  4 +-
 .../ds/service/consumer/HelloServiceClient.java |  8 +---
 samples/ds/service-provider/README.md           | 27 ++++-------
 samples/ds/service-provider/pom.xml             |  2 +-
 .../ds/service/provider/HelloServiceImpl.java   | 22 ++++++++-
 samples/ds/shell/pom.xml                        |  2 +-
 11 files changed, 43 insertions(+), 171 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/c615578e/samples/ds/config/README.md
----------------------------------------------------------------------
diff --git a/samples/ds/config/README.md b/samples/ds/config/README.md
deleted file mode 100644
index 1c8dbc5..0000000
--- a/samples/ds/config/README.md
+++ /dev/null
@@ -1,31 +0,0 @@
-== karaf-boot-sample-config ==
-
-This sample shows how to use a configuration provided in the etc folder of Karaf, and directly
use the
-properties values in your code.
-
-= Design
-
-The ConfigComponent use a SampleConfig configuration. The SampleConfig configuration is "injected"
at activation
-time of the component.
-
-The component just displays the values of the properties.
-
-= Build
-
-To build, simply do:
-
-  mvn clean install
-
-= Deploy
-
-To deploy in Karaf, you have to enable the DS support first. For that, you have to install
the scr feature:
-
-  feature:install scr
-
-Once scr feature installed:
-
-* you can drop the generated jar file (target/karaf-boot-sample-config-1.0.jar) in the
-Karaf deploy folder
-* in the Karaf shell console, do:
-
-  bundle:install -s mvn:org.apache.karaf.boot/karaf-boot-sample-config/1.0
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/c615578e/samples/ds/config/pom.xml
----------------------------------------------------------------------
diff --git a/samples/ds/config/pom.xml b/samples/ds/config/pom.xml
deleted file mode 100644
index 688150b..0000000
--- a/samples/ds/config/pom.xml
+++ /dev/null
@@ -1,47 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-
-    <!--
-
-        Licensed to the Apache Software Foundation (ASF) under one or more
-        contributor license agreements.  See the NOTICE file distributed with
-        this work for additional information regarding copyright ownership.
-        The ASF licenses this file to You under the Apache License, Version 2.0
-        (the "License"); you may not use this file except in compliance with
-        the License.  You may obtain a copy of the License at
-
-           http://www.apache.org/licenses/LICENSE-2.0
-
-        Unless required by applicable law or agreed to in writing, software
-        distributed under the License is distributed on an "AS IS" BASIS,
-        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-        See the License for the specific language governing permissions and
-        limitations under the License.
-    -->
-
-    <modelVersion>4.0.0</modelVersion>
-
-    <groupId>org.apache.karaf.boot</groupId>
-    <artifactId>karaf-boot-sample-config</artifactId>
-    <version>1.0.0-SNAPSHOT</version>
-
-    <dependencies>
-        <dependency>
-            <groupId>org.apache.karaf.boot</groupId>
-            <artifactId>karaf-boot-starter-ds</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-    </dependencies>
-
-    <build>
-        <plugins>
-            <plugin>
-                <groupId>org.apache.karaf.boot</groupId>
-                <artifactId>karaf-boot-maven-plugin</artifactId>
-                <version>${project.version}</version>
-                <extensions>true</extensions>
-            </plugin>
-        </plugins>
-    </build>
-
-</project>

http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/c615578e/samples/ds/config/src/main/java/sample/config/ConfigComponent.java
----------------------------------------------------------------------
diff --git a/samples/ds/config/src/main/java/sample/config/ConfigComponent.java b/samples/ds/config/src/main/java/sample/config/ConfigComponent.java
deleted file mode 100644
index 52cf369..0000000
--- a/samples/ds/config/src/main/java/sample/config/ConfigComponent.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/**
- *  Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  See the NOTICE file distributed with
- *  this work for additional information regarding copyright ownership.
- *  The ASF licenses this file to You under the Apache License, Version 2.0
- *  (the "License"); you may not use this file except in compliance with
- *  the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- */
-package sample.config;
-
-import org.osgi.service.component.annotations.Activate;
-import org.osgi.service.component.annotations.Component;
-import org.osgi.service.metatype.annotations.Designate;
-import org.osgi.service.metatype.annotations.ObjectClassDefinition;
-
-@ObjectClassDefinition(name = "Sample Configuration", pid = "org.apache.karaf.boot.sample.config")
-@interface SampleConfig {
-    String stringProperty() default "default";
-    int intProperty() default 0;
-    boolean booleanProperty() default false;
-}
-
-@Component
-@Designate(ocd = SampleConfig.class)
-public class ConfigComponent {
-
-    @Activate
-    public void activate(SampleConfig sampleConfig) {
-        System.out.println("We use the property there");
-        System.out.println("stringProperty:" + sampleConfig.stringProperty());
-        System.out.println("intProperty: " + sampleConfig.intProperty());
-        System.out.println("booleanProperty: " + sampleConfig.booleanProperty());
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/c615578e/samples/ds/pom.xml
----------------------------------------------------------------------
diff --git a/samples/ds/pom.xml b/samples/ds/pom.xml
index f031e88..7005d78 100644
--- a/samples/ds/pom.xml
+++ b/samples/ds/pom.xml
@@ -22,12 +22,11 @@
     <modelVersion>4.0.0</modelVersion>
 
     <groupId>org.apache.karaf.boot</groupId>
-    <artifactId>karaf-boot-samples-ds</artifactId>
+    <artifactId>karaf-boot-sample-ds</artifactId>
     <version>1.0.0-SNAPSHOT</version>
     <packaging>pom</packaging>
 
     <modules>
-        <module>config</module>
         <module>service-consumer</module>
         <module>service-provider</module>
         <module>shell</module>

http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/c615578e/samples/ds/service-consumer/README.md
----------------------------------------------------------------------
diff --git a/samples/ds/service-consumer/README.md b/samples/ds/service-consumer/README.md
index ae04875..1f2b683 100644
--- a/samples/ds/service-consumer/README.md
+++ b/samples/ds/service-consumer/README.md
@@ -1,36 +1,23 @@
-== karaf-boot-sample-service-provider-osgi ==
+== karaf-boot-sample-ds-service-consumer ==
 
-This sample exposes an OSGi service using the Karaf util classe and annotation.
+This sample binds and uses an OSGi service using declarative services (DS).
 
 = Design
 
-This artifact uses the hello service provided by another artifact (karaf-boot-sample-service-provider-ds
for instance).
+This artifact uses the hello service.
 
 It uses the DS annotations to create a bean with a reference (@Reference) to the hello service.
 In the HelloServiceClient bean, we use the @Activate annotation to execute a specific method.
 
-You don't think anything else: karaf-boot will generate all the plumbing for you, and you
will directly have a ready
-to use artifact.
-
 = Build
 
-To build, simply do:
-
   mvn clean install
 
 = Deploy
 
-To deploy in Karaf, you have to enable the DS support first. For that, you have to install
the scr feature:
+We need to enable DS support and install the service as well as the consumer
 
   feature:install scr
+  bundle:install -s mvn:org.apache.karaf.boot/karaf-boot-sample-ds-service-consumer/1.0.0-SNAPSHOT
+  bundle:install -s mvn:org.apache.karaf.boot/karaf-boot-sample-ds-service-consumer/1.0.0-SNAPSHOT
 
-Once scr feature installed, you have to install a hello service provider. Please use any
of karaf-boot-sample-service-provider-*
-deployment first.
-
-Once the service provider is installed:
-
-* you can drop the generated jar file (target/karaf-boot-sample-service-consumer-ds-1.0.jar)
in the
-Karaf deploy folder
-* in the Karaf shell console, do:
-
-  bundle:install -s mvn:org.apache.karaf.boot/karaf-boot-sample-service-consumer-ds/1.0
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/c615578e/samples/ds/service-consumer/pom.xml
----------------------------------------------------------------------
diff --git a/samples/ds/service-consumer/pom.xml b/samples/ds/service-consumer/pom.xml
index 3048e77..0324230 100644
--- a/samples/ds/service-consumer/pom.xml
+++ b/samples/ds/service-consumer/pom.xml
@@ -22,7 +22,7 @@
     <modelVersion>4.0.0</modelVersion>
 
     <groupId>org.apache.karaf.boot</groupId>
-    <artifactId>karaf-boot-sample-service-consumer-ds</artifactId>
+    <artifactId>karaf-boot-sample-ds-service-consumer</artifactId>
     <version>1.0.0-SNAPSHOT</version>
 
     <dependencies>
@@ -33,7 +33,7 @@
         </dependency>
         <dependency>
             <groupId>org.apache.karaf.boot</groupId>
-            <artifactId>karaf-boot-sample-service-provider-ds</artifactId>
+            <artifactId>karaf-boot-sample-ds-service-provider</artifactId>
             <version>${project.version}</version>
         </dependency>
     </dependencies>

http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/c615578e/samples/ds/service-consumer/src/main/java/sample/ds/service/consumer/HelloServiceClient.java
----------------------------------------------------------------------
diff --git a/samples/ds/service-consumer/src/main/java/sample/ds/service/consumer/HelloServiceClient.java
b/samples/ds/service-consumer/src/main/java/sample/ds/service/consumer/HelloServiceClient.java
index f70ebf7..f4ac3fd 100644
--- a/samples/ds/service-consumer/src/main/java/sample/ds/service/consumer/HelloServiceClient.java
+++ b/samples/ds/service-consumer/src/main/java/sample/ds/service/consumer/HelloServiceClient.java
@@ -25,7 +25,8 @@ import sample.ds.service.provider.HelloService;
 @Component
 public class HelloServiceClient implements Runnable {
 
-    private HelloService helloService;
+    @Reference
+    HelloService helloService;
 
     private Thread thread;
 
@@ -51,9 +52,4 @@ public class HelloServiceClient implements Runnable {
         }
     }
 
-    @Reference
-    public void setHelloService(HelloService helloService) {
-        this.helloService = helloService;
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/c615578e/samples/ds/service-provider/README.md
----------------------------------------------------------------------
diff --git a/samples/ds/service-provider/README.md b/samples/ds/service-provider/README.md
index 94066f1..a97bee8 100644
--- a/samples/ds/service-provider/README.md
+++ b/samples/ds/service-provider/README.md
@@ -1,35 +1,26 @@
-== karaf-boot-sample-service-provider-ds ==
+== karaf-boot-sample-ds-service-provider ==
 
-This sample exposes an OSGi service using the Karaf util classe and annotation.
+Exposes and configures a service using declarative services
 
 = Design
 
-The service "contract" is describe by the Hello interface. It's a very simple service that
expose one operation (hello).
-The service client send a message (String) to the hello service and he gets a response.
+The service "contract" is described by the Hello interface. It's a very simple service that
expose one operation (hello).
+The service client sends a message (String) to the hello service and he gets a response.
 
-The HelloServiceImpl is very simple: it prefixes the message with "Hello".
+Additionally the example shows how to inject configuration into a service by using the type
safe configurations of DS 1.3.
 
-We use the @Component DS annotation on HelloServiceImpl implementation in order to expose
the service.
+The HelloServiceImpl is very simple: it prefixes the message with "Hello" and adds the configured
name.
 
-You don't think anything else: karaf-boot will generate all the plumbing for you, and you
will directly have a ready
-to use artifact.
+We use the @Component DS annotation on HelloServiceImpl implementation in order to expose
the service.
 
 = Build
 
-To build, simply do:
-
   mvn clean install
 
 = Deploy
 
-To deploy in Karaf, you have to enable the DS support first. For that, you have to install
the scr feature:
+We enable DS support and install the example
 
   feature:install scr
+  bundle:install -s mvn:org.apache.karaf.boot/karaf-boot-sample-service-provider-ds/1.0
 
-Once scr feature installed:
-
-* you can drop the generated jar file (target/karaf-boot-sample-service-provider-ds-1.0.jar)
in the
-Karaf deploy folder
-* in the Karaf shell console, do:
-
-  bundle:install -s mvn:org.apache.karaf.boot/karaf-boot-sample-service-provider-ds/1.0
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/c615578e/samples/ds/service-provider/pom.xml
----------------------------------------------------------------------
diff --git a/samples/ds/service-provider/pom.xml b/samples/ds/service-provider/pom.xml
index 3340b34..f24cb81 100644
--- a/samples/ds/service-provider/pom.xml
+++ b/samples/ds/service-provider/pom.xml
@@ -22,7 +22,7 @@
     <modelVersion>4.0.0</modelVersion>
 
     <groupId>org.apache.karaf.boot</groupId>
-    <artifactId>karaf-boot-sample-service-provider-ds</artifactId>
+    <artifactId>karaf-boot-sample-ds-service-provider</artifactId>
     <version>1.0.0-SNAPSHOT</version>
 
     <dependencies>

http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/c615578e/samples/ds/service-provider/src/main/java/sample/ds/service/provider/HelloServiceImpl.java
----------------------------------------------------------------------
diff --git a/samples/ds/service-provider/src/main/java/sample/ds/service/provider/HelloServiceImpl.java
b/samples/ds/service-provider/src/main/java/sample/ds/service/provider/HelloServiceImpl.java
index 5319a47..c316a3f 100644
--- a/samples/ds/service-provider/src/main/java/sample/ds/service/provider/HelloServiceImpl.java
+++ b/samples/ds/service-provider/src/main/java/sample/ds/service/provider/HelloServiceImpl.java
@@ -16,16 +16,36 @@
  */
 package sample.ds.service.provider;
 
+import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
+import org.osgi.service.metatype.annotations.Designate;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
 
 /**
  * Simple implementation of the hello service..
  */
 @Component
+@Designate(ocd = SampleConfig.class)
 public class HelloServiceImpl implements HelloService {
 
+    private String name;
+
     public String hello(String message) {
-        return "Hello " + message + " !";
+        return String.format("Hello %s my name is %s!", message, name);
+    }
+    
+    @Activate
+
+    public void activate(SampleConfig sampleConfig) {
+        this.name = sampleConfig.name();
     }
 
+
 }
+
+@ObjectClassDefinition(name = "Sample Configuration", pid = "org.apache.karaf.boot.sample.config")
+@interface SampleConfig {
+    String name() default "default";
+    int intProperty() default 0;
+    boolean booleanProperty() default false;
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/c615578e/samples/ds/shell/pom.xml
----------------------------------------------------------------------
diff --git a/samples/ds/shell/pom.xml b/samples/ds/shell/pom.xml
index 1df8632..20c8cd3 100644
--- a/samples/ds/shell/pom.xml
+++ b/samples/ds/shell/pom.xml
@@ -22,7 +22,7 @@
     <modelVersion>4.0.0</modelVersion>
 
     <groupId>org.apache.karaf.boot</groupId>
-    <artifactId>karaf-boot-sample-shell</artifactId>
+    <artifactId>karaf-boot-sample-ds-shell</artifactId>
     <version>1.0.0-SNAPSHOT</version>
 
     <dependencies>


Mime
View raw message