Package net.xun.lib.common.internal.nbt
Class NbtAdapterCache
java.lang.Object
net.xun.lib.common.internal.nbt.NbtAdapterCache
Registry cache for NBT serialization adapters with thread-safe initialization.
Manages a global registry of INbtAdapter implementations discovered through:
- ServiceLoader API (automatic discovery)
- Manual registration (not shown)
Initialization Characteristics:
- Lazy initialization upon first access
- Double-checked locking for thread safety
- ConcurrentHashMap backing store (safe for concurrent reads)
Lookup Logic:
1. Exact type match in registered adapters
2. GenericNbtAdapter fallback
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Map<Class<?>, INbtAdapter<?>> Concurrent registry map storing adapters by target typestatic booleanInitialization state flag (volatile for double-checked locking) -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic INbtAdapter<?> findAdapter(Class<?> type) Retrieves the appropriate adapter for a given type with fallback handling.static voidInitializes the adapter registry using ServiceLoader discovery.
-
Field Details
-
ADAPTERS
Concurrent registry map storing adapters by target type -
initialized
public static volatile boolean initializedInitialization state flag (volatile for double-checked locking)
-
-
Constructor Details
-
NbtAdapterCache
public NbtAdapterCache()
-
-
Method Details
-
findAdapter
Retrieves the appropriate adapter for a given type with fallback handling.- Parameters:
type- The target serialization type (non-null)- Returns:
- Registered adapter or GenericNbtAdapter if none found
- Throws:
IllegalStateException- If initialization fails due to duplicate adapters
-
initialize
public static void initialize()Initializes the adapter registry using ServiceLoader discovery.Synchronized to prevent concurrent initialization with: - Volatile write for visibility - ConcurrentHashMap for thread-safe population
- Throws:
IllegalStateException- For duplicate adapter registrations
-