- Notifications
You must be signed in to change notification settings - Fork38.9k
Adding AdapterFinderBean and interceptor functionality.#34744
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
joe-chambers wants to merge1 commit intospring-projects:mainChoose a base branch fromjoe-chambers:adapter-locator
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
AdapterFinderBean and AdapterFinderInterceptor allow for similarfunctionality to ServiceLocatorFactoryBean but without the call fromthe client to find the appropriate service bean for each call.It would be anticipated that spring-boot functionality would becreated in the future to search the bean definition registry afterthe registry is created to find finder beans and build proxies forthe interfaces exposed by them and register those implementationswithin the application context.Signed-off-by: Joe Chambers <25091819+joe-chambers@users.noreply.github.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Labels
in: coreIssues in core modules (aop, beans, core, context, expression) status: waiting-for-triageAn issue we've not yet triaged or decided on
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AdapterFinderBean and AdapterFinderInterceptor allow for similar functionality to ServiceLocatorFactoryBean but without the call from the client to find the appropriate service bean for each call. This crosscutting concern can be implemented in an "AdapterFinderBean" used by an "AdapterFinderInterceptor" proxy bean that directs the method call to the "Adapter" returned by the "AdapterFinderBean"
Problem:
A business logic process such as "shipping" requires access to multiple services i.e. UPS, USPS, DHL, and FEDEX existing solutions at best require cluttering the client space with calls to find the service and then call it. When expanding from a single shipping service to an array of adapters this requires significant changes throughout the coad base with client pollution.
Solution:
In order to reduce the client side polution and make a flexible system, an AdapterFinderBean can be implemented so that it has access to each implementation by "Qualifier" and based on one or more of the method parameters (TenantId, CustomerId, OrderId, etc...) the finder determines which implementation of the defined Adapter interface to return.
Example
Each implementation has an Adapter implementation of a defined interface e.g. UPSShippingAdapter, USPSShippingAdapter, DHLShippingAdapter, and FEDEXShippingAdapter all implementations of the ShippingAdapter interface.
A "Finder" ShippingAdapterFinder implements the AdapterFinderBean with qualifier based access to all of the ShippingAdapter implementations. The finder returns the appropriate implementation based on the parameters passed in to each call such as TenantId, CustomerId, OrderId, and etc....
The AdapterFinderInterceptor is used to construct a "Proxy" of the ShippingAdapter that will query the "ShippingAdapterFinder" to determine which concrete implementation to pass the method call on to.
Additionally this same structures could be used to lookup based on feature flags, or properties (potentially a beta vs legacy) or versions i.e. a telephone system where the east coast (US) has upgraded from version 14 of the SIP server to version 16, but central, and west coast (US) have not.
Further
It is thought that a spring-cloud or spring-boot implementation could look through the bean definition registry to find implementations of the AdapterFinderBean, and create a "Primary" instance of the interface the AdapterFinderBean returns that is proxy bean that uses the finder in the application context.
Please excuse the terminology, you probably have better terminology this is my first PR into the spring ecosystem.