Class ClientUtils
java.lang.Object
io.fluxcapacitor.javaclient.common.ClientUtils
Utility class offering client-side support functions for working with Flux Capacitor.
Unlike ObjectUtils
, this class is specifically intended for use within Flux client
applications and can make use of infrastructure components such as
FluxCapacitor
.
It provides convenience methods for:
- Memoization with lifespans via Flux’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
Temporal
values
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final org.slf4j.Marker
A 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 String
determineSearchCollection
(@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 theLocalHandler
annotation 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 theLocalHandler
annotation associated with a given method, its declaring class, or ancestral package, if present.static int
getRevisionNumber
(Object object) Extracts the revision number from theRevision
annotation on the given object’s class.static SearchParameters
getSearchParameters
(Class<?> type) Returns the effectiveSearchParameters
for the given type, using theSearchable
annotation.static String
getTopic
(HandleDocument handleDocument, Executable executable) Extracts the topic associated with a givenHandleDocument
annotation 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 fromHandleDocument
orHandleCustom
annotated methods for the given classes.static boolean
isLocalHandler
(HandlerInvoker invoker, HasMessage message) Determines if the specified handler method handles messages locally.static boolean
isLocalSelfHandler
(HandlerInvoker invoker, HasMessage message) Returns whether the handler method should only handle messages from the same instance ("self").static boolean
isSelfTracking
(Class<?> target, Executable method) Returns whether the specified method or its declaring class is marked withTrackSelf
.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 Flux’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 Flux’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 Flux’s internal clock.static <T extends Temporal>
Ttruncate
(T timestamp, TemporalUnit unit) static void
waitForResults
(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
MarkerFactory
with 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:
true
if marked for self-tracking,false
otherwise
-
getLocalHandlerAnnotation
Retrieves theLocalHandler
annotation associated with a given handler, from its method, its declaring class, or ancestral package, if present. -
getLocalHandlerAnnotation
Retrieves theLocalHandler
annotation 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 usingLocalHandler
or meets the criteria for local self-handling, i.e.:isLocalSelfHandler(io.fluxcapacitor.common.handling.HandlerInvoker, io.fluxcapacitor.javaclient.common.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 noTrackSelf
annotation is present. -
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 Flux’s internal clock. -
memoize
Memoizes the given function using a time-based lifespan and Flux’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 Flux’s internal clock. -
getRevisionNumber
Extracts the revision number from theRevision
annotation on the given object’s class.- Returns:
- the revision number, or 0 if not present
-
determineSearchCollection
Determines the collection name used for document indexing and search based on the annotated handler or document type. -
getSearchParameters
Returns the effectiveSearchParameters
for the given type, using theSearchable
annotation. 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 fromHandleDocument
orHandleCustom
annotated 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 givenHandleDocument
annotation orExecutable
. The topic is determined based on the document collection name, the associated document class, or parameter type of the executable.- Parameters:
handleDocument
- theHandleDocument
annotation 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
null
if no valid topic is determined.
-
truncate
Truncates aTemporal
(e.g.,LocalDateTime
) to the specified unit (e.g.,MONTHS
orYEARS
). 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
-