当前位置: 首页>>代码示例>>Java>>正文


Java Service.startAndWait方法代码示例

本文整理汇总了Java中com.google.common.util.concurrent.Service.startAndWait方法的典型用法代码示例。如果您正苦于以下问题:Java Service.startAndWait方法的具体用法?Java Service.startAndWait怎么用?Java Service.startAndWait使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.util.concurrent.Service的用法示例。


在下文中一共展示了Service.startAndWait方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: startUp

import com.google.common.util.concurrent.Service; //导入方法依赖的package包/类
@Override
protected void startUp() throws Exception {
  Throwable failureCause = null;

  for (Service service : services) {
    try {
      service.startAndWait();
    } catch (UncheckedExecutionException e) {
      failureCause = e.getCause();
      break;
    }
  }

  if (failureCause != null) {
    // Stop all running services and then throw the failure exception
    try {
      stopAll();
    } catch (Throwable t) {
      // Ignore the stop error. Just log.
      LOG.warn("Failed when stopping all services on start failure", t);
    }

    Throwables.propagateIfPossible(failureCause, Exception.class);
    throw new RuntimeException(failureCause);
  }
}
 
开发者ID:apache,项目名称:twill,代码行数:27,代码来源:CompositeService.java

示例2: testCompletion

import com.google.common.util.concurrent.Service; //导入方法依赖的package包/类
@Test
public void testCompletion() throws ExecutionException, InterruptedException {
  Service service = new DummyService("s1", new AtomicBoolean());
  ListenableFuture<Service.State> completion = Services.getCompletionFuture(service);

  service.start();
  service.stop();

  completion.get();

  AtomicBoolean transiting = new AtomicBoolean();
  service = new DummyService("s2", transiting);
  completion = Services.getCompletionFuture(service);

  service.startAndWait();
  transiting.set(true);
  service.stop();

  try {
    completion.get();
    Assert.assertTrue(false);
  } catch (ExecutionException e) {
    // Expected
  }
}
 
开发者ID:apache,项目名称:twill,代码行数:26,代码来源:ServicesTest.java

示例3: testController

import com.google.common.util.concurrent.Service; //导入方法依赖的package包/类
@Test
public void testController() throws ExecutionException, InterruptedException, TimeoutException {
  InMemoryZKServer zkServer = InMemoryZKServer.builder().build();
  zkServer.startAndWait();

  LOG.info("ZKServer: " + zkServer.getConnectionStr());

  try {
    RunId runId = RunIds.generate();
    ZKClientService zkClientService = ZKClientService.Builder.of(zkServer.getConnectionStr()).build();
    zkClientService.startAndWait();

    Service service = createService(zkClientService, runId);
    service.startAndWait();

    TwillController controller = getController(zkClientService, "testController", runId);
    controller.sendCommand(Command.Builder.of("test").build()).get(2, TimeUnit.SECONDS);
    controller.terminate().get(2, TimeUnit.SECONDS);

    final CountDownLatch terminateLatch = new CountDownLatch(1);
    service.addListener(new ServiceListenerAdapter() {
      @Override
      public void terminated(Service.State from) {
        terminateLatch.countDown();
      }
    }, Threads.SAME_THREAD_EXECUTOR);

    Assert.assertTrue(service.state() == Service.State.TERMINATED || terminateLatch.await(2, TimeUnit.SECONDS));

    zkClientService.stopAndWait();

  } finally {
    zkServer.stopAndWait();
  }
}
 
开发者ID:apache,项目名称:twill,代码行数:36,代码来源:ControllerTest.java

示例4: testControllerListener

import com.google.common.util.concurrent.Service; //导入方法依赖的package包/类
@Test
public void testControllerListener() throws InterruptedException {
  InMemoryZKServer zkServer = InMemoryZKServer.builder().build();
  zkServer.startAndWait();

  LOG.info("ZKServer: " + zkServer.getConnectionStr());
  try {
    RunId runId = RunIds.generate();
    ZKClientService zkClientService = ZKClientService.Builder.of(zkServer.getConnectionStr()).build();
    zkClientService.startAndWait();

    Service service = createService(zkClientService, runId);
    service.startAndWait();

    final CountDownLatch runLatch = new CountDownLatch(1);
    TwillController controller = getController(zkClientService, "testControllerListener", runId);
    controller.onRunning(new Runnable() {
      @Override
      public void run() {
        runLatch.countDown();
      }
    }, Threads.SAME_THREAD_EXECUTOR);

    Assert.assertTrue(runLatch.await(2, TimeUnit.SECONDS));

    service.stopAndWait();

    zkClientService.stopAndWait();
  } finally {
    zkServer.stopAndWait();
  }
}
 
开发者ID:apache,项目名称:twill,代码行数:33,代码来源:ControllerTest.java


注:本文中的com.google.common.util.concurrent.Service.startAndWait方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。