public void refresh(String includesFile, String excludesFile) throws IOException { LOG.info("Refreshing hosts (include/exclude) list"); HostDetails oldDetails = current.get(); Set<String> newIncludes = oldDetails.includes; Map<String, Integer> newExcludes = oldDetails.excludes; if (includesFile != null && !includesFile.isEmpty()) { newIncludes = new HashSet<>(); readFileToSet("included", includesFile, newIncludes); newIncludes = Collections.unmodifiableSet(newIncludes); } if (excludesFile != null && !excludesFile.isEmpty()) { newExcludes = new HashMap<>(); readFileToMap("excluded", excludesFile, newExcludes); newExcludes = Collections.unmodifiableMap(newExcludes); } HostDetails newDetails = new HostDetails(includesFile, newIncludes, excludesFile, newExcludes); current.set(newDetails); }
private static int processHostList(String[] args, int i, String type, Set<String> nodes) { Preconditions.checkArgument(++i < args.length, "List of %s nodes | -f <filename> is missing: args=%s", type, Arrays.toString(args)); if ("-f".equalsIgnoreCase(args[i])) { Preconditions.checkArgument(++i < args.length, "File containing %s nodes is not specified: args=%s", type, Arrays.toString(args)); final String filename = args[i]; try { HostsFileReader.readFileToSet(type, filename, nodes); } catch (IOException e) { throw new IllegalArgumentException( "Failed to read " + type + " node list from file: " + filename); } } else { final String[] addresses = StringUtils.getTrimmedStrings(args[i]); nodes.addAll(Arrays.asList(addresses)); } return i; }
listURL = new URL(listArg); try { HostsFileReader.readFileToSet("include", Paths.get(listURL.getPath()).toString(), resultSet); } catch (FileNotFoundException e) {
private static HostSet readFile(String type, String filename) throws IOException { HostSet res = new HostSet(); if (!filename.isEmpty()) { HashSet<String> entrySet = new HashSet<String>(); HostsFileReader.readFileToSet(type, filename, entrySet); for (String str : entrySet) { InetSocketAddress addr = parseEntry(type, filename, str); if (addr != null) { res.add(addr); } } } return res; }
public Set<String> getNewIncludes() throws IOException { if (!includesFile.equals("")) { Set<String> newIncludes = new HashSet<String>(); readFileToSet(includesFile, newIncludes); return newIncludes; } return null; }
public synchronized void refresh() throws IOException { includes.clear(); excludes.clear(); if (!includesFile.equals("")) { readFileToSet(includesFile, includes); } if (!excludesFile.equals("")) { readFileToSet(excludesFile, excludes); } }
public Set<String> getNewExcludes() throws IOException { if (!excludesFile.equals("")) { Set<String> newExcludes = new HashSet<String>(); readFileToSet(excludesFile, newExcludes); return newExcludes; } return null; }
public synchronized void refresh() throws IOException { LOG.info("Refreshing hosts (include/exclude) list"); if (!includesFile.equals("")) { Set<String> newIncludes = new HashSet<String>(); readFileToSet(includesFile, newIncludes); // switch the new hosts that are to be included includes = newIncludes; } if (!excludesFile.equals("")) { Set<String> newExcludes = new HashSet<String>(); readFileToSet(excludesFile, newExcludes); // switch the excluded hosts excludes = newExcludes; } }
public synchronized void refresh() throws IOException { LOG.info("Refreshing hosts (include/exclude) list"); Set<String> newIncludes = new HashSet<String>(); Set<String> newExcludes = new HashSet<String>(); boolean switchIncludes = false; boolean switchExcludes = false; if (!includesFile.isEmpty()) { readFileToSet("included", includesFile, newIncludes); switchIncludes = true; } if (!excludesFile.isEmpty()) { readFileToSet("excluded", excludesFile, newExcludes); switchExcludes = true; } if (switchIncludes) { // switch the new hosts that are to be included includes = newIncludes; } if (switchExcludes) { // switch the excluded hosts excludes = newExcludes; } }
public synchronized void refresh() throws IOException { LOG.info("Refreshing hosts (include/exclude) list"); Set<String> newIncludes = new HashSet<String>(); Set<String> newExcludes = new HashSet<String>(); boolean switchIncludes = false; boolean switchExcludes = false; if (!includesFile.isEmpty()) { readFileToSet("included", includesFile, newIncludes); switchIncludes = true; } if (!excludesFile.isEmpty()) { readFileToSet("excluded", excludesFile, newExcludes); switchExcludes = true; } if (switchIncludes) { // switch the new hosts that are to be included includes = newIncludes; } if (switchExcludes) { // switch the excluded hosts excludes = newExcludes; } }
/** * Read set of host names from a file * * @return set of host names */ static Set<String> getHostListFromFile(String fileName, String type) { Set<String> nodes = new HashSet<String>(); try { HostsFileReader.readFileToSet(type, fileName, nodes); return StringUtils.getTrimmedStrings(nodes); } catch (IOException e) { throw new IllegalArgumentException( "Failed to read host list from file: " + fileName); } } }
/** * Read set of host names from a file * * @return set of host names */ static Set<String> getHostListFromFile(String fileName, String type) { Set<String> nodes = new HashSet<String>(); try { HostsFileReader.readFileToSet(type, fileName, nodes); return StringUtils.getTrimmedStrings(nodes); } catch (IOException e) { throw new IllegalArgumentException( "Failed to read host list from file: " + fileName); } } }
public synchronized void refresh() throws IOException { LOG.info("Refreshing hosts (include/exclude) list"); Set<String> newIncludes = new HashSet<String>(); Set<String> newExcludes = new HashSet<String>(); boolean switchIncludes = false; boolean switchExcludes = false; if (!includesFile.isEmpty()) { readFileToSet("included", includesFile, newIncludes); switchIncludes = true; } if (!excludesFile.isEmpty()) { readFileToSet("excluded", excludesFile, newExcludes); switchExcludes = true; } if (switchIncludes) { // switch the new hosts that are to be included includes = newIncludes; } if (switchExcludes) { // switch the excluded hosts excludes = newExcludes; } }
boolean switchExcludes = false; if (includeFiles != null && !includeFiles.isEmpty()) { readFileToSet("included", includeFiles, newIncludes); switchIncludes = true; readFileToSet("excluded", excludeFiles, newExcludes); switchExcludes = true;
private static HostSet readFile(String type, String filename) throws IOException { HostSet res = new HostSet(); if (!filename.isEmpty()) { HashSet<String> entrySet = new HashSet<String>(); HostsFileReader.readFileToSet(type, filename, entrySet); for (String str : entrySet) { InetSocketAddress addr = parseEntry(type, filename, str); if (addr != null) { res.add(addr); } } } return res; }
private static HostSet readFile(String type, String filename) throws IOException { HostSet res = new HostSet(); if (!filename.isEmpty()) { HashSet<String> entrySet = new HashSet<String>(); HostsFileReader.readFileToSet(type, filename, entrySet); for (String str : entrySet) { InetSocketAddress addr = parseEntry(type, filename, str); if (addr != null) { res.add(addr); } } } return res; }