Adding AdapterFinderBean and interceptor functionality. #34744
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.