Skip to content

Commit

Permalink
cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhee17 committed Dec 17, 2024
1 parent 3f945fd commit 8c48e15
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ interface ClientExecution {
* same thread as the caller. This is important to ensure backwards compatibility for APIs
* such as {@link Clients#newContextCaptor()}.
*/
ClientExecution prepare(ClientOptions clientOptions, HttpRequest httpRequest,
ClientExecution prepare(HttpRequest httpRequest,
@Nullable RpcRequest rpcRequest, RequestTarget requestTarget,
RequestOptions requestOptions);
RequestOptions requestOptions, ClientOptions clientOptions);

/**
* TBU.
Expand All @@ -74,10 +74,4 @@ default EndpointGroup endpointGroup() {
default SessionProtocol sessionProtocol() {
return SessionProtocol.UNDETERMINED;
}

/**
* TBU.
*/
default void validate(ClientBuilderParams params) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ final class DefaultClientBuilderParams implements ClientBuilderParams {
private final ContextInitializer contextInitializer;
private final Class<?> type;
private final ClientOptions options;
private final EndpointGroup endpointGroup;
private final URI uri;
private final String absolutePathRef;
final Scheme scheme;
Expand All @@ -51,7 +50,7 @@ final class DefaultClientBuilderParams implements ClientBuilderParams {
this.options = requireNonNull(options, "options");
final ClientFactory factory = requireNonNull(options, "options").factory();
this.uri = factory.validateUri(uri);
endpointGroup = Endpoint.parse(uri.getRawAuthority());
final EndpointGroup endpointGroup = Endpoint.parse(uri.getRawAuthority());
scheme = factory.validateScheme(Scheme.parse(uri.getScheme()));

final String absolutePathRef;
Expand All @@ -69,7 +68,6 @@ final class DefaultClientBuilderParams implements ClientBuilderParams {
this.absolutePathRef = absolutePathRef;

contextInitializer = new EndpointGroupContextInitializer(scheme.sessionProtocol(), endpointGroup);
contextInitializer.validate(this);
}

DefaultClientBuilderParams(SerializationFormat serializationFormat, ContextInitializer contextInitializer,
Expand All @@ -86,12 +84,7 @@ final class DefaultClientBuilderParams implements ClientBuilderParams {
} else {
schemeStr = scheme.uriText();
}
EndpointGroup endpointGroup = contextInitializer.endpointGroup();
if (endpointGroup == null) {
endpointGroup = EndpointGroup.of();
}
this.endpointGroup = endpointGroup;

final EndpointGroup endpointGroup = contextInitializer.endpointGroup();
final URI uri;
if (endpointGroup instanceof Endpoint) {
uri = URI.create(schemeStr + "://" + ((Endpoint) endpointGroup).authority() +
Expand All @@ -106,7 +99,6 @@ final class DefaultClientBuilderParams implements ClientBuilderParams {
this.absolutePathRef = normalizedAbsolutePathRef;
this.uri = factory.validateUri(uri);
this.contextInitializer = contextInitializer;
contextInitializer.validate(this);
}

private static URI dummyUri(Object key, String schemeStr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ public ExecutionContext<HttpResponse> executionContext(HttpRequest req, RequestO
throw new IllegalArgumentException("Failed to parse a scheme: " + reqTarget.scheme(), e);
}
execution = new EndpointGroupContextInitializer(parsedScheme.sessionProtocol(), endpoint)
.prepare(params().options(), newReq, null, reqTarget, requestOptions);
.prepare(newReq, null, reqTarget, requestOptions, params().options());
} else {
if (reqTarget.form() == RequestTargetForm.ABSOLUTE) {
throw new IllegalArgumentException(
"Cannot send a request with a \":path\" header that contains an authority, " +
"because the client was created with a base URI. path: " + originalPath);
}
execution = params().contextInitializer()
.prepare(params().options(), newReq, null, reqTarget, requestOptions);
.prepare(newReq, null, reqTarget, requestOptions, params().options());
}
return new ExecutionContext<HttpResponse>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public EndpointGroupContextInitializer(SessionProtocol sessionProtocol, Endpoint
}

@Override
public ClientExecution prepare(ClientOptions clientOptions, HttpRequest httpRequest,
public ClientExecution prepare(HttpRequest httpRequest,
@Nullable RpcRequest rpcRequest, RequestTarget requestTarget,
RequestOptions requestOptions) {
RequestOptions requestOptions, ClientOptions clientOptions) {
final DefaultClientRequestContext ctx = new DefaultClientRequestContext(
clientOptions.factory().meterRegistry(), sessionProtocol, httpRequest.method(),
requestTarget, clientOptions, httpRequest, rpcRequest, requestOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ void specifyEventLoops() {
final ArrayList<EventExecutor> eventExecutors = Lists.newArrayList(eventLoopGroup.get().iterator());
final WebClient client = WebClient.of(new ContextInitializer() {
@Override
public ClientExecution prepare(ClientOptions clientOptions, HttpRequest httpRequest,
public ClientExecution prepare(HttpRequest httpRequest,
@Nullable RpcRequest rpcRequest, RequestTarget requestTarget,
RequestOptions requestOptions) {
RequestOptions requestOptions, ClientOptions clientOptions) {
final ClientRequestContext ctx =
ClientRequestContext
.builder(httpRequest, rpcRequest, requestTarget)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public <I, O> ClientCall<I, O> newCall(MethodDescriptor<I, O> method, CallOption
assert reqTarget != null : path;
RequestTargetCache.putForClient(path, reqTarget);
final ClientExecution clientExecution =
params.contextInitializer().prepare(params.options(), req, null, reqTarget, requestOptions);
params.contextInitializer().prepare(req, null, reqTarget, requestOptions, params.options());
final ClientRequestContext ctx = clientExecution.ctx();

GrpcCallOptions.set(ctx, callOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private RpcResponse execute0(
.build());
try {
return params().contextInitializer()
.prepare(params().options(), httpReq, call, reqTarget, UNARY_REQUEST_OPTIONS)
.prepare(httpReq, call, reqTarget, UNARY_REQUEST_OPTIONS, params().options())
.execute(unwrap(), call);
} catch (Exception e) {
return RpcResponse.ofFailure(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@

package com.linecorp.armeria.xds.client.endpoint;

import static com.google.common.base.Preconditions.checkArgument;

import java.util.concurrent.CompletableFuture;

import com.linecorp.armeria.client.Client;
import com.linecorp.armeria.client.ClientBuilderParams;
import com.linecorp.armeria.client.ClientOptions;
import com.linecorp.armeria.client.ClientRequestContext;
import com.linecorp.armeria.client.ContextInitializer;
Expand Down Expand Up @@ -79,9 +76,9 @@ public void close() {
}

@Override
public ClientExecution prepare(ClientOptions clientOptions, HttpRequest httpRequest,
public ClientExecution prepare(HttpRequest httpRequest,
@Nullable RpcRequest rpcRequest, RequestTarget requestTarget,
RequestOptions requestOptions) {
RequestOptions requestOptions, ClientOptions clientOptions) {
final DefaultClientRequestContext ctx = new DefaultClientRequestContext(
clientOptions.factory().meterRegistry(), SessionProtocol.UNDETERMINED,
httpRequest.method(), requestTarget, clientOptions,
Expand All @@ -99,15 +96,4 @@ O execute(Client<I, O> delegate, I req) throws Exception {
}
};
}

@Override
public void validate(ClientBuilderParams params) {
validateSessionProtocol(params.scheme().sessionProtocol());
}

private void validateSessionProtocol(SessionProtocol sessionProtocol) {
checkArgument(sessionProtocol == SessionProtocol.UNDETERMINED,
"The scheme '%s' must be '%s' for %s", sessionProtocol,
SessionProtocol.UNDETERMINED, getClass().getSimpleName());
}
}

0 comments on commit 8c48e15

Please sign in to comment.