-
Notifications
You must be signed in to change notification settings - Fork 35
Added client call decorator feature #1200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
f7da05b
72dc964
1d6e17f
669f55d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package software.amazon.smithy.java.client.core; | ||
|
|
||
| import software.amazon.smithy.java.core.schema.ApiOperation; | ||
| import software.amazon.smithy.java.core.schema.SerializableStruct; | ||
|
|
||
| /** | ||
| * A decorator that wraps client call execution, allowing cross-cutting behavior to be applied | ||
| * around operation invocations. | ||
| * | ||
| * <p>Implementations can inspect or modify the input, add logging, metrics, caching, or other | ||
| * concerns before delegating to the next invoker in the chain. | ||
| * | ||
| * @param <C> the client type this decorator is applied to. | ||
| */ | ||
| @FunctionalInterface | ||
| public interface ClientCallDecorator<C> { | ||
| /** | ||
| * Applies decoration logic around a client call. | ||
| * | ||
| * @param client the client instance making the call. | ||
| * @param operation the API operation being invoked. | ||
| * @param input the operation input. | ||
| * @param overrideConfig optional per-request configuration overrides, or {@code null}. | ||
| * @param next the next invoker in the chain to delegate the actual call to. | ||
| * @param <I> the input type. | ||
| * @param <O> the output type. | ||
| * @return the operation output. | ||
| */ | ||
| <I extends SerializableStruct, O extends SerializableStruct> O apply( | ||
| C client, | ||
| ApiOperation<I, O> operation, | ||
| I input, | ||
| RequestOverrideConfig overrideConfig, | ||
| ClientCallInvoker next | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package software.amazon.smithy.java.client.core; | ||
|
|
||
| import software.amazon.smithy.java.core.schema.ApiOperation; | ||
| import software.amazon.smithy.java.core.schema.SerializableStruct; | ||
|
|
||
| /** | ||
| * Invokes a client operation call with the given input and configuration. | ||
| * | ||
| * <p>This functional interface represents the core call execution logic that a | ||
| * {@link ClientCallDecorator} delegates to after applying its decoration. | ||
| */ | ||
| @FunctionalInterface | ||
| public interface ClientCallInvoker { | ||
| /** | ||
| * Invokes the operation. | ||
| * | ||
| * @param input the operation input. | ||
| * @param operation the API operation being invoked. | ||
| * @param overrideConfig optional per-request configuration overrides, or {@code null}. | ||
| * @param <I> the input type. | ||
| * @param <O> the output type. | ||
| * @return the operation output. | ||
| */ | ||
| <I extends SerializableStruct, O extends SerializableStruct> O invoke( | ||
| I input, | ||
| ApiOperation<I, O> operation, | ||
| RequestOverrideConfig overrideConfig | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,7 +74,12 @@ List<IdentityResolver<?>> identityResolvers() { | |
| return identityResolvers; | ||
| } | ||
|
|
||
| Context context() { | ||
| /** | ||
| * Get the context of the override request config. | ||
| * | ||
| * @return the context. | ||
| */ | ||
| public Context context() { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One potential "issue" of this change I see is that call decorators now would be able to modify the context (so it is not a readonly), but maybe it is not an issue as the context is being exposed to hooks already where they could do the same before).
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, it currently kind of blurs the line between override and given context. Maybe we just add one more argument to the two interfaces and pass Context? It’s a lot of arguments, but seems necessary (and I want to avoid a kind of wrapper allocation for this since it’ll be a hot path).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking about it and it felt like it might be a bit ambiguous as in hooks we have context that is "merged" (or whichever takes precedence) with client's default context, but here we're mostly interested in the override context? Maybe its just me. Another thought, do you think we should keep the RequestOverrideConfig in the arguments of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I guess thats fine since the implementation can always take client's current context and do its own logic for "overrides" if needed, at least for now.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mtdowling pushed the changes in 1d6e17f and 669f55d
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. Gonna take a deeper look at this. Wondering if we can just not send RequestOverride somehow by resolving stuff before the decorator. Alternatively, expose ClientCall or a stripped down version of as an interface that exposes less than the internal ClientCall. Not sure. |
||
| return context; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.