List of usage examples for com.google.common.util.concurrent Service state
State state();
From source file:com.continuuity.weave.internal.ListenerExecutor.java
private boolean hasCalled(Service.State state) { return callStates.putIfAbsent(state, true) != null; }
From source file:org.apache.hadoop.examples.render.twill.RenderTwillMain.java
public void exec(List<String> argsList) throws ExecutionException, InterruptedException, IOException { RenderArgs params = new RenderArgs(argsList); params.validateForMain();/*from w w w .j a v a 2 s .c o m*/ String zkStr = params.zookeeper; String rmAddr = conf.get(YarnConfiguration.RM_ADDRESS); Preconditions.checkState(!rmAddr.startsWith("0.0.0.0"), "Resource manager not defined " + rmAddr); final TwillRunnerService twillRunner = new YarnTwillRunnerService(conf, zkStr, createLocationFactory()); twillRunner.startAndWait(); controller = null; Runtime.getRuntime().addShutdownHook(new Thread(() -> { if (controller != null) { controller.stopAndWait(); } twillRunner.stopAndWait(); })); controller = twillRunner.prepare(new StdoutRunnable()) // .addLogHandler(new Slf4JLogHandler(log)) .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out))) .withApplicationArguments(params.getArguments()).start(); ListenableFuture<Service.State> future = Services.getCompletionFuture(controller); future.get(); }
From source file:co.cask.cdap.kafka.run.KafkaServerMain.java
@Override public void start() { LOG.info("Starting embedded kafka server..."); kafkaServer = new EmbeddedKafkaServer(kafkaProperties); Service.State state = kafkaServer.startAndWait(); if (state != Service.State.RUNNING) { throw new IllegalStateException("Kafka server has not started... terminating."); }/*from w w w.jav a2s.co m*/ LOG.info("Embedded kafka server started successfully."); }
From source file:com.griddynamics.jagger.engine.e1.process.WorkloadProcess.java
public void stop() { log.debug("Going to terminate"); List<ListenableFuture<Service.State>> futures = Lists.newLinkedList(); for (WorkloadService thread : threads) { ListenableFuture<Service.State> stop = thread.stop(); futures.add(stop);/*from w w w. j av a 2 s . c o m*/ } for (ListenableFuture<Service.State> future : futures) { Service.State state = Futures.get(future, timeoutsConfiguration.getWorkloadStopTimeout()); log.debug("stopped workload thread with status {}", state); } log.debug("All threads were terminated"); executor.shutdown(); log.debug("Shutting down executor"); }
From source file:org.invenzzia.helium.gui.context.AbstractContext.java
@Override public final synchronized Service.State stopAndWait() { if (this.state != Service.State.RUNNING) { return this.state; }//from w w w . j a v a 2 s . c om try { this.state = Service.State.STOPPING; this.eventBus.post(new ContextStateChangeEvent(this, this.state)); if (this.shutdown()) { this.state = Service.State.TERMINATED; this.eventBus.post(new ContextStateChangeEvent(this, this.state)); } else { this.state = Service.State.RUNNING; } return this.state; } catch (RuntimeException exception) { this.state = Service.State.RUNNING; throw exception; } }
From source file:GRSX.Main.java
private void loadWindow(Stage mainWindow) throws IOException { this.mainWindow = mainWindow; instance = this; GuiUtils.handleCrashesOnThisThread(); URL location = getClass().getResource("main.fxml"); FXMLLoader loader = new FXMLLoader(location); mainUI = loader.load();/*from w w w.j a v a2s. c o m*/ controller = loader.getController(); notificationBar = new NotificationBarPane(mainUI); mainWindow.setTitle(APP_NAME); uiStack = new StackPane(); Scene scene = new Scene(uiStack); TextFieldValidator.configureScene(scene); scene.getStylesheets().add(getClass().getResource("wallet.css").toString()); uiStack.getChildren().add(notificationBar); mainWindow.setScene(scene); mainWindow.setResizable(false); //saving this for later for when i can work out .fxml scaling //mainWindow.setMaxWidth(Screen.getPrimary().getBounds().getWidth() / 2); //mainWindow.setMaxHeight(Screen.getPrimary().getBounds().getHeight() / 2); mainWindow.setMaxWidth(800); mainWindow.setMaxHeight(451); //using an online image to update the icon on the fly without needing to push new builds, just because i want to. mainWindow.getIcons().add(new Image("https://duudl3.xyz/img/vortex_wallet_logo.png")); BriefLogFormatter.init(); Threading.USER_THREAD = Platform::runLater; setupWalletKit(null); if (groestlcoin.isChainFileLocked()) { informationalAlert("Vortex Notification", "Vortex is already running and cannot be started twice."); Platform.exit(); return; } mainWindow.show(); groestlcoin.addListener(new Service.Listener() { @Override public void failed(Service.State from, Throwable failure) { GuiUtils.crashAlert(failure); } }, Platform::runLater); groestlcoin.startAsync(); }
From source file:org.apache.usergrid.management.export.ExportServiceIT.java
@Before public void setup() throws Exception { logger.info("in setup"); // start the scheduler after we're all set up try {/* w w w . ja v a 2 s . co m*/ JobSchedulerService jobScheduler = ConcurrentProcessSingleton.getInstance().getSpringResource() .getBean(JobSchedulerService.class); if (jobScheduler.state() != Service.State.RUNNING) { jobScheduler.startAsync(); jobScheduler.awaitRunning(); } } catch (Exception e) { logger.warn("Ignoring error starting jobScheduler, already started?", e); } adminUser = newOrgAppAdminRule.getAdminInfo(); organization = newOrgAppAdminRule.getOrganizationInfo(); applicationId = newOrgAppAdminRule.getApplicationInfo().getId(); setup.getEntityIndex().refresh(applicationId); }
From source file:co.cask.cdap.common.twill.AbstractMasterTwillRunnable.java
private Service.Listener createServiceListener(final String name, final SettableFuture<String> future) { return new ServiceListenerAdapter() { @Override/*from w ww . j ava 2 s.c om*/ public void terminated(Service.State from) { LOG.info("Service " + name + " terminated"); future.set(name); } @Override public void failed(Service.State from, Throwable failure) { LOG.error("Service " + name + " failed", failure); future.setException(failure); } }; }
From source file:co.cask.tigon.internal.app.runtime.flow.FlowletProgramController.java
private void listenDriveState(FlowletProcessDriver driver) { driver.addListener(new ServiceListenerAdapter() { @Override/*from ww w . j a va2 s .c o m*/ public void running() { started(); } @Override public void failed(Service.State from, Throwable failure) { LOG.error("Flowlet terminated with exception", failure); error(failure); } @Override public void terminated(Service.State from) { if (getState() != State.STOPPING) { LOG.warn("Flowlet terminated by itself"); // Close all consumers for (ConsumerSupplier consumerSupplier : consumerSuppliers) { Closeables.closeQuietly(consumerSupplier); } } } }, Threads.SAME_THREAD_EXECUTOR); }
From source file:co.cask.tigon.internal.app.runtime.distributed.AbstractServiceTwillRunnable.java
private Service.Listener createServiceListener(final SettableFuture<Service.State> completion) { return new ServiceListenerAdapter() { @Override//from w ww . ja va 2 s.co m public void terminated(Service.State from) { completion.set(from); } @Override public void failed(Service.State from, Throwable failure) { completion.setException(failure); } }; }