Guava Service - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Guava Service class.

This code example shows how to use the following methods:startAndWait, 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 
    } 
  } 
 
  private static final class DummyService extends AbstractIdleService {
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:stopAndWait
	} 
 
	@After 
	public void stopService() { 
		if (null != server) {
			server.stopAndWait();
		} 
	} 
 
	private static int getRandomPort() { 
		synchronized (RANDOM) {
			return DEFAULT_PORT + RANDOM.nextInt(1000);
		} 
	} 
 
	public void assertDownloadedFileEquals(String file) {
		try { 
			assertDownloadedFileEquals(new URL("file:" + file));
		} catch (MalformedURLException e) {
			throw Throwables.propagate(e);
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:startAsync
  public void testSchedulerStartup() throws Exception {
    updater.systemResume();
 
    control.replay(); 
 
    service.startAsync().awaitRunning();
  } 
 
  @Test
  public void testHandlesExceptions() throws Exception {
    updater.systemResume();
    expectLastCall().andThrow(new RuntimeException());
    updater.instanceChangedState(TASK);
    expectLastCall().andThrow(new RuntimeException());
    updater.instanceDeleted(INSTANCE_A);
    expectLastCall().andThrow(new RuntimeException());
 
    control.replay(); 
 
    service.startAsync().awaitRunning();
3
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Guava Service Methods: