Example usage for com.google.common.util.concurrent Service awaitRunning

List of usage examples for com.google.common.util.concurrent Service awaitRunning

Introduction

In this page you can find the example usage for com.google.common.util.concurrent Service awaitRunning.

Prototype

void awaitRunning(long timeout, TimeUnit unit) throws TimeoutException;

Source Link

Document

Waits for the Service to reach the State#RUNNING running state for no more than the given time.

Usage

From source file:co.runrightfast.core.utils.ServiceUtils.java

/**
 * Logs a warning every 10 seconds, waiting for the service to start
 *
 * @param service Service/*from ww  w .j  a va 2s  . co m*/
 */
static void awaitRunning(@NonNull final Service service) {
    while (true) {
        try {
            service.awaitRunning(10, TimeUnit.SECONDS);
            return;
        } catch (final TimeoutException ex) {
            LOG.logp(WARNING, ServiceUtils.class.getName(), "awaitTerminated",
                    "Wating for service to start : {0}", service.getClass().getName());
        }
    }
}

From source file:co.runrightfast.commons.utils.ServiceUtils.java

/**
 * Logs a warning every 10 seconds, waiting for the service to start
 *
 * @param service Service// w w w.  j  ava 2  s .c om
 */
public static void awaitRunning(@NonNull final Service service) {
    for (int i = 1; true; i++) {
        try {
            service.awaitRunning(10, TimeUnit.SECONDS);
            return;
        } catch (final TimeoutException ex) {
            final int elapsedTimeSeconds = i * 10;
            log.warn(String.format("Wating for service to start : %s : %d seconds",
                    service.getClass().getName(), elapsedTimeSeconds), new ApplicationException(MAJOR, ex));
        }
    }
}