@Override public List<ConfigGroup> getConfiguration(final ConfigType type, final String namespace) { if (!type.hasNamespace() && namespace != null && !namespace.isEmpty()) { throw new RuntimeException("The ConfigType " + type.toString() + " does not support namespaces."); } if (configGroupsByTypeWithNamespace.containsKey(type)) { final Map<String, List<ConfigGroup>> configGroupsByNamespace = configGroupsByTypeWithNamespace.get(type); if (configGroupsByNamespace.containsKey(namespace)) { return configGroupsByNamespace.get(namespace); } } final Path typeDir = ioService.get(systemRepository.getUri()).resolve(type.getDir()); final Path namespaceDir = typeDir.resolve(namespace); final List<ConfigGroup> configGroups = getConfiguration(namespaceDir, type); if (configGroups != null) { if (!configGroupsByTypeWithNamespace.containsKey(type)) { configGroupsByTypeWithNamespace.put(type, new ConcurrentHashMap<>()); } final Map<String, List<ConfigGroup>> configGroupsByNamespace = configGroupsByTypeWithNamespace.get(type); configGroupsByNamespace.put(namespace, configGroups); } else { return Collections.emptyList(); } return configGroups; }
@Override public List<ConfigGroup> getConfiguration(final ConfigType type) { if (type.hasNamespace()) { throw new RuntimeException("The ConfigType " + type.toString() + " requires a namespace."); } if (configGroupsByTypeWithoutNamespace.containsKey(type)) { return configGroupsByTypeWithoutNamespace.get(type); } final Path typeDir = ioService.get(systemRepository.getUri()).resolve(type.getDir()); final List<ConfigGroup> configGroups = getConfiguration(typeDir, type); if (configGroups != null) { configGroupsByTypeWithoutNamespace.put(type, configGroups); } else { return Collections.emptyList(); } return configGroups; }
@Override public Map<String, List<ConfigGroup>> getConfigurationByNamespace(final ConfigType type) { if (!type.hasNamespace()) { throw new RuntimeException("The ConfigType " + type.toString() + " does not support namespaces."); } final Path typeDir = ioService.get(systemRepository.getUri()).resolve(type.getDir()); if (!ioService.exists(typeDir)) { return Collections.emptyMap(); } final DirectoryStream<Path> foundNamespaces = getDirectoryStreamForDirectories(typeDir); // Force cache update for all namespaces in that type final Iterator<Path> it = foundNamespaces.iterator(); while (it.hasNext()) { final String namespace = Paths.convert(it.next()).getFileName(); getConfiguration(type, namespace); } // Return the updated cache return configGroupsByTypeWithNamespace.get(type); }