You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by st...@apache.org on 2018/04/05 12:16:06 UTC
[3/5] deltaspike git commit: DELTASPIKE-1335 proposal for atomic
config access
DELTASPIKE-1335 proposal for atomic config access
crafted together with Manfred Huber
Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/fdd1e3dc
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/fdd1e3dc
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/fdd1e3dc
Branch: refs/heads/master
Commit: fdd1e3dcd9a12ceed831dd7460492b6dd788721c
Parents: 1e5003f
Author: Mark Struberg <st...@apache.org>
Authored: Wed Apr 4 13:56:03 2018 +0200
Committer: Mark Struberg <st...@apache.org>
Committed: Wed Apr 4 17:31:39 2018 +0200
----------------------------------------------------------------------
.../deltaspike/core/api/config/Config.java | 41 ++++++++++++++++++++
.../core/api/config/ConfigTransaction.java | 27 +++++++++++++
2 files changed, 68 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/fdd1e3dc/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/Config.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/Config.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/Config.java
index 47d2c50..f1fc368 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/Config.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/Config.java
@@ -42,6 +42,47 @@ public interface Config
ConfigResolver.UntypedResolver<String> resolve(String name);
/**
+ * <p>This method can be used to access multiple
+ * {@link ConfigResolver.TypedResolver} which must be consistent.
+ *
+ * <p>An example would be to access some {@code 'myapp.host'} and {@code 'myapp.port'}:
+ * The underlying values are {@code 'oldserver'} and {@code '8080'}.
+ *
+ * <pre>
+ * // get the current host value
+ * TypedResolver<String> hostCfg config.resolve("myapp.host")
+ * .cacheFor(TimeUnit.MINUTES, 60);
+ *
+ * // and right inbetween the underlying values get changed to 'newserver' and port 8082
+ *
+ * // get the current port for the host
+ * TypedResolver<Integer> portCfg config.resolve("myapp.port")
+ * .cacheFor(TimeUnit.MINUTES, 60);
+ * </pre>
+ *
+ * In ths above code we would get the combination of {@code 'oldserver'} but with the new port {@code 8081}.
+ * And this will obviously blow up because that host+port combination doesn't exist.
+ *
+ * To consistently access n different config values we can start a {@link ConfigTransaction} for those values.
+ *
+ * <pre>
+ * ConfigTransaction cfgTx = config.startTx(hostCfg, portCfg);
+ *
+ * String host = cfgTx.getValue(hostCfg);
+ * Integer port = cfgTx.getValue(portCfg);
+ * </pre>
+ *
+ * Note that there is no <em>close</em> on the transaction.
+ * They should be used as local variables inside a method.
+ * Values will not be reloaded for an open {@link ConfigTransaction}.
+ *
+ * @param typedResolvers the list of {@link ConfigResolver.TypedResolver} to be accessed in an atomic way
+ *
+ * @return a new {@link ConfigTransaction} which holds the resolved values of all the {@param typedResolvers}.
+ */
+ ConfigTransaction startTx(ConfigResolver.TypedResolver<?>... typedResolvers);
+
+ /**
* @return all the current ConfigSources for this Config
*/
ConfigSource[] getConfigSources();
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/fdd1e3dc/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigTransaction.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigTransaction.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigTransaction.java
new file mode 100644
index 0000000..22afbac
--- /dev/null
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigTransaction.java
@@ -0,0 +1,27 @@
+/*
+ * 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.deltaspike.core.api.config;
+
+/**
+ * A value holder for
+ */
+public interface ConfigTransaction
+{
+ <T> T getValue(ConfigResolver.TypedResolver<T> typedResolver);
+}