Package com.spotify.zoltar
Interface ModelLoader<M extends Model<?>>
-
- Type Parameters:
M
- Underlying model instance.
- All Superinterfaces:
AutoCloseable
,Closeable
- All Known Subinterfaces:
ModelLoader.ConsLoader<M>
,ModelLoader.PreLoader<M>
,ModelMemoizer<M>
,Preloader<M>
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface ModelLoader<M extends Model<?>> extends Closeable
Handles the model loading logic.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
ModelLoader.ConsLoader<M extends Model<?>>
ConsLoader is a constantModelLoader
.static interface
ModelLoader.PreLoader<M extends Model<?>>
PreLoader is model loader that callsget()
allowing model preloading.static interface
ModelLoader.ThrowableSupplier<M extends Model<?>>
Supplier ofModel
.
-
Field Summary
Fields Modifier and Type Field Description static ExecutorService
DEFAULT_EXECUTOR_SERVICE
default executor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description default void
close()
default <L extends ModelLoader<M>>
Lcompose(Function<ModelLoader<M>,L> fn)
CompletionStage<M>
get()
Get's the underlying model instance.default M
get(Duration duration)
Get's the underlying model instance.static <M extends Model<?>>
ModelLoader<M>lift(ModelLoader.ThrowableSupplier<M> supplier)
Deprecated.static <M extends Model<?>>
ModelLoader<M>load(ModelLoader.ThrowableSupplier<M> supplier)
Create aModelLoader
that loads the supplied model asynchronously.static <M extends Model<?>>
ModelLoader<M>load(ModelLoader.ThrowableSupplier<M> supplier, Executor executor)
Create aModelLoader
that loads the supplied model asynchronously.static <M extends Model<?>>
ModelLoader<M>loaded(M model)
Creates aModelLoader
with an already loaded model.static <M extends Model<?>>
ModelLoader.PreLoader<M>preload(ModelLoader.ThrowableSupplier<M> supplier, Duration duration, Executor executor)
Returns a blockingModelLoader
.static <M extends Model<?>>
ModelLoader<M>preload(ModelLoader<M> loader, Duration duration)
Returns a blockingModelLoader.PreLoader
.default <L extends ModelLoader<M>>
Lwith(Function<ModelLoader<M>,L> fn)
Deprecated.
-
-
-
Field Detail
-
DEFAULT_EXECUTOR_SERVICE
static final ExecutorService DEFAULT_EXECUTOR_SERVICE
default executor.
-
-
Method Detail
-
loaded
static <M extends Model<?>> ModelLoader<M> loaded(M model)
Creates aModelLoader
with an already loaded model.- Parameters:
model
- Underlying model instance.
-
preload
static <M extends Model<?>> ModelLoader.PreLoader<M> preload(ModelLoader.ThrowableSupplier<M> supplier, Duration duration, Executor executor) throws InterruptedException, ExecutionException, TimeoutException
Returns a blockingModelLoader
. Blocks till the model is loaded or aDuration
is met.- Type Parameters:
M
- Underlying model instance.- Parameters:
supplier
- model supplier.duration
- Amount of time that it should wait, if necessary, for model to be loaded.executor
- the executor to use for asynchronous execution.- Throws:
InterruptedException
ExecutionException
TimeoutException
-
preload
static <M extends Model<?>> ModelLoader<M> preload(ModelLoader<M> loader, Duration duration) throws InterruptedException, ExecutionException, TimeoutException
Returns a blockingModelLoader.PreLoader
. Blocks till the model is loaded or aDuration
is met.- Type Parameters:
M
- Underlying model instance.- Parameters:
loader
- model loader.duration
- Amount of time that it should wait, if necessary, for model to be loaded.- Throws:
InterruptedException
ExecutionException
TimeoutException
-
load
static <M extends Model<?>> ModelLoader<M> load(ModelLoader.ThrowableSupplier<M> supplier, Executor executor)
Create aModelLoader
that loads the supplied model asynchronously.- Type Parameters:
M
- Underlying model instance.- Parameters:
supplier
- model supplier.
-
load
static <M extends Model<?>> ModelLoader<M> load(ModelLoader.ThrowableSupplier<M> supplier)
Create aModelLoader
that loads the supplied model asynchronously.- Type Parameters:
M
- Underlying model instance.- Parameters:
supplier
- model supplier.
-
lift
@Deprecated static <M extends Model<?>> ModelLoader<M> lift(ModelLoader.ThrowableSupplier<M> supplier)
Deprecated.Lifts a supplier into aModelLoader
.- Type Parameters:
M
- Underlying model instance.- Parameters:
supplier
- model supplier.
-
get
CompletionStage<M> get()
Get's the underlying model instance.- Returns:
- Model instance
-
get
default M get(Duration duration) throws InterruptedException, ExecutionException, TimeoutException
Get's the underlying model instance.- Returns:
- Model instance
- Throws:
InterruptedException
ExecutionException
TimeoutException
-
with
@Deprecated default <L extends ModelLoader<M>> L with(Function<ModelLoader<M>,L> fn)
Deprecated.
-
compose
default <L extends ModelLoader<M>> L compose(Function<ModelLoader<M>,L> fn)
-
close
default void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
-