Class NbtAdapterCache

java.lang.Object
net.xun.lib.common.internal.nbt.NbtAdapterCache

@Internal public class NbtAdapterCache extends Object
Registry cache for NBT serialization adapters with thread-safe initialization.

Manages a global registry of INbtAdapter implementations discovered through:

  1. ServiceLoader API (automatic discovery)
  2. 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 Details

    • ADAPTERS

      public static final Map<Class<?>,INbtAdapter<?>> ADAPTERS
      Concurrent registry map storing adapters by target type
    • initialized

      public static volatile boolean initialized
      Initialization state flag (volatile for double-checked locking)
  • Constructor Details

    • NbtAdapterCache

      public NbtAdapterCache()
  • Method Details

    • findAdapter

      public static INbtAdapter<?> findAdapter(Class<?> type)
      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