geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [geode] branch develop updated: GEODE-6295: Extract default from CollectingServiceLoader interface
Date Fri, 15 Mar 2019 16:13:47 GMT
This is an automated email from the ASF dual-hosted git repository.

klund pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new 8fed2fe  GEODE-6295: Extract default from CollectingServiceLoader interface
8fed2fe is described below

commit 8fed2fe49220029d8b5beac3254c787f734347dc
Author: Kirk Lund <klund@apache.org>
AuthorDate: Thu Mar 14 13:22:14 2019 -0700

    GEODE-6295: Extract default from CollectingServiceLoader interface
    
    Move CollectingServiceLoader to org.apache.geode.internal.util.
    
    Add javadocs.
    
    Extract default from CollectingServiceLoader interface to
    ListCollectingServiceLoader.
---
 .../metrics/CacheLifecycleMetricsSession.java      |  4 ++-
 .../internal/metrics/CollectingServiceLoader.java  | 29 -----------------
 .../internal/util/CollectingServiceLoader.java     | 37 ++++++++++++++++++++++
 .../internal/util/ListCollectingServiceLoader.java | 36 +++++++++++++++++++++
 .../CacheLifecycleMetricsSessionBuilderTest.java   |  1 +
 5 files changed, 77 insertions(+), 30 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/internal/metrics/CacheLifecycleMetricsSession.java
b/geode-core/src/main/java/org/apache/geode/internal/metrics/CacheLifecycleMetricsSession.java
index a621185..250616d 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/metrics/CacheLifecycleMetricsSession.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/metrics/CacheLifecycleMetricsSession.java
@@ -24,6 +24,8 @@ import org.apache.geode.annotations.VisibleForTesting;
 import org.apache.geode.internal.cache.CacheLifecycleListener;
 import org.apache.geode.internal.cache.GemFireCacheImpl;
 import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.util.CollectingServiceLoader;
+import org.apache.geode.internal.util.ListCollectingServiceLoader;
 import org.apache.geode.metrics.MetricsPublishingService;
 import org.apache.geode.metrics.MetricsSession;
 
@@ -86,7 +88,7 @@ public class CacheLifecycleMetricsSession implements MetricsSession, CacheLifecy
 
   public static class Builder {
 
-    private CollectingServiceLoader serviceLoader = new CollectingServiceLoader() {};
+    private CollectingServiceLoader serviceLoader = new ListCollectingServiceLoader();
     private CacheLifecycle cacheLifecycle = new CacheLifecycle() {};
 
     private Builder() {
diff --git a/geode-core/src/main/java/org/apache/geode/internal/metrics/CollectingServiceLoader.java
b/geode-core/src/main/java/org/apache/geode/internal/metrics/CollectingServiceLoader.java
deleted file mode 100644
index c5cbd69..0000000
--- a/geode-core/src/main/java/org/apache/geode/internal/metrics/CollectingServiceLoader.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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.geode.internal.metrics;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.ServiceLoader;
-
-interface CollectingServiceLoader {
-
-  default <S> Collection<S> loadServices(Class<S> service) {
-    List<S> services = new ArrayList<>();
-    ServiceLoader.load(service).iterator().forEachRemaining(services::add);
-    return services;
-  }
-}
diff --git a/geode-core/src/main/java/org/apache/geode/internal/util/CollectingServiceLoader.java
b/geode-core/src/main/java/org/apache/geode/internal/util/CollectingServiceLoader.java
new file mode 100644
index 0000000..0b98c3b
--- /dev/null
+++ b/geode-core/src/main/java/org/apache/geode/internal/util/CollectingServiceLoader.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.geode.internal.util;
+
+import java.util.Collection;
+import java.util.ServiceLoader;
+
+/**
+ * Loads and returns a collection of all currently loadable implementations of the given
service
+ * interface using {@link ServiceLoader}.
+ */
+public interface CollectingServiceLoader {
+
+  /**
+   * Loads and returns a collection of all currently loadable implementations of the given
service
+   * interface.
+   *
+   * @param service the service interface
+   * @param <S> the class of the service interface to load implementations of
+   * @return a collection of instantiated implementations of the given service interface
+   */
+  <S> Collection<S> loadServices(Class<S> service);
+}
diff --git a/geode-core/src/main/java/org/apache/geode/internal/util/ListCollectingServiceLoader.java
b/geode-core/src/main/java/org/apache/geode/internal/util/ListCollectingServiceLoader.java
new file mode 100644
index 0000000..03fc697
--- /dev/null
+++ b/geode-core/src/main/java/org/apache/geode/internal/util/ListCollectingServiceLoader.java
@@ -0,0 +1,36 @@
+/*
+ * 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.geode.internal.util;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.ServiceLoader;
+
+/**
+ * Implements {@link CollectingServiceLoader} by returning a {@link List} of all currently
loadable
+ * implementations of the given service interface.
+ */
+public class ListCollectingServiceLoader implements CollectingServiceLoader {
+
+  @Override
+  public <S> Collection<S> loadServices(Class<S> service) {
+    List<S> services = new ArrayList<>();
+    ServiceLoader.load(service).iterator().forEachRemaining(services::add);
+    return services;
+  }
+}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/metrics/CacheLifecycleMetricsSessionBuilderTest.java
b/geode-core/src/test/java/org/apache/geode/internal/metrics/CacheLifecycleMetricsSessionBuilderTest.java
index d8f5dbb..dcc6b37 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/metrics/CacheLifecycleMetricsSessionBuilderTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/metrics/CacheLifecycleMetricsSessionBuilderTest.java
@@ -29,6 +29,7 @@ import org.junit.Test;
 
 import org.apache.geode.internal.metrics.CacheLifecycleMetricsSession.Builder;
 import org.apache.geode.internal.metrics.CacheLifecycleMetricsSession.CacheLifecycle;
+import org.apache.geode.internal.util.CollectingServiceLoader;
 import org.apache.geode.metrics.MetricsPublishingService;
 
 public class CacheLifecycleMetricsSessionBuilderTest {


Mime
View raw message