Class ClientUtils
Unlike ObjectUtils, this class is specifically intended for use within Fluxzero client
applications and can make use of infrastructure components such as
Fluxzero.
It provides convenience methods for:
- Memoization with lifespans via Fluxzero's clock
- Topic resolution for annotated handler methods
- Determining whether handlers are local or self-tracking
- Time-bound execution blocking
- Safe annotation parsing and revision introspection
- Truncating
Temporalvalues
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final org.slf4j.MarkerA marker used to denote specific log entries that should be ignored or treated differently, typically to bypass error handling in logging frameworks. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringdetermineSearchCollection(@NonNull Object c) Determines the collection name used for document indexing and search based on the annotated handler or document type.static Optional<LocalHandler> getLocalHandlerAnnotation(HandlerInvoker handlerInvoker) Retrieves theLocalHandlerannotation associated with a given handler, from its method, its declaring class, or ancestral package, if present.static Optional<LocalHandler> getLocalHandlerAnnotation(Class<?> target, Executable method) Retrieves theLocalHandlerannotation associated with a given method, its declaring class, or ancestral package, if present.static intgetRevisionNumber(Object object) Extracts the revision number from theRevisionannotation on the given object’s class.static SearchParametersgetSearchParameters(Class<?> type) Returns the effectiveSearchParametersfor the given type, using theSearchableannotation.static StringgetTopic(HandleDocument handleDocument, Executable executable) Extracts the topic associated with a givenHandleDocumentannotation orExecutable.getTopics(MessageType messageType, Object handler) Extracts all topics associated with the given handler object and message type.getTopics(MessageType messageType, Collection<Class<?>> handlerClasses) Extracts all topics fromHandleDocumentorHandleCustomannotated methods for the given classes.static booleanisLocalHandler(HandlerInvoker invoker, HasMessage message) Determines if the specified handler method handles messages locally.static booleanisLocalSelfHandler(HandlerInvoker invoker, HasMessage message) Returns whether the handler method should only handle messages from the same instance ("self").static booleanisSelfTracking(Class<?> target, Executable method) Returns whether the specified method or its declaring class is marked withTrackSelf.static <T> List<T> loadServices(Class<T> serviceType) Loads implementations of the given service using Java'sServiceLoader.static <T,U, R> MemoizingBiFunction <T, U, R> memoize(BiFunction<T, U, R> supplier) Memoizes the given bi-function using a default memoization strategy.static <T,U, R> MemoizingBiFunction <T, U, R> memoize(BiFunction<T, U, R> supplier, Duration lifespan) Memoizes the given bi-function using a time-based lifespan and Fluxzero's internal clock.static <K,V> MemoizingFunction <K, V> Memoizes the given function using a default memoization strategy.static <K,V> MemoizingFunction <K, V> Memoizes the given function using a time-based lifespan and Fluxzero's internal clock.static <T> MemoizingSupplier<T> Memoizes the given supplier using a default memoization strategy.static <T> MemoizingSupplier<T> Memoizes the given supplier using a time-based lifespan and Fluxzero’s internal clock.static intResolves the configured order for the given component.static <T extends Temporal>
Ttruncate(T timestamp, TemporalUnit unit) static voidwaitForResults(Duration maxDuration, Collection<? extends Future<?>> futures) Blocks until all futures are complete or the maximum duration has elapsed.
-
Field Details
-
ignoreMarker
public static final org.slf4j.Marker ignoreMarkerA marker used to denote specific log entries that should be ignored or treated differently, typically to bypass error handling in logging frameworks.This marker is created using the
MarkerFactorywith the identifier "ignoreError". It can be useful in scenarios where certain log messages need to be flagged for exclusion from error-reporting workflows.
-
-
Constructor Details
-
ClientUtils
public ClientUtils()
-
-
Method Details
-
waitForResults
Blocks until all futures are complete or the maximum duration has elapsed.Useful for tracking batched async operations (e.g., event publishing or indexing).
- Parameters:
maxDuration- the maximum time to waitfutures- the set of futures to wait on
-
isSelfTracking
Returns whether the specified method or its declaring class is marked withTrackSelf.- Parameters:
target- the handler classmethod- the method to inspect- Returns:
trueif marked for self-tracking,falseotherwise
-
getLocalHandlerAnnotation
Retrieves theLocalHandlerannotation associated with a given handler, from its method, its declaring class, or ancestral package, if present. -
getLocalHandlerAnnotation
Retrieves theLocalHandlerannotation associated with a given method, its declaring class, or ancestral package, if present. -
isLocalHandler
Determines if the specified handler method handles messages locally. A handler is considered a local if it is explicitly annotated as such usingLocalHandleror meets the criteria for local self-handling, i.e.:isLocalSelfHandler(HandlerInvoker, HasMessage)returnstrue. -
isLocalSelfHandler
Returns whether the handler method should only handle messages from the same instance ("self"). This is true when the handler’s payload type equals the message type and noTrackSelfannotation is present. -
orderOf
Resolves the configured order for the given component.This first checks Fluxzero's own
Orderannotation and then falls back to Spring'sorg.springframework.core.annotation.Orderwhen present on the classpath.- Parameters:
component- the component to inspect- Returns:
- the configured order value, or
0if no order annotation is present
-
loadServices
Loads implementations of the given service using Java'sServiceLoader.Misconfigured providers that are present in
META-INF/servicesbut missing from the current classpath are skipped. This can happen, for example, when test resources contribute service descriptors without also exposing the corresponding provider classes to downstream modules.- Type Parameters:
T- the service type- Parameters:
serviceType- the service interface to load- Returns:
- discovered service implementations, ordered by
orderOf(Object)
-
memoize
Memoizes the given supplier using a default memoization strategy. -
memoize
Memoizes the given function using a default memoization strategy. -
memoize
Memoizes the given bi-function using a default memoization strategy. -
memoize
Memoizes the given supplier using a time-based lifespan and Fluxzero’s internal clock. -
memoize
Memoizes the given function using a time-based lifespan and Fluxzero's internal clock. -
memoize
public static <T,U, MemoizingBiFunction<T,R> U, memoizeR> (BiFunction<T, U, R> supplier, Duration lifespan) Memoizes the given bi-function using a time-based lifespan and Fluxzero's internal clock. -
getRevisionNumber
-
determineSearchCollection
-
getSearchParameters
Returns the effectiveSearchParametersfor the given type, using theSearchableannotation. Defaults to a collection name matching the class’s simple name if not explicitly set. -
getTopics
Extracts all topics associated with the given handler object and message type.The topics are derived based on the handler's annotations or inferred class properties. This method delegates the operation to another overload which processes a collection of handler classes.
- Parameters:
messageType- the type of the message (e.g., DOCUMENT or CUSTOM)handler- the handler object used to determine topics- Returns:
- a set of topic names associated with the handler and message type
-
getTopics
Extracts all topics fromHandleDocumentorHandleCustomannotated methods for the given classes.- Parameters:
messageType- the type of message (DOCUMENT or CUSTOM)handlerClasses- the classes to inspect- Returns:
- a set of topic names
-
getTopic
Extracts the topic associated with a givenHandleDocumentannotation orExecutable. The topic is determined based on the document collection name, the associated document class, or parameter type of the executable.- Parameters:
handleDocument- theHandleDocumentannotation containing metadata about the document handler. Can specify the document collection or class.executable- theExecutable(e.g., method or constructor) used to infer the topic if the annotation does not provide one. The parameter type of the executable may determine the topic.- Returns:
- the topic as a String, or
nullif no valid topic is determined.
-
truncate
Truncates aTemporal(e.g.,LocalDateTime) to the specified unit (e.g.,MONTHSorYEARS). Automatically adjusts the truncation unit for compound units likeMONTHS -> DAYS.- Parameters:
timestamp- the temporal value to truncateunit- the unit to truncate to- Returns:
- a truncated version of the original value
-