You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by cs...@apache.org on 2021/03/03 16:44:06 UTC

[aries-component-dsl] 06/09: Add configuration holder

This is an automated email from the ASF dual-hosted git repository.

csierra pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/aries-component-dsl.git

commit f6dc866ecc292a901a8a2c0af4e9b43d8d27c9f3
Author: Carlos Sierra Andrés <ca...@liferay.com>
AuthorDate: Tue Mar 2 15:59:47 2021 +0100

    Add configuration holder
---
 .../java/org/apache/aries/component/dsl/OSGi.java  |  5 +-
 .../dsl/configuration/ConfigurationHolder.java     | 37 ++++++++++
 .../component/dsl/configuration/package-info.java  | 20 ++++++
 .../dsl/internal/ConfigurationHolderImpl.java      | 78 ++++++++++++++++++++++
 .../dsl/internal/ConfigurationOSGiImpl.java        | 12 +++-
 .../dsl/internal/ConfigurationsOSGiImpl.java       | 21 ++++--
 6 files changed, 162 insertions(+), 11 deletions(-)

diff --git a/component-dsl/src/main/java/org/apache/aries/component/dsl/OSGi.java b/component-dsl/src/main/java/org/apache/aries/component/dsl/OSGi.java
index 9da249a..4476539 100644
--- a/component-dsl/src/main/java/org/apache/aries/component/dsl/OSGi.java
+++ b/component-dsl/src/main/java/org/apache/aries/component/dsl/OSGi.java
@@ -18,6 +18,7 @@
 
 package org.apache.aries.component.dsl;
 
+import org.apache.aries.component.dsl.configuration.ConfigurationHolder;
 import org.apache.aries.component.dsl.function.Function10;
 import org.apache.aries.component.dsl.function.Function14;
 import org.apache.aries.component.dsl.function.Function16;
@@ -297,7 +298,7 @@ public interface OSGi<T> extends OSGiRunnable<T> {
 		).map(
 			UpdateTuple::getT
 		).map(
-			Configuration::getProperties
+			ConfigurationHolder::getUpdatedProperties
 		);
 	}
 
@@ -308,7 +309,7 @@ public interface OSGi<T> extends OSGiRunnable<T> {
 		).map(
 			UpdateTuple::getT
 		).map(
-			Configuration::getProperties
+			ConfigurationHolder::getUpdatedProperties
 		);
 	}
 
diff --git a/component-dsl/src/main/java/org/apache/aries/component/dsl/configuration/ConfigurationHolder.java b/component-dsl/src/main/java/org/apache/aries/component/dsl/configuration/ConfigurationHolder.java
new file mode 100644
index 0000000..f114fb1
--- /dev/null
+++ b/component-dsl/src/main/java/org/apache/aries/component/dsl/configuration/ConfigurationHolder.java
@@ -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.aries.component.dsl.configuration;
+
+import java.util.Dictionary;
+
+public interface ConfigurationHolder {
+
+    String getPid();
+
+    Dictionary<String, ?> getProperties();
+
+    String getFactoryPid();
+
+    long getChangeCount();
+
+    void refresh();
+
+    long getUpdatedChangeCount();
+
+    Dictionary<String, ?> getUpdatedProperties();
+}
diff --git a/component-dsl/src/main/java/org/apache/aries/component/dsl/configuration/package-info.java b/component-dsl/src/main/java/org/apache/aries/component/dsl/configuration/package-info.java
new file mode 100644
index 0000000..d7fd4d3
--- /dev/null
+++ b/component-dsl/src/main/java/org/apache/aries/component/dsl/configuration/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+@org.osgi.annotation.bundle.Export
+@org.osgi.annotation.versioning.Version("1.0.0")
+package org.apache.aries.component.dsl.configuration;
diff --git a/component-dsl/src/main/java/org/apache/aries/component/dsl/internal/ConfigurationHolderImpl.java b/component-dsl/src/main/java/org/apache/aries/component/dsl/internal/ConfigurationHolderImpl.java
new file mode 100644
index 0000000..891c27d
--- /dev/null
+++ b/component-dsl/src/main/java/org/apache/aries/component/dsl/internal/ConfigurationHolderImpl.java
@@ -0,0 +1,78 @@
+/*
+ * 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.aries.component.dsl.internal;
+
+import org.apache.aries.component.dsl.configuration.ConfigurationHolder;
+import org.osgi.service.cm.Configuration;
+
+import java.util.Dictionary;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.atomic.AtomicReference;
+
+public class ConfigurationHolderImpl implements ConfigurationHolder {
+
+    private Configuration configuration;
+    private AtomicReference<Dictionary<String, ?>> properties;
+    private AtomicLong changeCount = new AtomicLong(-1);
+
+    public ConfigurationHolderImpl(Configuration configuration) {
+        this.configuration = configuration;
+    }
+
+    @Override
+    public String getPid() {
+        return configuration.getPid();
+    }
+
+    @Override
+    public Dictionary<String, ?> getProperties() {
+        properties.compareAndSet(null, configuration.getProperties());
+
+        return properties.get();
+    }
+
+    @Override
+    public String getFactoryPid() {
+        return configuration.getFactoryPid();
+    }
+
+    @Override
+    public long getChangeCount() {
+        changeCount.compareAndSet(-1, configuration.getChangeCount());
+
+        return changeCount.get();
+    }
+
+    @Override
+    public void refresh() {
+        changeCount.set(-1);
+
+        properties.set(null);
+    }
+
+    @Override
+    public long getUpdatedChangeCount() {
+        return configuration.getChangeCount();
+    }
+
+    @Override
+    public Dictionary<String, ?> getUpdatedProperties() {
+        return configuration.getProperties();
+    }
+
+}
diff --git a/component-dsl/src/main/java/org/apache/aries/component/dsl/internal/ConfigurationOSGiImpl.java b/component-dsl/src/main/java/org/apache/aries/component/dsl/internal/ConfigurationOSGiImpl.java
index 6ac0a90..7080fb7 100644
--- a/component-dsl/src/main/java/org/apache/aries/component/dsl/internal/ConfigurationOSGiImpl.java
+++ b/component-dsl/src/main/java/org/apache/aries/component/dsl/internal/ConfigurationOSGiImpl.java
@@ -18,6 +18,7 @@
 package org.apache.aries.component.dsl.internal;
 
 import org.apache.aries.component.dsl.OSGiResult;
+import org.apache.aries.component.dsl.configuration.ConfigurationHolder;
 import org.apache.aries.component.dsl.update.UpdateSelector;
 import org.apache.aries.component.dsl.update.UpdateTuple;
 import org.osgi.framework.BundleContext;
@@ -38,7 +39,7 @@ import java.util.concurrent.atomic.AtomicReference;
 /**
  * @author Carlos Sierra Andrés
  */
-public class ConfigurationOSGiImpl extends OSGiImpl<UpdateTuple<Configuration>> {
+public class ConfigurationOSGiImpl extends OSGiImpl<UpdateTuple<ConfigurationHolder>> {
 
 	public ConfigurationOSGiImpl(String pid) {
 		super((executionContext, op) -> {
@@ -109,7 +110,9 @@ public class ConfigurationOSGiImpl extends OSGiImpl<UpdateTuple<Configuration>>
 
 								terminatorAtomicReference.set(
 									op.apply(
-										new UpdateTuple<>(updateSelector, configuration)));
+										new UpdateTuple<>(
+											updateSelector,
+											new ConfigurationHolderImpl(configuration))));
 
 							});
 
@@ -138,7 +141,10 @@ public class ConfigurationOSGiImpl extends OSGiImpl<UpdateTuple<Configuration>>
                     initialCounter.set(configuration.getChangeCount());
 
                     terminatorAtomicReference.set(
-                        op.apply(new UpdateTuple<>(updateSelector, configuration)));
+                        op.apply(
+                        	new UpdateTuple<>(
+                        		updateSelector,
+								new ConfigurationHolderImpl(configuration))));
                 }
 			}
 
diff --git a/component-dsl/src/main/java/org/apache/aries/component/dsl/internal/ConfigurationsOSGiImpl.java b/component-dsl/src/main/java/org/apache/aries/component/dsl/internal/ConfigurationsOSGiImpl.java
index 7413c0e..e91d373 100644
--- a/component-dsl/src/main/java/org/apache/aries/component/dsl/internal/ConfigurationsOSGiImpl.java
+++ b/component-dsl/src/main/java/org/apache/aries/component/dsl/internal/ConfigurationsOSGiImpl.java
@@ -18,6 +18,7 @@
 package org.apache.aries.component.dsl.internal;
 
 import org.apache.aries.component.dsl.OSGiResult;
+import org.apache.aries.component.dsl.configuration.ConfigurationHolder;
 import org.apache.aries.component.dsl.update.UpdateSelector;
 import org.apache.aries.component.dsl.update.UpdateTuple;
 import org.osgi.framework.BundleContext;
@@ -38,7 +39,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
 /**
  * @author Carlos Sierra Andrés
  */
-public class ConfigurationsOSGiImpl extends OSGiImpl<UpdateTuple<Configuration>> {
+public class ConfigurationsOSGiImpl extends OSGiImpl<UpdateTuple<ConfigurationHolder>> {
 
 	public ConfigurationsOSGiImpl(String factoryPid) {
 		super((executionContext, op) -> {
@@ -107,7 +108,11 @@ public class ConfigurationsOSGiImpl extends OSGiImpl<UpdateTuple<Configuration>>
 							UpdateSupport.runUpdate(() -> {
 								signalLeave(pid, terminators);
 
-								terminators.put(pid, op.apply(new UpdateTuple<>(updateSelector, configuration)));
+								terminators.put(
+									pid, op.apply(
+										new UpdateTuple<>(
+											updateSelector,
+											new ConfigurationHolderImpl(configuration))));
 							});
 
 							if (closed.get()) {
@@ -129,12 +134,16 @@ public class ConfigurationsOSGiImpl extends OSGiImpl<UpdateTuple<Configuration>>
 				Configuration[] configurations = getConfigurations(
 					bundleContext, factoryPid, serviceReference);
 
-				for (Configuration c : configurations) {
-					configurationCounters.put(c.getPid(), c.getChangeCount());
+				for (Configuration configuration : configurations) {
+					configurationCounters.put(
+						configuration.getPid(), configuration.getChangeCount());
 
 					terminators.put(
-						c.getPid(),
-						op.publish(new UpdateTuple<>(updateSelector, c)));
+						configuration.getPid(),
+						op.publish(
+							new UpdateTuple<>(
+								updateSelector,
+								new ConfigurationHolderImpl(configuration))));
 				}
 			}