Class DataRouteSupportUtil
java.lang.Object
com.broadleafcommerce.common.extension.data.DataRouteSupportUtil
Utility class for processing and handling of route scenarios at runtime.
- Author:
- Jeff Fischer
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Perform a task and return a confirmation in the form of a boolean.static interface
Perform a task and return an arbitrary object instance as response.static interface
Perform a task and return nothing, but expose a checked exception.static interface
Perform a task and return nothing. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> List<T>
findMembersInScopeByExample
(List<T> beans, DataRouteReference reference, Class<?> example) Given a list of bean instances, filter the list based on the example class' package name, which is used to identity the package fragment for the current flow.static <T> List<T>
findMembersInScopeByFragment
(List<T> beans, DataRouteReference reference, String fragment) Given a list of bean instances, filter the list based on the package fragment identifying the current flow.static <T> T
getBestMatchInRoute
(List<T> beans, DataRouteReference reference, T defaultBean) Using the currentDataRouteContext.getLookupKey()
to match aDataRouteSupporting
, and find the first bean whose whose class package name has a package fragment match.Check for a current, activeDataRouteContext
, and return the lookupKey if available.static void
processAllOrOnce
(List<? extends DataRouteSupporting> supportingRoutes, DataRouteSupportUtil.VoidWork work, Class<?>... refineTypes) Given a piece of void work, execute the work repeatedly against all the supplied routes.static boolean
processFirstOrOnce
(List<? extends DataRouteSupporting> supportingRoutes, DataRouteSupportUtil.ConfirmingWork work, Class<?>... refineTypes) Given a piece of confirming work, execute the work against the supplied routes looking for the first positive confirmation.static boolean
Given a piece of confirming work, execute the work against the supplied route.static Object
Given a piece of returning work, execute the work against the supplied route.static <G extends Exception>
voidprocessOnRoute
(DataRouteSupportUtil.ThrowingVoidWork<G> work, DataRouteSupporting route, Class<G> exceptionClass) Given a piece of void work, execute the work against the supplied route.static void
Given a piece of void work, execute the work against the supplied route.static <T> T
proxyForDataRoute
(T bean, DataRouteSupporting route) Given a component, wrap the component in an AOP proxy that will guarantee any call on the component's API will have theDataRouteSupporting.getLookupKey()
set onDataRouteContext.setLookupKey(String)
during execution.
-
Constructor Details
-
DataRouteSupportUtil
public DataRouteSupportUtil()
-
-
Method Details
-
processFirstOrOnce
public static boolean processFirstOrOnce(@Nullable List<? extends DataRouteSupporting> supportingRoutes, @NonNull DataRouteSupportUtil.ConfirmingWork work, @NonNull Class<?>... refineTypes) Given a piece of confirming work, execute the work against the supplied routes looking for the first positive confirmation. However, if no routes are supplied, simply execute the work and return the response without route support. The ConfirmingWork implementation should take care to make its own validity determination and return immediately with false if it determines itself to not be qualified to execute against the current route.- Parameters:
supportingRoutes
- Optional list ofDataRouteSupporting
proxies.work
- The task to perform.refineTypes
- One or more specificDataRouteSupporting
extension types to filter the supportingRoutes by.- Returns:
- The result of the confirming work.
-
processAllOrOnce
public static void processAllOrOnce(@Nullable List<? extends DataRouteSupporting> supportingRoutes, @NonNull DataRouteSupportUtil.VoidWork work, @NonNull Class<?>... refineTypes) Given a piece of void work, execute the work repeatedly against all the supplied routes. Or, if no routes are supplied, execute the work once with no routing support.- Parameters:
supportingRoutes
- Optional list ofDataRouteSupporting
proxies.work
- The task to perform.refineTypes
- One or more specificDataRouteSupporting
extension types to filter the supportingRoutes by.
-
processOnRoute
public static boolean processOnRoute(@NonNull DataRouteSupportUtil.ConfirmingWork work, @Nullable DataRouteSupporting route) Given a piece of confirming work, execute the work against the supplied route. If no route is supplied, simply execute the work without route support.- Parameters:
work
- The task to perform.route
- TheDataRouteSupporting
proxy whose lookupKey is in effect during execution of the task.- Returns:
- The result of the confirming work.
-
processOnRoute
public static void processOnRoute(@NonNull DataRouteSupportUtil.VoidWork work, @Nullable DataRouteSupporting route) Given a piece of void work, execute the work against the supplied route. If no route is supplied, simply execute the work without route support.- Parameters:
work
- The task to perform.route
- TheDataRouteSupporting
proxy whose lookupKey is in effect during execution of the task.
-
processOnRoute
public static <G extends Exception> void processOnRoute(@NonNull DataRouteSupportUtil.ThrowingVoidWork<G> work, @Nullable DataRouteSupporting route, Class<G> exceptionClass) throws G Given a piece of void work, execute the work against the supplied route. If no route is supplied, simply execute the work without route support.- Type Parameters:
G
- The generic type of the checked exception.- Parameters:
work
- The task to perform.route
- TheDataRouteSupporting
proxy whose lookupKey is in effect during execution of the task.exceptionClass
- The class of the checked exception that can be thrown by the task execution.- Throws:
G
- The generic type of the checked exception.
-
processOnRoute
public static Object processOnRoute(@NonNull DataRouteSupportUtil.ReturningWork work, @Nullable DataRouteSupporting route) Given a piece of returning work, execute the work against the supplied route. If no route is supplied, simply execute the work without route support.- Parameters:
work
- The task to perform.route
- TheDataRouteSupporting
proxy whose lookupKey is in effect during execution of the task.- Returns:
- The response returned from the task execution.
-
proxyForDataRoute
Given a component, wrap the component in an AOP proxy that will guarantee any call on the component's API will have theDataRouteSupporting.getLookupKey()
set onDataRouteContext.setLookupKey(String)
during execution.- Type Parameters:
T
- The generic type of the bean.- Parameters:
bean
- The bean instance to wrap in a proxy.route
- The route whose lookup key is to be used.- Returns:
- The proxied bean instance.
-
findMembersInScopeByFragment
public static <T> List<T> findMembersInScopeByFragment(@NonNull List<T> beans, @Nullable DataRouteReference reference, @NonNull String fragment) Given a list of bean instances, filter the list based on the package fragment identifying the current flow. This is useful in identifying beans contributed from multiple routes that all participate in pipeline style processing. When on a subset of the processing beans should be used for a particular flow, this method can filter the superset to achieve the right mix. Note, this method is sophisticated enough to include beans defined in common libraries that cross-cut multiple services, as well as those defined specifically in the service itself.- Type Parameters:
T
- The generic type of the processing components.- Parameters:
beans
- The list of processing components that should be filtered for the current flow.reference
- Used to help look up routes based on the fragment.fragment
- Package fragment identifying the current flow.- Returns:
- The filtered list.
-
findMembersInScopeByExample
public static <T> List<T> findMembersInScopeByExample(@NonNull List<T> beans, @Nullable DataRouteReference reference, @NonNull Class<?> example) Given a list of bean instances, filter the list based on the example class' package name, which is used to identity the package fragment for the current flow. This is useful in identifying beans contributed from multiple routes that all participate in pipeline style processing. When on a subset of the processing beans should be used for a particular flow, this method can filter the superset to achieve the right mix. Note, this method is sophisticated enough to include beans defined in common libraries that cross-cut multiple services, as well as those defined specifically in the service itself.- Type Parameters:
T
- The generic type of the processing components.- Parameters:
beans
- The list of processing components that should be filtered for the current flow.reference
- Used to help look up routes based on the fragment.example
- Class whose package name is used to identify the package fragment for the current flow.- Returns:
- The filtered list.
-
getBestMatchInRoute
public static <T> T getBestMatchInRoute(@NonNull List<T> beans, @Nullable DataRouteReference reference, T defaultBean) Using the currentDataRouteContext.getLookupKey()
to match aDataRouteSupporting
, and find the first bean whose whose class package name has a package fragment match. If no match is found, or the reference param is null, return the default bean.- Type Parameters:
T
- The type of the bean.- Parameters:
beans
- The list of beans to filter to the best single match.reference
- Used to help look up routes based on the fragment.defaultBean
- The bean to return if no match is found.- Returns:
- The filtered bean instance.
-
getLookupKeyOnRoute
Check for a current, activeDataRouteContext
, and return the lookupKey if available.- Returns:
- The active
DataRouteContext.getLookupKey()
, if available.
-