private static Optional<RefreshableConfigStorage> readConfig(final String configLocation) { try { final URL config = new URL(configLocation); return Optional.of(new RefreshableConfigStorage(config)); } catch (final MalformedURLException ex) { LOGGER.warn("Wrong notification configuration location.", ex); return Optional.empty(); } }
public RefreshableConfigStorage(final URL source) { this.source = source; /* * force the code to have a value right away. this is done to ensure that even the event listeners initialized * immediately after this call have notification properties available - otherwise initial emails of the platform * wouldn't have been sent until this Refreshable has had time to initialize. this has been a problem in the * installer already, as evidenced by https://github.com/RoboZonky/robozonky/issues/216. */ run(); }
@Test void loadCorrectly() throws IOException { final File props = File.createTempFile("robozonky-", ".properties"); final Properties p = new Properties(); p.store(Files.newBufferedWriter(props.toPath(), Defaults.CHARSET), ""); final RefreshableConfigStorage s = new RefreshableConfigStorage(props.toURI().toURL()); assertThat(s.get()).isPresent(); }
@Override public <T extends Event> Stream<EventListenerSupplier<T>> findListeners(final Class<T> eventType) { final NotificationEventListenerSupplier<T> l = new NotificationEventListenerSupplier<>(eventType); final long tenants = getTenantConfigurations() .peek(config -> config.registerListener(l)) .count(); if (tenants > 0) { return Stream.of(Target.values()).map(e -> () -> l.apply(e)); } else { return Stream.empty(); } } }
@Test void loadNonexistent() throws IOException { final File props = File.createTempFile("robozonky-", ".properties"); props.delete(); final RefreshableConfigStorage s = new RefreshableConfigStorage(props.toURI().toURL()); assertThat(s.get()).isEmpty(); } }
@Override public <T extends Event> Stream<EventListenerSupplier<T>> findListeners(final Class<T> eventType) { final NotificationEventListenerSupplier<T> l = new NotificationEventListenerSupplier<>(eventType); final long tenants = getTenantConfigurations() .peek(config -> config.registerListener(l)) .count(); if (tenants > 0) { return Stream.of(Target.values()).map(e -> () -> l.apply(e)); } else { return Stream.empty(); } } }
private static Optional<RefreshableConfigStorage> readConfig(final String configLocation) { try { final URL config = new URL(configLocation); return Optional.of(new RefreshableConfigStorage(config)); } catch (final MalformedURLException ex) { LOGGER.warn("Wrong notification configuration location.", ex); return Optional.empty(); } }
public RefreshableConfigStorage(final URL source) { this.source = source; /* * force the code to have a value right away. this is done to ensure that even the event listeners initialized * immediately after this call have notification properties available - otherwise initial emails of the platform * wouldn't have been sent until this Refreshable has had time to initialize. this has been a problem in the * installer already, as evidenced by https://github.com/RoboZonky/robozonky/issues/216. */ run(); }