use of com.peterphi.std.threading.Timeout in project stdlib by petergeneric.
the class NginxService method reload.
/**
* Reload the nginx configuration
*/
public void reload() {
try {
final Execed process = Exec.rootUtility(new File(binPath, "nginx-reload").getAbsolutePath());
process.waitForExit(new Timeout(30, TimeUnit.SECONDS).start(), 0);
} catch (IOException e) {
throw new RuntimeException("Error executing nginx-reload command", e);
}
}
use of com.peterphi.std.threading.Timeout in project stdlib by petergeneric.
the class TimeoutConverterTest method test.
@Test
public void test() {
PropertyFile props = new PropertyFile();
props.set("timeout1msNoUnit", "1");
props.set("timeout1ms", "1ms");
props.set("timeout1s", "1s");
props.set("timeout1h", "1h");
props.set("timeout60m", "60m");
props.set("timeout50h", "50h");
final Injector injector = Guice.createInjector(new ServicePropertiesModule(props));
injector.injectMembers(this);
// extract values
assertEquals(new Timeout(1, TimeUnit.MILLISECONDS), timeout1msNoUnit);
assertEquals(new Timeout(1, TimeUnit.MILLISECONDS), timeout1ms);
assertEquals(new Timeout(1, TimeUnit.SECONDS), timeout1s);
assertEquals(new Timeout(60, TimeUnit.MINUTES), timeout60m);
assertEquals(new Timeout(1, TimeUnit.HOURS), timeout1h);
// compare against one another
assertEquals(timeout60m, timeout1h);
assertEquals(timeout1msNoUnit, timeout1ms);
assertFalse(timeout50h.equals(timeout1h));
}
use of com.peterphi.std.threading.Timeout in project stdlib by petergeneric.
the class CarbonClientImpl method createSocket.
private Socket createSocket() {
int attempt = 0;
Timeout sleep = reconnectSleep;
while (attempt++ < MAX_CONNECT_ATTEMPTS) try {
return new Socket(host, port);
} catch (Exception e) {
if (attempt < MAX_CONNECT_ATTEMPTS) {
// back off
sleep.sleep();
// Sleep longer next time
sleep = sleep.multiply(reconnectSleepMultiplier);
} else {
throw new CarbonConnectException("Could not connect to Carbon API in " + MAX_CONNECT_ATTEMPTS + " attempts", e);
}
}
throw new CarbonConnectException("Could not conect to Carbon API socket!");
}
Aggregations