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


Java Service.start方法代码示例

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


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

示例1: 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

示例2: doChain

import com.google.common.util.concurrent.Service; //导入方法依赖的package包/类
/**
 * Performs the actual logic of chain Service start/stop.
 */
private static ListenableFuture<List<ListenableFuture<Service.State>>> doChain(boolean doStart,
                                                                               Service firstService,
                                                                               Service...moreServices) {
  SettableFuture<List<ListenableFuture<Service.State>>> resultFuture = SettableFuture.create();
  List<ListenableFuture<Service.State>> result = Lists.newArrayListWithCapacity(moreServices.length + 1);

  ListenableFuture<Service.State> future = doStart ? firstService.start() : firstService.stop();
  future.addListener(createChainListener(future, moreServices, new AtomicInteger(0), result, resultFuture, doStart),
                     Threads.SAME_THREAD_EXECUTOR);
  return resultFuture;
}
 
开发者ID:apache,项目名称:twill,代码行数:15,代码来源:Services.java

示例3: testControllerBefore

import com.google.common.util.concurrent.Service; //导入方法依赖的package包/类
@Test
public void testControllerBefore() throws InterruptedException, ExecutionException, 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();

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

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

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

    try {
      controller.awaitTerminated(2, TimeUnit.SECONDS);
      Assert.fail("Service should not be terminated");
    } catch (TimeoutException e) {
      // Expected
    }

    service.stop();
    controller.awaitTerminated(120, TimeUnit.SECONDS);

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


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