@Test public void testZookeeperLoad() { ConfigScan.scan(); ServerConfigLoader loader = new ServerConfigLoader(); loader.load(ConfigLoader.Context::new, (context, config) -> { System.out.println("config:---->" + config); if (config != null) { if (StringUtils.isNotBlank(config.getConfigMode())) { String configMode = config.getConfigMode(); if (configMode.equals("zookeeper")) { new ZookeeperConfigLoader(client).load(context, this::assertTest); } } } }); }
private void zookeeperLoad(final Supplier<Context> context, final LoaderHandler<ZookeeperConfig> handler, final ZookeeperConfig config) { if (config != null) { check(config); if (Objects.isNull(client)) { client = CuratorZookeeperClient.getInstance(config); } if (config.isUpdate()) { client.persist(config.getPath(), FileUtils.readYAML(config.getUpdateFileName())); } InputStream result = client.pull(config.getPath()); String fileExtension = config.getFileExtension(); PropertyLoader propertyLoader = LOADERS.get(fileExtension); if (propertyLoader == null) { throw new ConfigException("zookeeper.fileExtension setting error, The loader was not found"); } Optional.ofNullable(result) .map(e -> propertyLoader.load("remote.zookeeper." + fileExtension, e)) .ifPresent(e -> context.get().getOriginal().load(() -> context.get().withSources(e), this::zookeeperFinish)); handler.finish(context, config); try { client.addListener(context, (c1, c2) -> this.passive(c1, null, c2), config); } catch (Exception e) { LOGGER.error("passive zookeeper remote started error...."); } } else { throw new ConfigException("zookeeper config is null"); } }
ZookeeperConfigLoader implements ConfigLoader<ZookeeperConfig> { private void zookeeperLoad(final Supplier<Context> context, final LoaderHandler<ZookeeperConfig> handler, final ZookeeperConfig config) { if (config != null) { check(config); if (Objects.isNull(client)) { client = CuratorZookeeperClient.getInstance(config); } if (config.isUpdate()) { client.persist(config.getPath(), FileUtils.readYAML(config.getUpdateFileName())); } InputStream result = client.pull(config.getPath()); String fileExtension = config.getFileExtension(); PropertyLoader propertyLoader = LOADERS.get(fileExtension); if (propertyLoader == null) { throw new ConfigException("zookeeper.fileExtension setting error, The loader was not found"); } Optional.ofNullable(result) .map(e -> propertyLoader.load("remote.zookeeper." + fileExtension, e)) .ifPresent(e -> context.get().getOriginal().load(() -> context.get().withSources(e), this::zookeeperFinish)); handler.finish(context, config); try { client.addListener(context, (c1, c2) -> this.passive(c1, null, c2), config); } catch (Exception e) { LOGGER.error("passive zookeeper remote started error...."); } } else { throw new ConfigException("zookeeper config is null"); } } }
ZookeeperConfigLoader implements ConfigLoader<ZookeeperConfig> { private void zookeeperLoad(final Supplier<Context> context, final LoaderHandler<ZookeeperConfig> handler, final ZookeeperConfig config) { if (config != null) { check(config); if (Objects.isNull(client)) { client = CuratorZookeeperClient.getInstance(config); } if (config.isUpdate()) { client.persist(config.getPath(), FileUtils.readYAML(config.getUpdateFileName())); } InputStream result = client.pull(config.getPath()); String fileExtension = config.getFileExtension(); PropertyLoader propertyLoader = LOADERS.get(fileExtension); if (propertyLoader == null) { throw new ConfigException("zookeeper.fileExtension setting error, The loader was not found"); } Optional.ofNullable(result) .map(e -> propertyLoader.load("remote.zookeeper." + fileExtension, e)) .ifPresent(e -> context.get().getOriginal().load(() -> context.get().withSources(e), this::zookeeperFinish)); handler.finish(context, config); try { client.addListener(context, (c1, c2) -> this.passive(c1, null, c2), config); } catch (Exception e) { LOGGER.error("passive zookeeper remote started error...."); } } else { throw new ConfigException("zookeeper config is null"); } } ZookeeperConfigLoader();  ZookeeperConfigLoader(final CuratorZookeeperClient client); }
ZookeeperConfigLoader implements ConfigLoader<ZookeeperConfig> { private void zookeeperLoad(final Supplier<Context> context, final LoaderHandler<ZookeeperConfig> handler, final ZookeeperConfig config) { if (config != null) { check(config); if (Objects.isNull(client)) { client = CuratorZookeeperClient.getInstance(config); } if (config.isUpdate()) { client.persist(config.getPath(), FileUtils.readYAML(config.getUpdateFileName())); } InputStream result = client.pull(config.getPath()); String fileExtension = config.getFileExtension(); PropertyLoader propertyLoader = LOADERS.get(fileExtension); if (propertyLoader == null) { throw new ConfigException("zookeeper.fileExtension setting error, The loader was not found"); } Optional.ofNullable(result) .map(e -> propertyLoader.load("remote.zookeeper." + fileExtension, e)) .ifPresent(e -> context.get().getOriginal().load(() -> context.get().withSources(e), this::zookeeperFinish)); handler.finish(context, config); try { client.addListener(context, (c1, c2) -> this.passive(c1, null, c2), config); } catch (Exception e) { LOGGER.error("passive zookeeper remote started error...."); } } else { throw new ConfigException("zookeeper config is null"); } } ZookeeperConfigLoader();  ZookeeperConfigLoader(final CuratorZookeeperClient client); @Override void passive(final Supplier<Context> context, final PassiveHandler<Config> handler, final Config config); @Override void load(final Supplier<Context> context, final LoaderHandler<ZookeeperConfig> handler); }
ZookeeperConfigLoader implements ConfigLoader<ZookeeperConfig> { private void zookeeperLoad(final Supplier<Context> context, final LoaderHandler<ZookeeperConfig> handler, final ZookeeperConfig config) { if (config != null) { check(config); if (Objects.isNull(client)) { client = CuratorZookeeperClient.getInstance(config); } if (config.isUpdate()) { client.persist(config.getPath(), FileUtils.readYAML(config.getUpdateFileName())); } InputStream result = client.pull(config.getPath()); String fileExtension = config.getFileExtension(); PropertyLoader propertyLoader = LOADERS.get(fileExtension); if (propertyLoader == null) { throw new ConfigException("zookeeper.fileExtension setting error, The loader was not found"); } Optional.ofNullable(result) .map(e -> propertyLoader.load("remote.zookeeper." + fileExtension, e)) .ifPresent(e -> context.get().getOriginal().load(() -> context.get().withSources(e), this::zookeeperFinish)); handler.finish(context, config); try { client.addListener(context, (c1, c2) -> this.passive(c1, null, c2), config); } catch (Exception e) { LOGGER.error("passive zookeeper remote started error...."); } } else { throw new ConfigException("zookeeper config is null"); } } ZookeeperConfigLoader();  ZookeeperConfigLoader(final CuratorZookeeperClient client); @Override void passive(final Supplier<Context> context, final PassiveHandler<Config> handler, final Config config); @Override void load(final Supplier<Context> context, final LoaderHandler<ZookeeperConfig> handler);  }