From b65cd89989ead7082089bf6f333e56b03f619606 Mon Sep 17 00:00:00 2001 From: Jan Srnicek Date: Thu, 13 Jul 2017 20:21:01 +0200 Subject: HONEYCOMB-360 - Restconf Northbound Intefaces provider separation - Restconf configuration included under restconf.json Change-Id: I45f503d3ef383bd6e3d356308d3212c7314b7a28 Signed-off-by: Jan Srnicek --- .../distro/activation/ActiveModuleProvider.java | 26 ++++++++-------------- 1 file changed, 9 insertions(+), 17 deletions(-) (limited to 'infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/activation/ActiveModuleProvider.java') diff --git a/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/activation/ActiveModuleProvider.java b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/activation/ActiveModuleProvider.java index d31024ce9..a373bf636 100644 --- a/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/activation/ActiveModuleProvider.java +++ b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/activation/ActiveModuleProvider.java @@ -20,6 +20,8 @@ import com.google.common.collect.ImmutableList; import com.google.inject.Inject; import com.google.inject.Module; import com.google.inject.Provider; +import io.fd.honeycomb.infra.distro.schema.ResourceLoader; + import java.io.File; import java.io.IOException; import java.net.URI; @@ -27,7 +29,7 @@ import java.net.URISyntaxException; import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Set; @@ -40,7 +42,7 @@ import org.slf4j.LoggerFactory; /** * Provides list of active modules for distribution */ -class ActiveModuleProvider implements Provider { +public class ActiveModuleProvider implements Provider, ResourceLoader { private static final Logger LOG = LoggerFactory.getLogger(ActiveModuleProvider.class); @@ -50,7 +52,7 @@ class ActiveModuleProvider implements Provider { @Override public ActiveModules get() { return new ActiveModules(loadActiveModules( - aggregateResources(config.getModulesResourcePath(), Thread.currentThread().getContextClassLoader()))); + aggregateResources(config.getModulesResourcePath()))); } /** @@ -77,20 +79,10 @@ class ActiveModuleProvider implements Provider { /** * Aggregate all resources from provided relative path into a {@code List} */ - public static List aggregateResources(final String relativePath, final ClassLoader classLoader) { - try { - return Collections.list(classLoader.getResources(relativePath)).stream() - .map(ActiveModuleProvider::toURI) - .flatMap(ActiveModuleProvider::folderToFile) - .map(File::toURI) - .map(Paths::get) - // readAll lines and add them to iteration - .flatMap(ActiveModuleProvider::readLines) - .collect(Collectors.toList()); - } catch (IOException e) { - LOG.error("Unable to load resources from relative path {}", relativePath, e); - throw new IllegalStateException("Unable to load resources from relative path " + relativePath, e); - } + public List aggregateResources(final String relativePath) { + // must use universal approach of loading from folder/jar + // because of memory footprint benchmark + return new ArrayList<>(loadResourceContentsOnPath(relativePath)); } private static Stream folderToFile(final URI uri) { -- cgit 1.2.3-korg