Class McpServiceLoader<S extends Supplier<R>,R>

java.lang.Object
io.modelcontextprotocol.util.McpServiceLoader<S,R>
Type Parameters:
S - the type of the supplier
R - the type of the supplier result/returned value

public class McpServiceLoader<S extends Supplier<R>,R> extends Object
Instance of this class are intended to be used differently in OSGi and non-OSGi environments. In all non-OSGi environments the supplier member will be null and the serviceLoad method will be called to use the ServiceLoader.load to find the first instance of the supplier (assuming one is present in the runtime), cache it, and call the supplier's get method.

In OSGi environments, the Service component runtime (scr) will call the setSupplier method upon bundle activation (assuming one is present in the runtime), and subsequent calls will use the given supplier instance rather than the ServiceLoader.load.

  • Constructor Details

    • McpServiceLoader

      public McpServiceLoader(Class<S> supplierType)
  • Method Details

    • setSupplier

      public void setSupplier(S supplier)
    • unsetSupplier

      public void unsetSupplier(S supplier)
    • serviceLoad

      protected Optional<S> serviceLoad(Class<S> type)
    • getDefault

      public R getDefault()