/** * Returns a fake {@link Channel} which is required internally when creating a context. */ protected final Channel fakeChannel() { if (channel == null) { channel = new FakeChannel(eventLoop(), alloc(), remoteAddress(), localAddress()); } return channel; }
/** * Returns the {@link System#nanoTime()} value when the request started. * * @throws IllegalStateException if the request start time is unspecified. */ protected final long requestStartTimeNanos() { checkState(isRequestStartTimeSet(), "requestStartTime is not set."); return requestStartTimeNanos; }
@Override public ClientRequestContextBuilder method(HttpMethod method) { super.method(method); return this; }
/** * Sets the request start time of the request. * * @param requestStartTimeNanos the {@link System#nanoTime()} value when the request started. * @param requestStartTimeMicros the number of microseconds since the epoch when the request started. */ public final B requestStartTime(long requestStartTimeNanos, long requestStartTimeMicros) { this.requestStartTimeNanos = requestStartTimeNanos; this.requestStartTimeMicros = requestStartTimeMicros; requestStartTimeSet = true; return self(); }
/** * Returns the local socket address of the connection. */ protected final InetSocketAddress localAddress() { if (localAddress == null) { if (server) { localAddress = new InetSocketAddress(NetUtil.LOCALHOST, guessServerPort(sessionProtocol, authority)); } else { localAddress = new InetSocketAddress(NetUtil.LOCALHOST, randomClientPort()); } } return localAddress; }
/** * Sets the {@link SSLSession} of the connection. If the current {@link SessionProtocol} is not TLS, * the TLS version of the current {@link SessionProtocol} will be set automatically. For example, * {@link SessionProtocol#H2C} will be automatically upgraded to {@link SessionProtocol#H2}. * Note that upgrading the current {@link SessionProtocol} may trigger an {@link IllegalArgumentException}, * as described in {@link #sessionProtocol(SessionProtocol)}. */ public final B sslSession(SSLSession sslSession) { this.sslSession = requireNonNull(sslSession, "sslSession"); switch (sessionProtocol) { case HTTP: sessionProtocol(SessionProtocol.HTTPS); break; case H1C: sessionProtocol(SessionProtocol.H1); break; case H2C: sessionProtocol(SessionProtocol.H2); break; } return self(); }
/** * Sets the local socket address of the connection. If not set, it is auto-generated with the localhost * IP address (e.g. {@code "127.0.0.1"} or {@code "::1"}). */ public final B localAddress(InetSocketAddress localAddress) { this.localAddress = requireNonNull(localAddress, "localAddress"); return self(); }
/** * Returns the remote socket address of the connection. */ protected final InetSocketAddress remoteAddress() { if (remoteAddress == null) { if (server) { remoteAddress = new InetSocketAddress(NetUtil.LOCALHOST, randomClientPort()); } else { remoteAddress = new InetSocketAddress(NetUtil.LOCALHOST, guessServerPort(sessionProtocol, authority)); } } return remoteAddress; }
/** * Sets the {@link MeterRegistry}. If not set, {@link NoopMeterRegistry} is used. */ public final B meterRegistry(MeterRegistry meterRegistry) { this.meterRegistry = requireNonNull(meterRegistry, "meterRegistry"); return self(); }
/** * Returns the number of microseconds since the epoch when the request started. * * @throws IllegalStateException if the request start time is unspecified. */ protected final long requestStartTimeMicros() { checkState(isRequestStartTimeSet(), "requestStartTime is not set."); return requestStartTimeMicros; }
/** * Sets the {@link EventLoop} that handles the request. * If not set, one of the {@link CommonPools#workerGroup()} is used. */ public final B eventLoop(EventLoop eventLoop) { this.eventLoop = requireNonNull(eventLoop, "eventLoop"); return self(); }
/** * Sets the remote socket address of the connection. If not set, it is auto-generated with the localhost * IP address (e.g. {@code "127.0.0.1"} or {@code "::1"}). */ public final B remoteAddress(InetSocketAddress remoteAddress) { this.remoteAddress = requireNonNull(remoteAddress, "remoteAddress"); return self(); }
/** * Sets the {@link ByteBufAllocator}. If not set, {@link ByteBufAllocator#DEFAULT} is used. */ public final B alloc(ByteBufAllocator alloc) { this.alloc = requireNonNull(alloc, "alloc"); return self(); }
/** * Sets the {@link SessionProtocol} of the request. * * @throws IllegalArgumentException if the specified {@link SessionProtocol} is not compatible with * the scheme of the {@link URI} you specified when creating this builder. * For example, you cannot specify {@link SessionProtocol#H2C} if you * created this builder with {@code h1c://example.com/}. */ public final B sessionProtocol(SessionProtocol sessionProtocol) { requireNonNull(sessionProtocol, "sessionProtocol"); if (request instanceof RpcRequest) { checkArgument(sessionProtocol == this.sessionProtocol, "sessionProtocol: %s (expected: same as the session protocol specified in 'uri')", sessionProtocol); } else { this.sessionProtocol = sessionProtocol; } return self(); }
/** * Sets the {@link HttpMethod} of the request. * * @throws IllegalArgumentException if the specified {@link HttpMethod} is not same with the * {@link HttpMethod} of the {@link HttpRequest} you specified when * creating this builder. This exception is not thrown if you * created a builder with an {@link RpcRequest}. */ protected B method(HttpMethod method) { requireNonNull(method, "method"); if (request instanceof HttpRequest) { checkArgument(method == ((HttpRequest) request).method(), "method: %s (expected: same as request.method)", method); } else { this.method = method; } return self(); }