Class RemoteInferenceEngine
- java.lang.Object
-
- com.codedstream.otterstream.remote.RemoteInferenceEngine
-
- All Implemented Interfaces:
InferenceEngine<Void>
- Direct Known Subclasses:
HttpInferenceClient,SageMakerInferenceClient
public abstract class RemoteInferenceEngine extends Object implements InferenceEngine<Void>
Abstract base class for remote inference engines communicating with external model endpoints.Provides common functionality for remote inference implementations including:
- Basic initialization with endpoint URL
- Default batch inference implementation (sequential processing)
- Connection state management
- Resource cleanup framework
Extending This Class:
Subclasses should implement:
initialize(ModelConfig)- Set up remote connectioninfer(Map)- Send single inference requestvalidateConnection()- Verify endpoint availabilityclose()- Clean up resources
Batch Inference:
The default
inferBatch(Map[])implementation processes requests sequentially. Subclasses should override this method if the remote endpoint supports native batch processing for better performance.Usage Pattern:
{@code public class MyRemoteEngine extends RemoteInferenceEngine {- Since:
- 1.0.0
- Author:
- Nestor Martourez, Sr Software and Data Streaming Engineer @ CodedStreams
- See Also:
InferenceEngine,HttpInferenceClient,SageMakerInferenceClient
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.codedstream.otterstream.inference.engine.InferenceEngine
InferenceEngine.EngineCapabilities
-
-
Field Summary
Fields Modifier and Type Field Description protected StringendpointUrlprotected booleaninitializedprotected ModelConfigmodelConfig
-
Constructor Summary
Constructors Constructor Description RemoteInferenceEngine()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the engine and releases resources.InferenceEngine.EngineCapabilitiesgetCapabilities()Gets engine capabilities for remote endpoints.abstract InferenceResultinfer(Map<String,Object> inputs)Performs single inference on remote endpoint (abstract).InferenceResultinferBatch(Map<String,Object>[] batchInputs)Performs batch inference using sequential processing.voidinitialize(ModelConfig config)Initializes the remote inference engine with endpoint configuration.booleanisReady()Checks if the engine is ready for inference.abstract booleanvalidateConnection()Validates connection to remote endpoint (abstract).-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.codedstream.otterstream.inference.engine.InferenceEngine
getMetadata, getModelConfig
-
-
-
-
Field Detail
-
modelConfig
protected ModelConfig modelConfig
-
initialized
protected boolean initialized
-
endpointUrl
protected String endpointUrl
-
-
Method Detail
-
initialize
public void initialize(ModelConfig config) throws InferenceException
Initializes the remote inference engine with endpoint configuration.Basic initialization sets:
modelConfig- Configuration for the remote modelendpointUrl- URL fromModelConfig.getEndpointUrl()initialized- Marks engine as ready for inference
Subclasses should call
super.initialize(config)first, then perform their own initialization (HTTP client setup, authentication, etc.).- Specified by:
initializein interfaceInferenceEngine<Void>- Parameters:
config- model configuration containing endpoint URL- Throws:
InferenceException- if initialization fails
-
infer
public abstract InferenceResult infer(Map<String,Object> inputs) throws InferenceException
Performs single inference on remote endpoint (abstract).Subclasses must implement this method to send inference requests to the remote endpoint and parse responses.
- Specified by:
inferin interfaceInferenceEngine<Void>- Parameters:
inputs- map of input names to values- Returns:
- inference result containing outputs and timing
- Throws:
InferenceException- if inference fails
-
inferBatch
public InferenceResult inferBatch(Map<String,Object>[] batchInputs) throws InferenceException
Performs batch inference using sequential processing.Default implementation processes batch inputs sequentially by calling
infer(Map)for each input. Outputs are aggregated with index suffixes to maintain traceability.Output Format:
{ "output1_0": value1, "output2_0": value2, "output1_1": value3, "output2_1": value4, ... }Performance Note: Sequential processing is inefficient for large batches. Override this method if the remote endpoint supports native batch processing.
- Specified by:
inferBatchin interfaceInferenceEngine<Void>- Parameters:
batchInputs- array of input maps for batch processing- Returns:
- aggregated inference result containing all batch outputs
- Throws:
InferenceException- if any inference in the batch fails
-
isReady
public boolean isReady()
Checks if the engine is ready for inference.- Specified by:
isReadyin interfaceInferenceEngine<Void>- Returns:
- true if initialized and endpoint URL is set
-
close
public void close() throws InferenceExceptionCloses the engine and releases resources.Base implementation marks engine as not initialized and clears endpoint URL. Subclasses should override to clean up their own resources (close HTTP clients, database connections, etc.), then call
super.close().- Specified by:
closein interfaceInferenceEngine<Void>- Throws:
InferenceException- if cleanup fails
-
validateConnection
public abstract boolean validateConnection() throws InferenceExceptionValidates connection to remote endpoint (abstract).Subclasses must implement this method to test connectivity to the remote endpoint. This is useful for health checks and connection pooling.
- Returns:
- true if connection is successful
- Throws:
InferenceException- if validation fails (network error, timeout)
-
getCapabilities
public InferenceEngine.EngineCapabilities getCapabilities()
Gets engine capabilities for remote endpoints.Default capabilities indicate:
- Not a local engine (remote = false)
- No native batch support (batch = false)
- Max batch size of 1 (sequential processing)
- Async operations supported (async = true)
Subclasses should override to provide accurate capabilities for their specific remote endpoint.
- Specified by:
getCapabilitiesin interfaceInferenceEngine<Void>- Returns:
- default engine capabilities for remote inference
-
-