public void submit(final ListeningExecutorService executorService) { future = executorService.submit(new ThreadRenameCallableWrap<Object>("Rule " + rule.id, (Callable<Object>) this)); } }
@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 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 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 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 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); }