From 8c48e157e839bc5e1c4d7d25b36e525859621069 Mon Sep 17 00:00:00 2001 From: jrhee17 Date: Tue, 3 Dec 2024 16:41:43 +0900 Subject: [PATCH] cleanups --- .../armeria/client/ContextInitializer.java | 10 ++-------- .../client/DefaultClientBuilderParams.java | 12 ++---------- .../armeria/client/DefaultWebClient.java | 4 ++-- .../EndpointGroupContextInitializer.java | 4 ++-- .../armeria/client/CustomContextInitTest.java | 4 ++-- .../internal/client/grpc/ArmeriaChannel.java | 2 +- .../client/thrift/DefaultTHttpClient.java | 2 +- .../client/endpoint/XdsContextInitializer.java | 18 ++---------------- 8 files changed, 14 insertions(+), 42 deletions(-) diff --git a/core/src/main/java/com/linecorp/armeria/client/ContextInitializer.java b/core/src/main/java/com/linecorp/armeria/client/ContextInitializer.java index 3418a8e6752..143365a6c71 100644 --- a/core/src/main/java/com/linecorp/armeria/client/ContextInitializer.java +++ b/core/src/main/java/com/linecorp/armeria/client/ContextInitializer.java @@ -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. @@ -74,10 +74,4 @@ default EndpointGroup endpointGroup() { default SessionProtocol sessionProtocol() { return SessionProtocol.UNDETERMINED; } - - /** - * TBU. - */ - default void validate(ClientBuilderParams params) { - } } diff --git a/core/src/main/java/com/linecorp/armeria/client/DefaultClientBuilderParams.java b/core/src/main/java/com/linecorp/armeria/client/DefaultClientBuilderParams.java index edd562f79c3..b4fe1536fdf 100644 --- a/core/src/main/java/com/linecorp/armeria/client/DefaultClientBuilderParams.java +++ b/core/src/main/java/com/linecorp/armeria/client/DefaultClientBuilderParams.java @@ -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; @@ -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; @@ -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, @@ -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() + @@ -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, diff --git a/core/src/main/java/com/linecorp/armeria/client/DefaultWebClient.java b/core/src/main/java/com/linecorp/armeria/client/DefaultWebClient.java index 40602c03080..5a855be9123 100644 --- a/core/src/main/java/com/linecorp/armeria/client/DefaultWebClient.java +++ b/core/src/main/java/com/linecorp/armeria/client/DefaultWebClient.java @@ -142,7 +142,7 @@ public ExecutionContext 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( @@ -150,7 +150,7 @@ public ExecutionContext executionContext(HttpRequest req, RequestO "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() { @Override diff --git a/core/src/main/java/com/linecorp/armeria/internal/client/EndpointGroupContextInitializer.java b/core/src/main/java/com/linecorp/armeria/internal/client/EndpointGroupContextInitializer.java index cead7f099e1..efd19038eec 100644 --- a/core/src/main/java/com/linecorp/armeria/internal/client/EndpointGroupContextInitializer.java +++ b/core/src/main/java/com/linecorp/armeria/internal/client/EndpointGroupContextInitializer.java @@ -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); diff --git a/core/src/test/java/com/linecorp/armeria/client/CustomContextInitTest.java b/core/src/test/java/com/linecorp/armeria/client/CustomContextInitTest.java index 16a0cfdaa86..8557d202b19 100644 --- a/core/src/test/java/com/linecorp/armeria/client/CustomContextInitTest.java +++ b/core/src/test/java/com/linecorp/armeria/client/CustomContextInitTest.java @@ -68,9 +68,9 @@ void specifyEventLoops() { final ArrayList 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) diff --git a/grpc/src/main/java/com/linecorp/armeria/internal/client/grpc/ArmeriaChannel.java b/grpc/src/main/java/com/linecorp/armeria/internal/client/grpc/ArmeriaChannel.java index 8d1fe90fffb..5017f015fcf 100644 --- a/grpc/src/main/java/com/linecorp/armeria/internal/client/grpc/ArmeriaChannel.java +++ b/grpc/src/main/java/com/linecorp/armeria/internal/client/grpc/ArmeriaChannel.java @@ -168,7 +168,7 @@ public ClientCall newCall(MethodDescriptor 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); diff --git a/thrift/thrift0.13/src/main/java/com/linecorp/armeria/internal/client/thrift/DefaultTHttpClient.java b/thrift/thrift0.13/src/main/java/com/linecorp/armeria/internal/client/thrift/DefaultTHttpClient.java index 653f7c62689..a67314cfeab 100644 --- a/thrift/thrift0.13/src/main/java/com/linecorp/armeria/internal/client/thrift/DefaultTHttpClient.java +++ b/thrift/thrift0.13/src/main/java/com/linecorp/armeria/internal/client/thrift/DefaultTHttpClient.java @@ -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); diff --git a/xds/src/main/java/com/linecorp/armeria/xds/client/endpoint/XdsContextInitializer.java b/xds/src/main/java/com/linecorp/armeria/xds/client/endpoint/XdsContextInitializer.java index 9a18d2a0023..3b22e9bebd9 100644 --- a/xds/src/main/java/com/linecorp/armeria/xds/client/endpoint/XdsContextInitializer.java +++ b/xds/src/main/java/com/linecorp/armeria/xds/client/endpoint/XdsContextInitializer.java @@ -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; @@ -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, @@ -99,15 +96,4 @@ O execute(Client 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()); - } }