private void monitorComponents() { for (ProgramController controller : components.values()) { controller.addListener(new AbstractListener() { @Override public void completed() { if (liveComponents.decrementAndGet() == 0) { // If at least one of the components failed with an error, then set the state to ERROR if (errorCause != null) { setError(errorCause); } else { complete(); } } } @Override public void error(Throwable cause) { // Make a note that a component failed with an error errorCause = cause; // If the live component count goes to zero, then set the state of the controller to ERROR if (liveComponents.decrementAndGet() == 0) { setError(cause); } } }, Threads.SAME_THREAD_EXECUTOR); } }
private void monitorComponents() { for (ProgramController controller : components.values()) { controller.addListener(new AbstractListener() { @Override public void completed() { if (liveComponents.decrementAndGet() == 0) { // If at least one of the components failed with an error, then set the state to ERROR if (errorCause != null) { setError(errorCause); } else { complete(); } } } @Override public void error(Throwable cause) { // Make a note that a component failed with an error errorCause = cause; // If the live component count goes to zero, then set the state of the controller to ERROR if (liveComponents.decrementAndGet() == 0) { setError(cause); } } }, Threads.SAME_THREAD_EXECUTOR); } }
controller.addListener(new AbstractListener() {
controller.addListener(new AbstractListener() {
private ProgramController addStateChangeListener(ProgramController controller) { controller.addListener(new StateChangeListener(controller.getProgramRunId(), null, programStateWriter), Threads.SAME_THREAD_EXECUTOR); return controller; }
private ProgramController addStateChangeListener(ProgramController controller) { controller.addListener(new StateChangeListener(controller.getProgramRunId(), null, programStateWriter), Threads.SAME_THREAD_EXECUTOR); return controller; }
private boolean waitForCompletion(ProgramController controller) throws InterruptedException { final AtomicBoolean success = new AtomicBoolean(false); final CountDownLatch completion = new CountDownLatch(1); controller.addListener(new AbstractListener() { @Override public void completed() { success.set(true); completion.countDown(); } @Override public void error(Throwable cause) { completion.countDown(); } }, Threads.SAME_THREAD_EXECUTOR); // MR tests can run for long time. completion.await(10, TimeUnit.MINUTES); return success.get(); } }
controller.addListener(new AbstractListener() { @Override public void init(ProgramController.State currentState, @Nullable Throwable cause) {
controller.addListener(new AbstractListener() { @Override public void init(ProgramController.State currentState, @Nullable Throwable cause) {
protected void doMain() throws Exception { TwillRuntimeSpecification twillRuntimeSpec = TwillRuntimeSpecificationAdapter.create() .fromJson(new File(Constants.Files.RUNTIME_CONFIG_JAR, Constants.Files.TWILL_SPEC)); org.apache.twill.internal.Arguments arguments = readJsonFile(new File(Constants.Files.RUNTIME_CONFIG_JAR, Constants.Files.ARGUMENTS), org.apache.twill.internal.Arguments.class); TwillContext context = new DirectExecutionTwillContext(name, twillRuntimeSpec, arguments); initialize(context); Runtime.getRuntime().addShutdownHook(new Thread(AbstractProgramTwillRunnable.this::stop)); // Add the program state writer listener when the program controller is available ProgramStateWriter programStateWriter = injector.getInstance(ProgramStateWriter.class); controllerFuture.thenAcceptAsync( c -> c.addListener(new StateChangeListener(c.getProgramRunId(), null, programStateWriter), Threads.SAME_THREAD_EXECUTOR), command -> { Thread t = new Thread(command); t.start(); }); run(); }
protected void doMain() throws Exception { TwillRuntimeSpecification twillRuntimeSpec = TwillRuntimeSpecificationAdapter.create() .fromJson(new File(Constants.Files.RUNTIME_CONFIG_JAR, Constants.Files.TWILL_SPEC)); org.apache.twill.internal.Arguments arguments = readJsonFile(new File(Constants.Files.RUNTIME_CONFIG_JAR, Constants.Files.ARGUMENTS), org.apache.twill.internal.Arguments.class); TwillContext context = new DirectExecutionTwillContext(name, twillRuntimeSpec, arguments); initialize(context); Runtime.getRuntime().addShutdownHook(new Thread(AbstractProgramTwillRunnable.this::stop)); // Add the program state writer listener when the program controller is available ProgramStateWriter programStateWriter = injector.getInstance(ProgramStateWriter.class); controllerFuture.thenAcceptAsync( c -> c.addListener(new StateChangeListener(c.getProgramRunId(), null, programStateWriter), Threads.SAME_THREAD_EXECUTOR), command -> { Thread t = new Thread(command); t.start(); }); run(); }
controller.addListener(new AbstractListener() {
controller.addListener(new AbstractListener() {
controller.addListener(new AbstractListener() { @Override public void init(ProgramController.State currentState, @Nullable Throwable cause) {
controller.addListener(new AbstractListener() { @Override public void init(ProgramController.State currentState, @Nullable Throwable cause) {
private void stopProgram(ProgramController controller) throws Throwable { final AtomicReference<Throwable> errorCause = new AtomicReference<>(); final CountDownLatch complete = new CountDownLatch(1); controller.addListener(new AbstractListener() { @Override public void error(Throwable cause) { complete.countDown(); errorCause.set(cause); } @Override public void completed() { complete.countDown(); } @Override public void killed() { complete.countDown(); } }, Threads.SAME_THREAD_EXECUTOR); controller.stop(); complete.await(30, TimeUnit.SECONDS); runningPrograms.remove(controller); Throwable t = errorCause.get(); if (t != null) { throw t; } } }
private ProgramController startProgram(ApplicationWithPrograms app, Class<?> programClass) throws Throwable { final AtomicReference<Throwable> errorCause = new AtomicReference<>(); final ProgramController controller = AppFabricTestHelper.submit(app, programClass.getName(), new BasicArguments(), TEMP_FOLDER_SUPPLIER); runningPrograms.add(controller); controller.addListener(new AbstractListener() { @Override public void error(Throwable cause) { errorCause.set(cause); } @Override public void killed() { errorCause.set(new RuntimeException("Killed")); } }, Threads.SAME_THREAD_EXECUTOR); Tasks.waitFor(ProgramController.State.ALIVE, new Callable<ProgramController.State>() { @Override public ProgramController.State call() throws Exception { Throwable t = errorCause.get(); if (t != null) { Throwables.propagateIfInstanceOf(t, Exception.class); throw Throwables.propagate(t); } return controller.getState(); } }, 30, TimeUnit.SECONDS); return controller; }
ListenableFuture<Service.State> startCompletion = service.start(); controller.addListener(new AbstractListener() { private volatile boolean initCalled;
false); controller.addListener(new AbstractListener() { @Override public void init(ProgramController.State currentState, @Nullable Throwable cause) {
false); controller.addListener(new AbstractListener() { @Override public void init(ProgramController.State currentState, @Nullable Throwable cause) {