Java Code Examples for org.rapidoid.u.U#timedOut()

The following examples show how to use org.rapidoid.u.U#timedOut() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FutureImpl.java    From rapidoid with Apache License 2.0 6 votes vote down vote up
@Override
public T get(long timeoutMs, long sleepingIntervalMs) throws TimeoutException {
	long waitingSince = U.time();

	while (!isDone()) {
		if (U.timedOut(waitingSince, timeoutMs)) {
			throw new TimeoutException();
		}

		U.sleep(sleepingIntervalMs);
	}

	if (getError() != null) {
		throw U.rte("Cannot get the result, there was an error!", error);
	}

	return result;
}
 
Example 2
Source File: JdbcWorker.java    From rapidoid with Apache License 2.0 5 votes vote down vote up
@Override
protected void loop() throws Exception {

	Connection conn = null;

	try {

		long since = 0;

		do {
			Operation<Connection> op = queue.poll();

			if (op != null) {

				if (conn == null) {
					// first op
					conn = jdbc.getConnection();
					since = U.time();
				}

				op.execute(conn);

			} else {
				U.sleep(1);
				break;
			}

		} while (U.timedOut(since, batchTimeMs));

	} catch (Exception e) {
		Log.error("JDBC worker operation error!", e);

	} finally {
		if (conn != null) {
			conn.close();
		}
	}
}
 
Example 3
Source File: HttpRoutesImpl.java    From rapidoid with Apache License 2.0 4 votes vote down vote up
public boolean ready() {
	long lastChangedAt = lastChangedAt().getTime();
	return !isEmpty() && U.timedOut(lastChangedAt, ROUTE_SETUP_WAITING_TIME_MS);
}
 
Example 4
Source File: ReverseProxy.java    From rapidoid with Apache License 2.0 4 votes vote down vote up
private void handleError(Throwable error, final Req req, final Resp resp, final ProxyMapping mapping, final int attempts, final long since) {
	if (error instanceof ConnectException || error instanceof IOException) {

		if (HttpUtils.isGetReq(req) && !U.timedOut(since, timeout())) {

			Jobs.after(retryDelay()).milliseconds(() -> process(req, resp, mapping, attempts + 1, since));

		} else {
			HttpIO.INSTANCE.errorAndDone(req, U.rte("Couldn't connect to the upstream!", error), LogLevel.DEBUG);
		}

	} else {

		HttpIO.INSTANCE.errorAndDone(req, error, LogLevel.ERROR);
	}
}