@Test public void testApplyConfig() { configStore.addConfigFactory(new MockConfigFactory(BasicConfig.class, "config1")); configStore.applyConfig("subject", BasicConfig.class, new ObjectMapper().createObjectNode()); assertThat(configStore.getConfigClasses("subject"), hasSize(1)); assertThat(configStore.getSubjects(String.class, BasicConfig.class), hasSize(1)); assertThat(configStore.getSubjects(String.class), hasSize(1)); }
@Override public <S, C extends Config<S>> C applyConfig(S subject, Class<C> configClass, JsonNode json) { C config = createConfig(subject, configClass, json); try { checkArgument(config.isValid(), INVALID_CONFIG_JSON); } catch (RuntimeException e) { ConfigFactory<S, C> configFactory = getConfigFactory(configClass); String subjectKey = configFactory.subjectFactory().subjectClassKey(); String subjectString = configFactory.subjectFactory().subjectKey(config.subject()); String configKey = config.key(); throw new InvalidConfigException(subjectKey, subjectString, configKey, e); } Versioned<JsonNode> versioned = configs.putAndGet(key(subject, configClass), json); return versioned.value() == json ? config : createConfig(subject, configClass, versioned.value()); }
DistributedNetworkConfigStore extends AbstractStore<NetworkConfigEvent, NetworkConfigStoreDelegate> implements NetworkConfigStore { @Override public <S, C extends Config<S>> C applyConfig(S subject, Class<C> configClass, JsonNode json) { C config = createConfig(subject, configClass, json); try { checkArgument(config.isValid(), INVALID_CONFIG_JSON); } catch (RuntimeException e) { ConfigFactory<S, C> configFactory = getConfigFactory(configClass); String subjectKey = configFactory.subjectFactory().subjectClassKey(); String subjectString = configFactory.subjectFactory().subjectKey(config.subject()); String configKey = config.key(); throw new InvalidConfigException(subjectKey, subjectString, configKey, e); } Versioned<JsonNode> versioned = configs.putAndGet(key(subject, configClass), json); return versioned.value() == json ? config : createConfig(subject, configClass, versioned.value()); } }
DistributedNetworkConfigStore extends AbstractStore<NetworkConfigEvent, NetworkConfigStoreDelegate> implements NetworkConfigStore { @Override public <S, C extends Config<S>> C applyConfig(S subject, Class<C> configClass, JsonNode json) { C config = createConfig(subject, configClass, json); try { checkArgument(config.isValid(), INVALID_CONFIG_JSON); } catch (RuntimeException e) { ConfigFactory<S, C> configFactory = getConfigFactory(configClass); String subjectKey = configFactory.subjectFactory().subjectClassKey(); String subjectString = configFactory.subjectFactory().subjectKey(config.subject()); String configKey = config.key(); throw new InvalidConfigException(subjectKey, subjectString, configKey, e); } Versioned<JsonNode> versioned = configs.putAndGet(key(subject, configClass), json); return versioned.value() == json ? config : createConfig(subject, configClass, versioned.value()); }  }
DistributedNetworkConfigStore extends AbstractStore<NetworkConfigEvent, NetworkConfigStoreDelegate> implements NetworkConfigStore { @Override public <S, C extends Config<S>> C applyConfig(S subject, Class<C> configClass, JsonNode json) { C config = createConfig(subject, configClass, json); try { checkArgument(config.isValid(), INVALID_CONFIG_JSON); } catch (RuntimeException e) { ConfigFactory<S, C> configFactory = getConfigFactory(configClass); String subjectKey = configFactory.subjectFactory().subjectClassKey(); String subjectString = configFactory.subjectFactory().subjectKey(config.subject()); String configKey = config.key(); throw new InvalidConfigException(subjectKey, subjectString, configKey, e); } Versioned<JsonNode> versioned = configs.putAndGet(key(subject, configClass), json); return versioned.value() == json ? config : createConfig(subject, configClass, versioned.value()); }  @Activate void activate(); @Deactivate void deactivate(); @Override void addConfigFactory(ConfigFactory configFactory); @Override void removeConfigFactory(ConfigFactory configFactory); @Override @SuppressWarnings("unchecked") ConfigFactory<S, C> getConfigFactory(Class<C> configClass); @Override @SuppressWarnings("unchecked") Set<S> getSubjects(Class<S> subjectClass); @Override @SuppressWarnings("unchecked") Set<S> getSubjects(Class<S> subjectClass, Class<C> configClass); @Override @SuppressWarnings("unchecked") Set<Class<? extends Config<S>>> getConfigClasses(S subject); @Override T getConfig(S subject, Class<T> configClass); @Override C createConfig(S subject, Class<C> configClass); @Override C applyConfig(S subject, Class<C> configClass, JsonNode json); @Override void queueConfig(S subject, String configKey, JsonNode json); @Override void clearConfig(S subject, Class<C> configClass); @Override void clearQueuedConfig(S subject, String configKey); @Override void clearConfig(S subject); @Override void clearConfig(); }
DistributedNetworkConfigStore extends AbstractStore<NetworkConfigEvent, NetworkConfigStoreDelegate> implements NetworkConfigStore { @Override public <S, C extends Config<S>> C applyConfig(S subject, Class<C> configClass, JsonNode json) { C config = createConfig(subject, configClass, json); try { checkArgument(config.isValid(), INVALID_CONFIG_JSON); } catch (RuntimeException e) { ConfigFactory<S, C> configFactory = getConfigFactory(configClass); String subjectKey = configFactory.subjectFactory().subjectClassKey(); String subjectString = configFactory.subjectFactory().subjectKey(config.subject()); String configKey = config.key(); throw new InvalidConfigException(subjectKey, subjectString, configKey, e); } Versioned<JsonNode> versioned = configs.putAndGet(key(subject, configClass), json); return versioned.value() == json ? config : createConfig(subject, configClass, versioned.value()); }  @Activate void activate(); @Deactivate void deactivate(); @Override void addConfigFactory(ConfigFactory configFactory); @Override void removeConfigFactory(ConfigFactory configFactory); @Override @SuppressWarnings("unchecked") ConfigFactory<S, C> getConfigFactory(Class<C> configClass); @Override @SuppressWarnings("unchecked") Set<S> getSubjects(Class<S> subjectClass); @Override @SuppressWarnings("unchecked") Set<S> getSubjects(Class<S> subjectClass, Class<C> configClass); @Override @SuppressWarnings("unchecked") Set<Class<? extends Config<S>>> getConfigClasses(S subject); @Override T getConfig(S subject, Class<T> configClass); @Override C createConfig(S subject, Class<C> configClass); @Override C applyConfig(S subject, Class<C> configClass, JsonNode json); @Override void queueConfig(S subject, String configKey, JsonNode json); @Override void clearConfig(S subject, Class<C> configClass); @Override void clearQueuedConfig(S subject, String configKey); @Override void clearConfig(S subject); @Override void clearConfig();  }