public void submit(final ListeningExecutorService executorService) { future = executorService.submit(new ThreadRenameCallableWrap<Object>("Rule " + rule.id, (Callable<Object>) this)); } }
@Inject public HealthCheckWorker(HealthCheckRegistry registry) { super(new Timeout(10, TimeUnit.MINUTES)); this.registry = registry; }
private void waitForResult(final ListenableFuture<Void> future, final Timeout timeout) throws InterruptedException Deadline deadline = timeout.start(); while (deadline.isValid()) if (deadline.isValid()) Thread.sleep(Timeout.TEN_SECONDS.getMilliseconds());
@Override public ITemplateResolver get() { ServletContextTemplateResolver resolver = new ServletContextTemplateResolver(); resolver.setTemplateMode("HTML5"); // Load templates from WEB-INF/templates/{name}.html resolver.setPrefix("/WEB-INF/template/"); resolver.setSuffix(".html"); if (cacheTTL.getMilliseconds() > 0) { // cache templates for an hour resolver.setCacheTTLMs(cacheTTL.getMilliseconds()); resolver.setCacheable(true); } else { // Don't cache resolver.setCacheable(false); } return resolver; } }
@Override public Future<Void> stopAsync(final String id) { final VirtualMachine vm = getById(id); final String threadName = "Azure Async Call - " + vm.resourceGroupName() + " - " + vm.name(); ThreadRenameCallableWrap<Void> call = new ThreadRenameCallableWrap<Void>(threadName, new Callable<Void>() { @Override public Void call() throws Exception { stop(vm, Timeout.THIRTY_MINUTES); return null; } }); return asynchronous.submit(call); }
@Override public ITemplateResolver get() { ServletContextTemplateResolver resolver = new ServletContextTemplateResolver(); resolver.setTemplateMode("HTML5"); // Load templates from WEB-INF/templates/{name}.html resolver.setPrefix("/WEB-INF/template/"); resolver.setSuffix(".html"); if (cacheTTL.getMilliseconds() > 0) { // cache templates for an hour resolver.setCacheTTLMs(cacheTTL.getMilliseconds()); resolver.setCacheable(true); } else { // Don't cache resolver.setCacheable(false); } return resolver; } }
@Override public Future<Void> startAsync(final String id) { final VirtualMachine vm = getById(id); final String threadName = "Azure Async Call" + vm.resourceGroupName() + " - " + vm.name(); ThreadRenameCallableWrap<Void> call = new ThreadRenameCallableWrap<Void>(threadName, new Callable<Void>() { @Override public Void call() throws Exception { start(vm, Timeout.THIRTY_MINUTES); return null; } }); return asynchronous.submit(call); }
@Override public Future<Void> restartAsync(final String id) { final VirtualMachine vm = getById(id); final String threadName = "Azure Async Call - " + vm.resourceGroupName() + " - " + vm.name(); ThreadRenameCallableWrap<Void> call = new ThreadRenameCallableWrap<Void>(threadName, new Callable<Void>() { @Override public Void call() throws Exception { restart(vm, Timeout.THIRTY_MINUTES); return null; } }); return asynchronous.submit(call); }
private void start(final VirtualMachine vm, final Timeout timeout) throws InterruptedException { //start some work final String threadName = "Azure VM Start - " + vm.resourceGroupName() + " - " + vm.name(); ListenableFuture<Void> future = synchronous.submit(new ThreadRenameCallableWrap<Void>(threadName, new Callable<Void>() { @Override public Void call() throws Exception { try { vm.start(); } catch (CloudException e) { log.error("Error starting " + vm.resourceGroupName() + " " + vm.name() + ": " + e.getMessage(), e); throw new RuntimeException(e); } catch (IOException e) { log.error("Error starting " + vm.resourceGroupName() + " " + vm.name() + ": " + e.getMessage(), e); throw new RuntimeException(e); } return null; } })); waitForResult(future, timeout); }
private void stop(final VirtualMachine vm, final Timeout timeout) throws InterruptedException { final String threadName = "Azure VM Stop - " + vm.resourceGroupName() + " - " + vm.name(); ListenableFuture<Void> future = synchronous.submit(new ThreadRenameCallableWrap<Void>(threadName, new Callable<Void>() { @Override public Void call() throws Exception { try { vm.deallocate(); } catch (CloudException e) { log.error("Error deallocating " + vm.resourceGroupName() + " " + vm.name() + ": " + e.getMessage(), e); throw new RuntimeException(e); } catch (IOException e) { log.error("Error deallocating " + vm.resourceGroupName() + " " + vm.name() + ": " + e.getMessage(), e); throw new RuntimeException(e); } return null; } })); waitForResult(future, timeout); }
private void restart(final VirtualMachine vm, final Timeout timeout) throws InterruptedException { //start some work final String threadName = "Azure VM Restart - " + vm.resourceGroupName() + " - " + vm.name(); ListenableFuture<Void> future = synchronous.submit(new ThreadRenameCallableWrap<Void>(threadName, new Callable<Void>() { @Override public Void call() throws Exception { try { vm.restart(); } catch (CloudException e) { log.error("Error restarting " + vm.resourceGroupName() + " " + vm.name() + ": " + e.getMessage(), e); throw new RuntimeException(e); } catch (IOException e) { log.error("Error restarting " + vm.resourceGroupName() + " " + vm.name() + ": " + e.getMessage(), e); throw new RuntimeException(e); } return null; } })); waitForResult(future, timeout); }