Class Adapter

  • Direct Known Subclasses:
    PyAdapter

    public abstract class Adapter
    extends java.lang.Object
    An adapter is a modification producing a variation of a model that can be used during prediction.
    • Field Detail

      • name

        protected java.lang.String name
      • src

        protected java.lang.String src
    • Constructor Detail

      • Adapter

        protected Adapter​(java.lang.String name,
                          java.lang.String src)
        Constructs an Adapter.
        Parameters:
        name - the adapter name
        src - the adapter source
    • Method Detail

      • newInstance

        public static Adapter newInstance​(WorkerPoolConfig<?,​?> wpc,
                                          java.lang.String name,
                                          java.lang.String src)
        Constructs a new Adapter.

        After registration, you should call register(WorkerPool). This doesn't affect the worker pool itself.

        Parameters:
        wpc - the worker pool config for the new adapter
        name - the adapter name
        src - the adapter source
        Returns:
        the new adapter
      • unregister

        public static <I,​O> void unregister​(WorkerPool<I,​O> wp,
                                                  java.lang.String adapterName)
        Unregisters an adapter in a worker pool.

        This unregisters it in the wpc for new threads and all existing threads.

        Type Parameters:
        I - the input type
        O - the output type
        Parameters:
        wp - the worker pool to remove the adapter from
        adapterName - the adapter name
      • getName

        public java.lang.String getName()
        Returns the adapter name.
        Returns:
        the adapter name
      • getSrc

        public java.lang.String getSrc()
        Returns the adapter src.
        Returns:
        the adapter src
      • register

        public <I,​O> void register​(WorkerPool<I,​O> wp)
        Registers this adapter in a worker pool.

        This registers it in the wpc for new threads and all existing threads.

        Type Parameters:
        I - the input type
        O - the output type
        Parameters:
        wp - the worker pool to register this adapter in
      • registerJob

        public <I,​O> WorkerJob<I,​O> registerJob​(WorkerPoolConfig<I,​O> wpc,
                                                            WorkerPoolConfig.ThreadConfig<I,​O> threadConfig)
        Creates a WorkerJob to register this adapter in a WorkerThread.
        Type Parameters:
        I - the input type
        O - the output type
        Parameters:
        wpc - the worker pool of the thread
        threadConfig - the thread config to register
        Returns:
        the registration job
      • unregisterJob

        public <I,​O> WorkerJob<I,​O> unregisterJob​(WorkerPoolConfig<I,​O> wpc,
                                                              WorkerPoolConfig.ThreadConfig<I,​O> threadConfig)
        Creates a WorkerJob to unregister this adapter from a WorkerThread.
        Type Parameters:
        I - the input type
        O - the output type
        Parameters:
        wpc - the worker pool of the thread
        threadConfig - the thread config to unregister
        Returns:
        the unregistration job
      • registerPredictor

        protected abstract void registerPredictor​(ai.djl.inference.Predictor<?,​?> predictor)
      • unregisterPredictor

        protected abstract void unregisterPredictor​(ai.djl.inference.Predictor<?,​?> predictor)