Package com.helixframework.logging
Class HelixMarkerFactory
java.lang.Object
com.helixframework.logging.HelixMarkerFactory
A factory class for creating and managing
Marker instances. The HelixMarkerFactory
provides an efficient mechanism to handle composite markers with caching capabilities, ensuring
reusability and immutability where needed.
This class is implemented as a singleton to centralize access and management of markers. It
allows creating both cached and detached marker instances, ensuring thread-safe operations
through the use of a ConcurrentMap. The internal caching mechanism optimizes marker
retrieval and ensures consistency across different usages.-
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears all entries from the marker cache.booleandetachMarker(String... names) Detaches a Marker associated with the specified names from the marker cache.booleandetachMarker(Set<String> names) Detaches a Marker associated with the specified set of names from the marker cache.booleanChecks if a Marker exists in the marker cache for the given names.booleanChecks if an entry corresponding to the specified set of names exists in the marker cache.org.slf4j.MarkergetDetachedMarker(String... names) Retrieves a detached Marker instance corresponding to the specified names.org.slf4j.MarkergetDetachedMarker(Set<String> names) Retrieves a detached Marker instance corresponding to the specified set of names.static HelixMarkerFactoryProvides a globally accessible instance of the HelixMarkerFactory class.org.slf4j.MarkerRetrieves a Marker instance corresponding to the specified names.org.slf4j.MarkerRetrieves a Marker instance corresponding to the specified list of names.org.slf4j.MarkergetMarker(org.slf4j.Marker... markers) Retrieves a Marker instance corresponding to the specified array of Marker objects.
-
Method Details
-
getInstance
Provides a globally accessible instance of the HelixMarkerFactory class.- Returns:
- the singleton instance of HelixMarkerFactory
-
getMarker
Retrieves a Marker instance corresponding to the specified names. The method accepts a variable number of String parameters representing marker names and delegates the operation togetMarker(List).- Parameters:
names- the names of the markers to retrieve; must not be null or contain nulls- Returns:
- a Marker representing the composite structure of the specified marker names
- Throws:
IllegalArgumentException- if the names parameter is null, empty, or contains null elements
-
getMarker
Retrieves a Marker instance corresponding to the specified list of names. The method validates the provided list of names, processes them into a canonical form, and either retrieves a cached Marker or builds a composite Marker structure.- Parameters:
names- the list of marker names to be processed; must not be null, empty, or contain null elements- Returns:
- a Marker representing the composite structure of the specified marker names
- Throws:
IllegalArgumentException- if the names parameter is null, empty, or contains null elements
-
getMarker
public org.slf4j.Marker getMarker(org.slf4j.Marker... markers) Retrieves a Marker instance corresponding to the specified array of Marker objects. The method validates the input array, ensuring it is non-null, non-empty, and does not contain null elements. It then extracts the names of the markers and retrieves a composite Marker structure based on those names.- Parameters:
markers- the array of Marker objects to be processed; must not be null, empty, or contain null elements- Returns:
- a Marker representing the composite structure of the specified Marker objects
- Throws:
IllegalArgumentException- if the markers parameter is null, empty, or contains null elements
-
exists
Checks if a Marker exists in the marker cache for the given names. This method uses the specified names to create a canonical key and verifies whether it is present in the marker cache.- Parameters:
names- the variable-length array of marker names to check; may be empty or null- Returns:
- true if the marker cache contains an entry for the canonical key derived from the specified names; false otherwise
-
exists
Checks if an entry corresponding to the specified set of names exists in the marker cache. This method uses the set of names to construct a canonical key and verifies its presence in the cache.- Parameters:
names- the set of marker names to check; may be null or empty- Returns:
- true if the marker cache contains an entry corresponding to the derived canonical key; false otherwise
-
detachMarker
Detaches a Marker associated with the specified names from the marker cache. This method generates a canonical key from the provided names and attempts to remove the corresponding Marker entry from the cache.- Parameters:
names- the variable-length array of marker names to identify the Marker to be detached; may be null or empty- Returns:
- true if a Marker corresponding to the specified names was successfully removed from the cache; false otherwise
-
detachMarker
Detaches a Marker associated with the specified set of names from the marker cache. This method constructs a canonical key using the provided set of names and attempts to remove the corresponding entry from the cache.- Parameters:
names- the set of marker names used to identify the Marker to detach; may be null or empty- Returns:
- true if a Marker corresponding to the specified names was successfully removed from the cache; false otherwise
-
clear
public void clear()Clears all entries from the marker cache. This method removes any cached marker instances, effectively resetting the state of the marker cache within the factory. After invoking this method, previously cached markers are no longer retrievable, and a new instance will be created if requested. -
getDetachedMarker
Retrieves a detached Marker instance corresponding to the specified names. The method validates the input names, processes them into a canonical key, and constructs a composite Marker structure that is immutable.- Parameters:
names- the variable-length array of marker names to be processed; must not be null, empty, or contain null elements- Returns:
- an immutable Marker representing the composite structure of the specified names
- Throws:
IllegalArgumentException- if the names parameter is null, empty, or contains null elements
-
getDetachedMarker
Retrieves a detached Marker instance corresponding to the specified set of names. The method validates the provided set of names, processes them into a canonical key, and constructs a composite Marker structure that is immutable.- Parameters:
names- the set of marker names to be processed; must not be null, empty, or contain null elements- Returns:
- an immutable Marker representing the composite structure of the specified names
- Throws:
IllegalArgumentException- if the names parameter is null, empty, or contains null elements
-