java.util.concurrent.TimeoutException

Here are the examples of the java api class java.util.concurrent.TimeoutException taken from open source projects.

1. ProcessExecutor#newTimeoutException()

Project: zt-exec
File: ProcessExecutor.java
private TimeoutException newTimeoutException(long timeout, TimeUnit unit, WaitForProcess task) {
    StringBuilder sb = new StringBuilder();
    Process process = task.getProcess();
    Integer exitValue = getExitCodeOrNull(process);
    if (exitValue == null) {
        sb.append("Timed out waiting for ").append(process).append(" to finish");
    } else {
        sb.append("Timed out finishing ").append(process);
        sb.append(", exit value: ").append(exitValue);
    }
    sb.append(", timeout: ").append(timeout).append(" ").append(getUnitsAsString(timeout, unit));
    task.addExceptionMessageSuffix(sb);
    TimeoutException result = new TimeoutException(sb.toString());
    if (exitValue != null) {
        StackTraceElement[] stackTrace = task.getStackTrace();
        if (stackTrace != null) {
            Exception cause = new Exception("Stack dump of worker thread.");
            cause.setStackTrace(stackTrace);
            result.initCause(cause);
        }
    }
    return result;
}

2. GalenPageActionWaitTest#shouldThrowException()

Project: galen
File: GalenPageActionWaitTest.java
@Test
public void shouldThrowException() throws Exception {
    GalenPageActionWait wait = new GalenPageActionWait();
    wait.setTimeout(1000);
    wait.setUntilElements(asList(until(UntilType.HIDDEN, css("div.list")), until(UntilType.VISIBLE, id("qwe")), until(UntilType.GONE, xpath("//div[@id='wqe']")), until(UntilType.EXIST, css("qweqwewqee"))));
    MockedBrowser browser = new MockedBrowser(null, null, new MockedPage());
    browser.setMockedPage(mockedPage);
    TimeoutException exception = null;
    try {
        wait.execute(new TestReport(), browser, null, null);
    } catch (TimeoutException e) {
        exception = e;
    }
    assertThat("Exception should be thrown", exception, notNullValue());
    assertThat("Exception message should be", exception.getMessage(), is("Failed waiting for:\n" + " - hidden css: div.list\n" + " - visible id: qwe\n" + " - gone xpath: //div[@id='wqe']\n" + " - exist css: qweqwewqee\n"));
}

3. MQTTEndpoint#publish()

Project: camel
File: MQTTEndpoint.java
void publish(final String topic, final byte[] payload, final QoS qoS, final boolean retain, final Callback<Void> callback) throws Exception {
    // if not connected then create a new connection to re-connect
    boolean done = isConnected();
    int attempt = 0;
    TimeoutException timeout = null;
    while (!done && attempt <= PUBLISH_MAX_RECONNECT_ATTEMPTS) {
        attempt++;
        try {
            LOG.warn("#{} attempt to re-create connection to {} before publishing", attempt, configuration.getHost());
            createConnection();
            connect();
        } catch (TimeoutException e) {
            timeout = e;
            LOG.debug("Timed out after {} seconds after {} attempt to re-create connection to {}", new Object[] { configuration.getConnectWaitInSeconds(), attempt, configuration.getHost() });
        } catch (Throwable e) {
            callback.onFailure(e);
            return;
        }
        done = isConnected();
    }
    if (attempt > 3 && !isConnected()) {
        LOG.warn("Cannot re-connect to {} after {} attempts", configuration.getHost(), attempt);
        callback.onFailure(timeout);
        return;
    }
    connection.getDispatchQueue().execute(new Task() {

        @Override
        public void run() {
            LOG.debug("Publishing to {}", configuration.getHost());
            connection.publish(topic, payload, qoS, retain, callback);
        }
    });
}