Author: pderop
Date: Wed Jun 21 22:51:56 2017
New Revision: 1799529
URL: http://svn.apache.org/viewvc?rev=1799529&view=rev
Log:
FELIX-5653: Simplify DM-Lambda samples
Added:
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/HelloClient.java
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/HelloService.java
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/HelloServiceImpl.java
Removed:
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/Configuration.java
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/Configurator.java
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/ServiceConsumer.java
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/ServiceProvider.java
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/ServiceProviderImpl.java
Modified:
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/compositefactory/Activator.java
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/device/Activator.java
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/device/DeviceAccessImpl.java
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/dictionary/Activator.java
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/future/PageLinksImpl.java
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/Activator.java
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/README
Modified:
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/compositefactory/Activator.java
URL:
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/compositefactory/Activator.java?rev=1799529&r1=1799528&r2=1799529&view=diff
==============================================================================
---
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/compositefactory/Activator.java
(original)
+++
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/compositefactory/Activator.java
Wed Jun 21 22:51:56 2017
@@ -45,7 +45,7 @@ public class Activator extends Dependenc
public void init(BundleContext ctx, DependencyManager dm) throws Exception
{
out.println("type \"log warn\" to see the logs emitted by this test.");
- // Create the Factory used to instantiate ProvuderImpl,
ProviderComposite1 and ProviderComposite2
+ // Create the Factory used to instantiate ProviderImpl,
ProviderComposite1 and ProviderComposite2
ProviderFactory factory = new ProviderFactory();
// Define the component which implementation is instantiated by the
ProviderFactory.
@@ -55,9 +55,9 @@ public class Activator extends Dependenc
component(comp -> comp
.factory(factory::create, factory::getComposition)
.withSvc(LogService.class, svc ->
svc.required().add(ProviderImpl::bind).add(ProviderComposite1::bind))
- .withCnf(conf -> conf.update(MyConfig.class, factory::updated)));
+ .withCnf(cnf -> cnf.update(MyConfig.class, factory::updated)));
- // Creates a configuration with pid name =
"org.apache.felix.dependencymanager.lambda.samples.compositefactory.ProviderFactory"
+ // Creates a configuration with pid name =
"org.apache.felix.dependencymanager.lambda.samples.compositefactory.MyConfig"
component(comp ->
comp.impl(Configurator.class).withSvc(ConfigurationAdmin.class, true));
}
}
Modified:
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/device/Activator.java
URL:
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/device/Activator.java?rev=1799529&r1=1799528&r2=1799529&view=diff
==============================================================================
---
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/device/Activator.java
(original)
+++
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/device/Activator.java
Wed Jun 21 22:51:56 2017
@@ -47,7 +47,7 @@ public class Activator extends Dependenc
component(comp -> comp
.impl(DeviceAccessConsumer.class)
.withSvc(LogService.class, true)
- .withSvc(DeviceAccess.class, device ->
device.required().add(DeviceAccessConsumer::add)));
+ .withSvc(DeviceAccess.class, svc ->
svc.required().add(DeviceAccessConsumer::add)));
}
private void createDeviceAndParameter(int id) {
Modified:
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/device/DeviceAccessImpl.java
URL:
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/device/DeviceAccessImpl.java?rev=1799529&r1=1799528&r2=1799529&view=diff
==============================================================================
---
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/device/DeviceAccessImpl.java
(original)
+++
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/device/DeviceAccessImpl.java
Wed Jun 21 22:51:56 2017
@@ -35,7 +35,7 @@ public class DeviceAccessImpl implements
component(c, builder -> builder
.properties("device.access.id", device.getDeviceId())
- .withSvc(DeviceParameter.class, svc -> svc.filter("(device.id=" +
device.getDeviceId() + ")")));
+ .withSvc(DeviceParameter.class, svc ->
svc.required().filter("(device.id=" + device.getDeviceId() + ")")));
}
@Override
Modified:
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/dictionary/Activator.java
URL:
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/dictionary/Activator.java?rev=1799529&r1=1799528&r2=1799529&view=diff
==============================================================================
---
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/dictionary/Activator.java
(original)
+++
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/dictionary/Activator.java
Wed Jun 21 22:51:56 2017
@@ -49,7 +49,7 @@ public class Activator extends Dependenc
aspect(DictionaryService.class, aspect -> aspect
.impl(DictionaryAspect.class)
.filter("(lang=en)").rank(10)
- .withCnf(conf -> conf.update(DictionaryAspectConfiguration.class,
DictionaryAspect::addWords))
+ .withCnf(cnf -> cnf.update(DictionaryAspectConfiguration.class,
DictionaryAspect::addWords))
.withSvc(LogService.class, true));
// Create the SpellChecker component. It depends on all available
DictionaryService instances, possibly
Modified:
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/future/PageLinksImpl.java
URL:
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/future/PageLinksImpl.java?rev=1799529&r1=1799528&r2=1799529&view=diff
==============================================================================
---
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/future/PageLinksImpl.java
(original)
+++
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/future/PageLinksImpl.java
Wed Jun 21 22:51:56 2017
@@ -53,7 +53,8 @@ public class PageLinksImpl implements Pa
void init(Component c) {
// asynchronously download the content of the URL specified in the
constructor.
- CompletableFuture<List<String>> futureLinks =
CompletableFuture.supplyAsync(() -> download(m_url))
+ CompletableFuture<List<String>> futureLinks = CompletableFuture
+ .supplyAsync(() -> download(m_url))
.thenApply(this::parseLinks);
// Add the future dependency so we'll be started once the
CompletableFuture "futureLinks" has completed.
Modified:
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/Activator.java
URL:
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/Activator.java?rev=1799529&r1=1799528&r2=1799529&view=diff
==============================================================================
---
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/Activator.java
(original)
+++
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/Activator.java
Wed Jun 21 22:51:56 2017
@@ -18,48 +18,27 @@
*/
package org.apache.felix.dm.lambda.samples.hello;
-import static java.lang.System.out;
-
import org.apache.felix.dm.DependencyManager;
import org.apache.felix.dm.lambda.DependencyManagerActivator;
import org.osgi.framework.BundleContext;
-import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.service.event.EventAdmin;
import org.osgi.service.log.LogService;
/**
* Hello world example.
- *
- * @author <a href="mailto:[email protected]">Felix Project Team</a>
*/
public class Activator extends DependencyManagerActivator {
+
@Override
- public void init(BundleContext ctx, DependencyManager dm) throws Exception
{
- out.println("type \"log warn\" to see the logs emitted by this test.");
-
- // Creates a component that populates some properties in the
Configuration Admin.
- // Here, we inject the CM (Configuration Admin) service dependency
using a method reference:
-
- component(comp -> comp.factory(() -> new
Configurator(Configuration.class.getName()))
- .withSvc(ConfigurationAdmin.class, svc ->
svc.required().add(Configurator::bind)));
+ public void init(BundleContext ctx, DependencyManager dm) throws Exception
{
+ // Declare the Hello service.
+ component(comp -> comp
+ .impl(HelloServiceImpl.class).provides(HelloService.class));
- // Creates a Service Provider (property names are deduced from lambda
parameter names).
- // The provider depends on a required log service, injected by
reflection on compatible class fields.
-
- component(comp -> comp.impl(ServiceProviderImpl.class)
- .provides(ServiceProvider.class, p1 -> "v1", p2 -> 123)
- .withSvc(LogService.class, true /* required */));
-
- // Creates a Service Consumer which depends on LogService, EventAdmin
and on the ServiceProvider.
- // LogService and EventAdmin are declared in one single method call,
and are injected in class fields.
- // We also depend on a configuration. the configuration callback is
assumed to be the "ServiceConsumer.updated" method which
- // takes as argument a "Configuration" interface. This interface is
used to wrap the actual properties behind a dynamic proxy
- // that is implemented by Dependency Manager.
- // The pid is assumed to be by default the fqdn of the specified
Configuration interface
("org.apache.felix.dm.lambda.samples.hello.Configuration").
-
- component(comp -> comp.impl(ServiceConsumer.class)
- .withSvc(true /* required */, LogService.class, EventAdmin.class)
- .withSvc(ServiceProvider.class, "(p1=v1)", true /* required */)
- .withCnf(Configuration.class));
+ // Declare an HelloClient component depending on the HelloService, and
on LogService
+ component(comp -> comp
+ .impl(HelloClient.class)
+ .withSvc(HelloService.class, svc ->
svc.required().add(HelloClient::bind))
+ .withSvc(LogService.class, svc -> svc.optional()));
}
+
}
Added:
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/HelloClient.java
URL:
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/HelloClient.java?rev=1799529&view=auto
==============================================================================
---
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/HelloClient.java
(added)
+++
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/HelloClient.java
Wed Jun 21 22:51:56 2017
@@ -0,0 +1,59 @@
+/*
+ * 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 org.apache.felix.dm.lambda.samples.hello;
+
+import org.osgi.service.log.LogService;
+
+/**
+ * Our HelloClient, which has a required dependency on the HelloService
service, as well as an optional
+ * dependency on the OSGi LogService. The LogService is injected on compatible
class fields and a NullObject
+ * will be injected in case there is no LogService currently available.
+ */
+public class HelloClient {
+
+ /**
+ * Injected by Dependency Manager, possibly as a null object in case
the dependency is unavailable.
+ */
+ volatile LogService m_log;
+
+ /**
+ * Injected by Dependency Manager.
+ * @param hello the required HelloService instance
+ */
+ void bind(HelloService hello) {
+ m_log.log(LogService.LOG_DEBUG, "bound hello service.");
+ System.out.println("HelloClient bound with HelloService: saying
hello: " + hello.sayHello());
+ }
+
+ /**
+ * Our component is starting, it has been injected with the required
HelloService, as well as the LogService,
+ * which is injected in the m_log class field (possibly with a
NullObject in case the LogService is unavailable).
+ */
+ void start() {
+ System.out.println("HelliClient started");
+ }
+
+ /**
+ * Our component is stopping, it has possibly lost the required
HelloService, or our bundle is being stopped.
+ */
+ void stop() {
+ System.out.println("HelloClient stopped");
+ }
+
+}
Added:
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/HelloService.java
URL:
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/HelloService.java?rev=1799529&view=auto
==============================================================================
---
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/HelloService.java
(added)
+++
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/HelloService.java
Wed Jun 21 22:51:56 2017
@@ -0,0 +1,23 @@
+/*
+ * 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 org.apache.felix.dm.lambda.samples.hello;
+
+public interface HelloService {
+ String sayHello();
+}
Added:
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/HelloServiceImpl.java
URL:
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/HelloServiceImpl.java?rev=1799529&view=auto
==============================================================================
---
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/HelloServiceImpl.java
(added)
+++
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/HelloServiceImpl.java
Wed Jun 21 22:51:56 2017
@@ -0,0 +1,37 @@
+/*
+ * 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 org.apache.felix.dm.lambda.samples.hello;
+
+/**
+ * The implementation for our HelloService interface.
+ */
+public class HelloServiceImpl implements HelloService {
+
+ /**
+ * Our component is starting.
+ */
+ void start() {
+ System.out.println("Hello service starting");
+ }
+
+ @Override
+ public String sayHello() {
+ return "hello !";
+ }
+}
Modified:
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/README
URL:
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/README?rev=1799529&r1=1799528&r2=1799529&view=diff
==============================================================================
---
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/README
(original)
+++
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/README
Wed Jun 21 22:51:56 2017
@@ -15,15 +15,14 @@
* limitations under the License.
*/
-This sample provides a DM Activator declaring one service consumer and a
service provider. The
-ServiceConsumer is also depending on a configuration pid (see
org.apache.felix.dependencymanager.samples.hello.Configurator).
-To see logs, just type this under gogo shell:
-
-g! log info|grep hello.annot
-
-and you should see the following logs:
-
-2016.02.01 10:12:02 INFO - Bundle:
org.apache.felix.dependencymanager.lambda.samples.hello -
ServiceProviderImpl.hello
-2016.02.01 10:12:02 INFO - Bundle:
org.apache.felix.dependencymanager.lambda.samples.hello -
ServiceConsumer.start: calling service.hello()
+This sample provides a DM Activator declaring an "HelloService" on which an
HelloClient component is depending on.
+The HelloClient component also optionally depends on the LogService, which is
injected as a NullObject in case
+no LogService is currently available.
+
+Run the hello.bndrun and you should see the following output:
+
+Hello service starting
+HelloClient bound with HelloService.
+hello !