本文整理汇总了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
}
}
示例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;
}
示例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();
}
}