@Test public void testNTPClient(){ }
public NTPClient(List<String> listHosts, int pollMs) throws UnknownHostException, SocketException, NullPointerException { logger.traceEntry("params: {} {}", listHosts, pollMs); this.pollMs = pollMs; Util.check(listHosts != null, "listHosts should not be null!"); StringBuilder stringBuilderHosts = new StringBuilder(); logger.trace("Building internal lists..."); for (int i = 0; i < listHosts.size(); i++){ InetAddress host = InetAddress.getByName(listHosts.get(i)); listHostsAddr.add(host); this.listHosts.add(listHosts.get(i)); if (i > 0){ stringBuilderHosts.append(", "); } stringBuilderHosts.append(host); } if (listHostsAddr.size() == 0){ logger.trace("Lists are empty, adding a default, not usable server!"); listHostsAddr.add(InetAddress.getByName("localhost")); listHosts.add("[N/A]"); } ntpUdpClient = new NTPUDPClient(); ntpUdpClient.setDefaultTimeout(10000); ntpUdpClient.open(); ntpUdpClient.setSoTimeout(pollMs * 2 + 20); pollThread = new Thread(this::pollNtpServer, "pollNtpServer(" + stringBuilderHosts.toString() + "," + pollMs + ")"); pollThread.start(); logger.traceExit(); }
NTPClient implements AutoCloseable { public NTPClient(List<String> listHosts, int pollMs) throws UnknownHostException, SocketException, NullPointerException { logger.traceEntry("params: {} {}", listHosts, pollMs); this.pollMs = pollMs; Util.check(listHosts != null, "listHosts should not be null!"); StringBuilder stringBuilderHosts = new StringBuilder(); logger.trace("Building internal lists..."); for (int i = 0; i < listHosts.size(); i++){ InetAddress host = InetAddress.getByName(listHosts.get(i)); listHostsAddr.add(host); this.listHosts.add(listHosts.get(i)); if (i > 0){ stringBuilderHosts.append(", "); } stringBuilderHosts.append(host); } if (listHostsAddr.size() == 0){ logger.trace("Lists are empty, adding a default, not usable server!"); listHostsAddr.add(InetAddress.getByName("localhost")); listHosts.add("[N/A]"); } ntpUdpClient = new NTPUDPClient(); ntpUdpClient.setDefaultTimeout(10000); ntpUdpClient.open(); ntpUdpClient.setSoTimeout(pollMs * 2 + 20); pollThread = new Thread(this::pollNtpServer, "pollNtpServer(" + stringBuilderHosts.toString() + "," + pollMs + ")"); pollThread.start(); logger.traceExit(); } }
NTPClient implements AutoCloseable { public NTPClient(List<String> listHosts, int pollMs) throws UnknownHostException, SocketException, NullPointerException { logger.traceEntry("params: {} {}", listHosts, pollMs); this.pollMs = pollMs; Util.check(listHosts != null, "listHosts should not be null!"); StringBuilder stringBuilderHosts = new StringBuilder(); logger.trace("Building internal lists..."); for (int i = 0; i < listHosts.size(); i++){ InetAddress host = InetAddress.getByName(listHosts.get(i)); listHostsAddr.add(host); this.listHosts.add(listHosts.get(i)); if (i > 0){ stringBuilderHosts.append(", "); } stringBuilderHosts.append(host); } if (listHostsAddr.size() == 0){ logger.trace("Lists are empty, adding a default, not usable server!"); listHostsAddr.add(InetAddress.getByName("localhost")); listHosts.add("[N/A]"); } ntpUdpClient = new NTPUDPClient(); ntpUdpClient.setDefaultTimeout(10000); ntpUdpClient.open(); ntpUdpClient.setSoTimeout(pollMs * 2 + 20); pollThread = new Thread(this::pollNtpServer, "pollNtpServer(" + stringBuilderHosts.toString() + "," + pollMs + ")"); pollThread.start(); logger.traceExit(); } NTPClient(List<String> listHosts, int pollMs); }
NTPClient implements AutoCloseable { public NTPClient(List<String> listHosts, int pollMs) throws UnknownHostException, SocketException, NullPointerException { logger.traceEntry("params: {} {}", listHosts, pollMs); this.pollMs = pollMs; Util.check(listHosts != null, "listHosts should not be null!"); StringBuilder stringBuilderHosts = new StringBuilder(); logger.trace("Building internal lists..."); for (int i = 0; i < listHosts.size(); i++){ InetAddress host = InetAddress.getByName(listHosts.get(i)); listHostsAddr.add(host); this.listHosts.add(listHosts.get(i)); if (i > 0){ stringBuilderHosts.append(", "); } stringBuilderHosts.append(host); } if (listHostsAddr.size() == 0){ logger.trace("Lists are empty, adding a default, not usable server!"); listHostsAddr.add(InetAddress.getByName("localhost")); listHosts.add("[N/A]"); } ntpUdpClient = new NTPUDPClient(); ntpUdpClient.setDefaultTimeout(10000); ntpUdpClient.open(); ntpUdpClient.setSoTimeout(pollMs * 2 + 20); pollThread = new Thread(this::pollNtpServer, "pollNtpServer(" + stringBuilderHosts.toString() + "," + pollMs + ")"); pollThread.start(); logger.traceExit(); } NTPClient(List<String> listHosts, int pollMs); long getPollMs(); void setPollMs(int pollMs); long currentTimeMillis(); boolean isOffline(); String getCurrentHostName(); @Override void close(); }
NTPClient implements AutoCloseable { public NTPClient(List<String> listHosts, int pollMs) throws UnknownHostException, SocketException, NullPointerException { logger.traceEntry("params: {} {}", listHosts, pollMs); this.pollMs = pollMs; Util.check(listHosts != null, "listHosts should not be null!"); StringBuilder stringBuilderHosts = new StringBuilder(); logger.trace("Building internal lists..."); for (int i = 0; i < listHosts.size(); i++){ InetAddress host = InetAddress.getByName(listHosts.get(i)); listHostsAddr.add(host); this.listHosts.add(listHosts.get(i)); if (i > 0){ stringBuilderHosts.append(", "); } stringBuilderHosts.append(host); } if (listHostsAddr.size() == 0){ logger.trace("Lists are empty, adding a default, not usable server!"); listHostsAddr.add(InetAddress.getByName("localhost")); listHosts.add("[N/A]"); } ntpUdpClient = new NTPUDPClient(); ntpUdpClient.setDefaultTimeout(10000); ntpUdpClient.open(); ntpUdpClient.setSoTimeout(pollMs * 2 + 20); pollThread = new Thread(this::pollNtpServer, "pollNtpServer(" + stringBuilderHosts.toString() + "," + pollMs + ")"); pollThread.start(); logger.traceExit(); } NTPClient(List<String> listHosts, int pollMs); long getPollMs(); void setPollMs(int pollMs); long currentTimeMillis(); boolean isOffline(); String getCurrentHostName(); @Override void close();  }