Java Code Examples for com.linecorp.armeria.server.ServiceRequestContext#requestTimeoutMillis()

The following examples show how to use com.linecorp.armeria.server.ServiceRequestContext#requestTimeoutMillis() . 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: CentralDogmaTimeoutScheduler.java    From centraldogma with Apache License 2.0 6 votes vote down vote up
@Override
public RpcResponse serve(ServiceRequestContext ctx, RpcRequest req) throws Exception {
    if (ctx.requestTimeoutMillis() > 0) {
        final String method = req.method();
        if ("watchFile".equals(method) || "watchRepository".equals(method)) {
            final List<Object> params = req.params();
            final long timeout = (Long) params.get(params.size() - 1);
            if (timeout > 0) {
                ctx.setRequestTimeoutMillis(
                        TimeoutMode.EXTEND,
                        WatchTimeout.availableTimeout(timeout, ctx.requestTimeoutMillis()));
            }
        }
    }

    return unwrap().serve(ctx, req);
}
 
Example 2
Source File: HealthCheckService.java    From armeria with Apache License 2.0 5 votes vote down vote up
/**
 * Extends the request timeout by the specified {@code longPollingTimeoutMillis}, because otherwise
 * the client will get {@code "503 Service Unavailable} due to a {@link RequestTimeoutException} before
 * long-polling finishes.
 */
private static void updateRequestTimeout(ServiceRequestContext ctx, long longPollingTimeoutMillis) {
    final long requestTimeoutMillis = ctx.requestTimeoutMillis();
    if (requestTimeoutMillis > 0) {
        ctx.setRequestTimeoutMillis(TimeoutMode.EXTEND, longPollingTimeoutMillis);
    }
}