public void foo() { counter++; if (counter % 1000 == 0) { Sys.sleep(20); } } }
/** * Create a new one with default TTL of 20 seconds. * * @param healthStatus healthStatus * @param id id * @param name name * @param host post * @param port port */ public EndpointDefinition( final HealthStatus healthStatus, final String id, final String name, final String host, final int port) { this(healthStatus, id, name, host, port, Sys.sysProp(EndpointDefinition.class.getName() + ".timeToLive", 20L), null); }
/** * Checks for the key under system property. * Then checks it as an environment variable. * (Looks up in env using straight key and performing underBarCase on it.) * Then converts defaultValue into a string. * @param key key * @param defaultValue default value * @return prop */ public static String sysProp(String key, Object defaultValue) { return _sysProp(key, defaultValue); }
/** * Prints a simple message to the console. * * @param message string to print. */ public static void println(String message) { Sys.println(message); }
public static String getWindowsPathIfNeeded( String path ) { if ( Sys.isWindows() ) { if ( path.startsWith( ".\\" ) ) { path = Str.slc(path, 2); } } return path; }
/** * Prints to console. * * @param message message */ public static void print(String message) { Sys.print(message); }
public static BigDecimal sysPropBigDecimal(String key) { return sysPropBigDecima(key, (BigDecimal) null); }
public static String sysPropMultipleKeys(String... keys) { for (String key : keys) { String value = _sysProp(key, DEFAULT_NULL_NOT_EMPTY); if (value != null) { return value; } } return null; }
/** * Prints a simple message to the console. * * @param message string to print. */ public static void println(String message) { Sys.println(message); }
public static String getWindowsPathIfNeeded( String path ) { if ( Sys.isWindows() ) { if ( path.startsWith( ".\\" ) ) { path = Str.slc(path, 2); } } return path; }
/** * Prints to console. * * @param message message */ public static void print(String message) { Sys.print(message); }
public static BigDecimal sysPropBigDecimal(String key) { return sysPropBigDecima(key, (BigDecimal) null); }
@Override public void openAndWait() { open(e -> { }); /* Try to open for three seconds. */ int count = 5; while (!open.get()) { Sys.sleep(50); count--; if (count <= 0) { throw new IllegalStateException("Unable to open WebSocket connection"); } } }
/** * Create a new one with default TTL of 20 seconds. * * @param healthStatus healthStatus * @param id id * @param name name * @param host post * @param port port * @param tags tags */ public EndpointDefinition( final HealthStatus healthStatus, final String id, final String name, final String host, final int port, final List<String> tags) { this(healthStatus, id, name, host, port, Sys.sysProp(EndpointDefinition.class.getName() + ".timeToLive", 20L), tags); }
public static String sysPropMultipleKeys(String... keys) { for (String key : keys) { String value = _sysProp(key, DEFAULT_NULL_NOT_EMPTY); if (value != null) { return value; } } return null; }
/** * Adds a newline to the console. */ public static void println() { Sys.println(""); }
public static Path uriToPath( URI uri ) { Path thePath = null; if ( Sys.isWindows() ) { String newPath = uri.getPath(); if ( newPath.startsWith( "/C:" ) ) { newPath = Str.slc(newPath, 3); } thePath = FileSystems.getDefault().getPath( newPath ); } else { thePath = FileSystems.getDefault().getPath( uri.getPath() ); } return thePath; }
@Override public void sendText(final String body) { httpSendWebSocketCalled = true; periodicFlushCallback.accept(null); Sys.sleep(100); } };
public static List<URI> readDnsConf() { final Logger logger = LoggerFactory.getLogger(DnsUtil.class); final boolean debug = logger.isDebugEnabled(); final File file = new File(Sys.sysProp(QBIT_DNS_RESOLV_CONF, "/etc/resolv.conf")); if (file.exists()) { final List<String> lines = IO.readLines(file); if (debug) logger.debug("file contents {}", lines); return lines.stream().filter(line -> line.startsWith("nameserver")) .map(line -> { if (debug) logger.debug("file content line = {}", line); final String uriToParse = line.replace("nameserver ", "").trim(); final String[] split = Str.split(uriToParse, ':'); try { if (split.length == 1) { return new URI("dns", "", split[0], 53, "", "", ""); } else if (split.length >= 2) { return new URI("dns", "", split[0], Integer.parseInt(split[1]), "", "", ""); } else { throw new IllegalStateException("Unable to parse URI from /etc/resolv.conf"); } } catch (URISyntaxException e) { throw new IllegalStateException("failed to convert to URI"); } }) .collect(Collectors.toList()); } else { throw new IllegalStateException("" + file + " not found"); } }
/** * Checks for the key under system property. * Then checks it as an environment variable. * (Looks up in env using straight key and performing underBarCase on it.) * Then converts defaultValue into a string. * @param key key * @param defaultValue default value * @return prop */ public static String sysProp(String key, Object defaultValue) { return _sysProp(key, defaultValue); }