This is an automated email from the ASF dual-hosted git repository.
sijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git
The following commit(s) were added to refs/heads/master by this push:
new f6778ab Provide a util method to run functions with metadata client
driver
f6778ab is described below
commit f6778ab7c1424bc5d71b6b52337649c0b06ae669
Author: Sijie Guo <[email protected]>
AuthorDate: Mon May 21 22:39:40 2018 -0700
Provide a util method to run functions with metadata client driver
Descriptions of the changes in this PR:
*Motivation*
Currently `MetadataDrivers` provides util methods to run functions with
metadata bookie driver.
It is convinient to provide a util method to run functions with metadata
client driver as well.
*Solution*
Provide a util method `runFunctionWithMetadataClientDriver` to run
functions with metadata client driver.
Author: Sijie Guo <[email protected]>
Reviewers: Enrico Olivelli <[email protected]>, Jia Zhai <None>
This closes #1421 from sijie/utils_to_run_client_driver
---
.../apache/bookkeeper/meta/MetadataDrivers.java | 35 ++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/MetadataDrivers.java
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/MetadataDrivers.java
index f278205..bab6d84 100644
---
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/MetadataDrivers.java
+++
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/MetadataDrivers.java
@@ -25,16 +25,19 @@ import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Sets;
import com.google.common.util.concurrent.UncheckedExecutionException;
import java.net.URI;
+import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ScheduledExecutorService;
import java.util.function.Function;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
+import org.apache.bookkeeper.conf.ClientConfiguration;
import org.apache.bookkeeper.conf.ServerConfiguration;
import org.apache.bookkeeper.discover.RegistrationManager;
import org.apache.bookkeeper.meta.exceptions.Code;
@@ -319,6 +322,38 @@ public final class MetadataDrivers {
}
/**
+ * Process the provided <i>function</i> with metadata client driver
resolved
+ * from the metadata service uri returned by {@link
ClientConfiguration#getMetadataServiceUri()}.
+ *
+ * @param conf client configuration
+ * @param function function to apply with metadata client driver.
+ * @param executorService executor service used by the metadata client
driver.
+ * @throws MetadataException when failed to access metadata store
+ * @throws ExecutionException exception thrown when processing
<tt>function</tt>.
+ */
+ public static <T> T
runFunctionWithMetadataClientDriver(ClientConfiguration conf,
+
Function<MetadataClientDriver, T> function,
+
ScheduledExecutorService executorService)
+ throws MetadataException, ExecutionException {
+ try (MetadataClientDriver driver = MetadataDrivers.getClientDriver(
+ URI.create(conf.getMetadataServiceUri())
+ )) {
+ driver.initialize(conf, executorService, NullStatsLogger.INSTANCE,
Optional.empty());
+ try {
+ return function.apply(driver);
+ } catch (Exception uee) {
+ if (uee.getCause() instanceof MetadataException) {
+ throw (MetadataException) uee.getCause();
+ } else {
+ throw new ExecutionException(uee.getMessage(),
uee.getCause());
+ }
+ }
+ } catch (ConfigurationException e) {
+ throw new MetadataException(Code.INVALID_METADATA_SERVICE_URI, e);
+ }
+ }
+
+ /**
* Process the provided <i>function</i> with metadata bookie driver
resolved
* from the metadata service uri returned by {@link
ServerConfiguration#getMetadataServiceUri()}.
*
--
To stop receiving notification emails like this one, please contact
[email protected].