You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by pd...@apache.org on 2016/09/08 22:34:45 UTC
svn commit: r1759920 - in /felix/trunk/dependencymanager:
org.apache.felix.dependencymanager.lambda.itest/src/org/apache/felix/dm/lambda/itest/
org.apache.felix.dependencymanager.lambda/
org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm...
Author: pderop
Date: Thu Sep 8 22:34:45 2016
New Revision: 1759920
URL: http://svn.apache.org/viewvc?rev=1759920&view=rev
Log:
FELIX-5238: ConfigurationDependency should provide the setRequired() method.
Added:
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.itest/src/org/apache/felix/dm/lambda/itest/OptionalConfigurationTest.java
Modified:
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/bnd.bnd
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ConfigurationDependencyBuilder.java
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ConfigurationDependencyBuilderImpl.java
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/packageinfo
Added: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.itest/src/org/apache/felix/dm/lambda/itest/OptionalConfigurationTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.itest/src/org/apache/felix/dm/lambda/itest/OptionalConfigurationTest.java?rev=1759920&view=auto
==============================================================================
--- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.itest/src/org/apache/felix/dm/lambda/itest/OptionalConfigurationTest.java (added)
+++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.itest/src/org/apache/felix/dm/lambda/itest/OptionalConfigurationTest.java Thu Sep 8 22:34:45 2016
@@ -0,0 +1,151 @@
+/*
+ * 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.itest;
+
+import static org.apache.felix.dm.lambda.DependencyManagerActivator.component;
+
+import java.io.IOException;
+import java.util.Hashtable;
+import java.util.Properties;
+
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.junit.Assert;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+/**
+ * Integration test for Optional ConfigurationDependency.
+ * The following behaviors are tested:
+ *
+ * 1) an OptionalConfigurationConsumer component defines an optional configuration dependency.
+ * 2) then the component is activated: since there is no currently an available configuration, the component is called in its
+ * updated callback with a type-safe config, and the component can then be initialized using the default methods from the type-safe config interface.
+ * 3) then the configuration is registered: at this point the OptionalConfigurationConsumer is called again in its updated callback , but
+ * with the real just registered configuration. So, the component can be updated with the newly just registered config.
+ * 4) then the configuration is unregistered: at this point, the OptionalConfigurationConsumer is called again in updated callback, like in step 2).
+ * So, the component is re-initilized using the default methods from the type-safe config.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class OptionalConfigurationTest extends TestBase {
+ final static String PID = "ConfigurationDependencyTest.pid";
+
+ public void testOptionalConfigurationConsumer() {
+ DependencyManager m = getDM();
+ Ensure e = new Ensure();
+
+ ConfigurationCreator confCreate = new ConfigurationCreator(e, PID, 3);
+ Component c1 = component(m, comp -> comp.impl(confCreate).autoAdd(false).withSvc(ConfigurationAdmin.class, true));
+
+ Pojo pojo = new Pojo(e);
+ Component c2 = component(m, comp -> comp.impl(pojo).autoAdd(false).withCnf(cnf -> cnf.update(Config.class, Pojo::updated).pid(PID).optional()));
+
+ m.add(c2);
+ e.waitForStep(1, 5000); // c2 called in updated with testKey="default" config
+ e.waitForStep(2, 5000); // c2 called in start()
+ m.add(c1); // c1 registers a "testKey=testvalue" configuration, using config admin.
+ e.waitForStep(3, 5000); // c1 created the conf.
+ e.waitForStep(4, 5000); // c2 called in updated with testKey="testvalue"
+ m.remove(c1); // remove configuration.
+ e.waitForStep(5, 5000); // c2 called in updated with default "testkey=default" property (using the default method from the config interface.
+ m.remove(c2); // stop the OptionalConfigurationConsumer component
+ e.waitForStep(6, 5000); // c2 stopped
+ }
+
+
+ public static interface Config {
+ public default String getTestkey() { return "default"; }
+ }
+
+ static class Pojo {
+ protected final Ensure m_ensure;
+ protected volatile int m_updateCount;
+
+ public Pojo(Ensure e) {
+ m_ensure = e;
+ }
+
+ public void updated(Config cnf) { // optional configuration, called after start(), like any other optional dependency callbacks.
+ if (cnf != null) {
+ m_updateCount ++;
+ if (m_updateCount == 1) {
+ if (!"default".equals(cnf.getTestkey())) {
+ Assert.fail("Could not find the configured property.");
+ }
+ m_ensure.step(1);
+ } else if (m_updateCount == 2) {
+ if (!"testvalue".equals(cnf.getTestkey())) {
+ Assert.fail("Could not find the configured property.");
+ }
+ m_ensure.step(4);
+ } else if (m_updateCount == 3) {
+ if (!"default".equals(cnf.getTestkey())) {
+ Assert.fail("Could not find the configured property.");
+ }
+ m_ensure.step(5);
+ }
+ } else {
+ // configuration destroyed: should never happen
+ m_ensure.throwable(new Exception("lost configuration"));
+ }
+ }
+
+ public void start() {
+ m_ensure.step(2);
+ }
+
+ public void stop() {
+ m_ensure.step(6);
+ }
+ }
+
+ public static class ConfigurationCreator {
+ private volatile ConfigurationAdmin m_ca;
+ private final Ensure m_ensure;
+ Configuration m_conf;
+ final String m_pid;
+ final int m_initStep;
+
+ public ConfigurationCreator(Ensure e, String pid, int initStep) {
+ m_ensure = e;
+ m_pid = pid;
+ m_initStep = initStep;
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ public void init() {
+ try {
+ Assert.assertNotNull(m_ca);
+ m_ensure.step(m_initStep);
+ m_conf = m_ca.getConfiguration(m_pid, null);
+ Hashtable props = new Properties();
+ props.put("testkey", "testvalue");
+ m_conf.update(props);
+ }
+ catch (IOException e) {
+ Assert.fail("Could not create configuration: " + e.getMessage());
+ }
+ }
+
+ public void destroy() throws IOException {
+ m_conf.delete();
+ }
+ }
+}
Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/bnd.bnd
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/bnd.bnd?rev=1759920&r1=1759919&r2=1759920&view=diff
==============================================================================
--- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/bnd.bnd (original)
+++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/bnd.bnd Thu Sep 8 22:34:45 2016
@@ -16,11 +16,12 @@
#
javac.source: 1.8
javac.target: 1.8
-Bundle-Version: 1.0.1
+Bundle-Version: 1.1.0
-buildpath: \
org.apache.felix.dependencymanager;version=latest,\
osgi.core;version=6.0,\
- osgi.cmpn;version=6.0
+ osgi.cmpn;version=6.0,\
+ osgi.annotation;version=6.0.1
Export-Package: \
org.apache.felix.dm.lambda,\
org.apache.felix.dm.lambda.callbacks
Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ConfigurationDependencyBuilder.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ConfigurationDependencyBuilder.java?rev=1759920&r1=1759919&r2=1759920&view=diff
==============================================================================
--- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ConfigurationDependencyBuilder.java (original)
+++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ConfigurationDependencyBuilder.java Thu Sep 8 22:34:45 2016
@@ -31,9 +31,12 @@ import org.apache.felix.dm.lambda.callba
import org.apache.felix.dm.lambda.callbacks.InstanceCbConfigurationComponent;
import org.apache.felix.dm.lambda.callbacks.InstanceCbDictionary;
import org.apache.felix.dm.lambda.callbacks.InstanceCbDictionaryComponent;
+import org.osgi.annotation.versioning.ProviderType;
/**
* Builds a Dependency Manager Configuration Dependency.
+ * (configuration dependencies are required by default).
+ *
* Two families of callbacks are supported: <p>
*
* <ul>
@@ -147,8 +150,32 @@ import org.apache.felix.dm.lambda.callba
*
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
+@ProviderType
public interface ConfigurationDependencyBuilder extends DependencyBuilder<ConfigurationDependency> {
/**
+ * Sets the required flag which determines if this configuration dependency is required or not.
+ * A configuration dependency is required by default.
+ *
+ * @param required the required flag
+ * @return this service dependency
+ */
+ ConfigurationDependencyBuilder required(boolean required);
+
+ /**
+ * Sets the dependency as required. A configuration dependency is required by default.
+ *
+ * @return this service dependency
+ */
+ ConfigurationDependencyBuilder required();
+
+ /**
+ * Sets the dependency as optional. A configuration dependency is required by default.
+ *
+ * @return this service dependency
+ */
+ ConfigurationDependencyBuilder optional();
+
+ /**
* Sets the pid for this configuration dependency.
*
* @param pid the configuration dependency pid.
Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ConfigurationDependencyBuilderImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ConfigurationDependencyBuilderImpl.java?rev=1759920&r1=1759919&r2=1759920&view=diff
==============================================================================
--- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ConfigurationDependencyBuilderImpl.java (original)
+++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ConfigurationDependencyBuilderImpl.java Thu Sep 8 22:34:45 2016
@@ -40,6 +40,7 @@ import org.apache.felix.dm.lambda.callba
public class ConfigurationDependencyBuilderImpl implements ConfigurationDependencyBuilder {
private String m_pid;
private boolean m_propagate;
+ private boolean m_required = true;
private final Component m_component;
private String m_updateMethodName = "updated";
private Object m_updateCallbackInstance;
@@ -76,6 +77,24 @@ public class ConfigurationDependencyBuil
return this;
}
+ @Override
+ public ConfigurationDependencyBuilder required(boolean required) {
+ m_required = required;
+ return this;
+ }
+
+ @Override
+ public ConfigurationDependencyBuilder required() {
+ m_required = true;
+ return this;
+ }
+
+ @Override
+ public ConfigurationDependencyBuilder optional() {
+ m_required = false;
+ return this;
+ }
+
public ConfigurationDependencyBuilder update(String update) {
checkHasNoMethodRefs();
m_hasReflectionCallback = true;
@@ -175,6 +194,7 @@ public class ConfigurationDependencyBuil
Objects.nonNull(m_pid);
dep.setPid(pid);
dep.setPropagate(m_propagate);
+ dep.setRequired(m_required);
if (m_updateMethodName != null) {
dep.setCallback(m_updateCallbackInstance, m_updateMethodName, m_configType);
} else if (m_refs.size() > 0) {
Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/packageinfo
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/packageinfo?rev=1759920&r1=1759919&r2=1759920&view=diff
==============================================================================
--- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/packageinfo (original)
+++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/packageinfo Thu Sep 8 22:34:45 2016
@@ -1 +1 @@
-version 1.0.0
\ No newline at end of file
+version 1.1.0
\ No newline at end of file