Class MagicRuntimeResource<T extends AutoCloseable>

java.lang.Object
dev.ua.theroer.magicutils.bootstrap.MagicRuntimeResource<T>
Type Parameters:
T - resource type
All Implemented Interfaces:
AutoCloseable

public final class MagicRuntimeResource<T extends AutoCloseable> extends Object implements AutoCloseable
Managed resource slot owned by a MagicRuntime.

The slot keeps the current resource under a stable name, exposes it through the runtime's named component registry, and closes replaced/current resources automatically.

  • Method Details

    • name

      public String name()
      Returns the resource name used in the runtime registry.
      Returns:
      resource name
    • isClosed

      public boolean isClosed()
      Returns true when the slot has been closed.
      Returns:
      closed flag
    • current

      public Optional<T> current()
      Returns the current resource when present.
      Returns:
      optional current resource
    • require

      public T require()
      Returns the current resource or throws when absent.
      Returns:
      current resource
    • set

      @Nullable public T set(@Nullable T next)
      Installs a new resource, closing the previous one.
      Parameters:
      next - next resource, optionally null
      Returns:
      the installed resource, or null when cleared
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable