@Override public ResourceUpdate<ChangeNotification<Server>> reload(Set<ChangeNotification<Server>> currentSnapshot) { if (!isUpdated()) { return new ResourceUpdate<>(currentSnapshot, Collections.<ChangeNotification<Server>>emptySet()); } try { try (LineNumberReader reader = new LineNumberReader(new FileReader(textFile))) { Set<ChangeNotification<Server>> newAddresses = new HashSet<>(); String line; while ((line = reader.readLine()) != null) { if (!(line = line.trim()).isEmpty()) { Server server = parseLine(reader.getLineNumber(), line); newAddresses.add(new ChangeNotification<Server>(Kind.Add, server)); } } return new ResourceUpdate<>(newAddresses, cancellationSet(currentSnapshot, newAddresses)); } } catch (IOException e) { if (lastModified == -1) { throw new ResourceLoaderException("Server resolver file missing on startup " + textFile, false, e); } throw new ResourceLoaderException("Cannot reload server resolver file " + textFile, true, e); } }
@Override public ResourceObservable.ResourceUpdate<ChangeNotification<Server>> reload(Set<ChangeNotification<Server>> currentSnapshot) { if (!isUpdated()) { return new ResourceObservable.ResourceUpdate<>(currentSnapshot, Collections.<ChangeNotification<Server>>emptySet(), sentinel); } try { try (LineNumberReader reader = new LineNumberReader(new FileReader(textFile))) { Set<ChangeNotification<Server>> newAddresses = new HashSet<>(); String line; while ((line = reader.readLine()) != null) { if (!(line = line.trim()).isEmpty()) { Server server = parseLine(reader.getLineNumber(), line); newAddresses.add(new ChangeNotification<Server>(ChangeNotification.Kind.Add, server)); } } return new ResourceObservable.ResourceUpdate<>(newAddresses, cancellationSet(currentSnapshot, newAddresses), sentinel); } } catch (IOException e) { if (lastModified == -1) { throw new ResourceObservable.ResourceLoaderException("Server resolver file missing on startup " + textFile, false, e); } throw new ResourceObservable.ResourceLoaderException("Cannot reload server resolver file " + textFile, true, e); } }
@Override protected Observable<ChangeNotification<Server>> serverUpdates() { return ResourceObservable.fromResource(new FileResolveTask(), reloadInterval, idleTimeout, timeUnit, scheduler); }
private static Observable<ChangeNotification<Server>> createServerSource(File textFile, Configuration configuration) { return ResourceObservable.fromResource( new FileResolveTask(textFile, configuration), configuration.reloadInterval, configuration.idleTimeout, configuration.timeUnit, configuration.scheduler ); }