Class AbstractRestProcessService<I,O>
java.lang.Object
de.iip_ecosphere.platform.services.environment.AbstractService
de.iip_ecosphere.platform.services.environment.AbstractRunnablesService
de.iip_ecosphere.platform.services.environment.AbstractProcessService<I,String,String,O>
de.iip_ecosphere.platform.services.environment.AbstractRestProcessService<I,O>
- Type Parameters:
I- the input data typeO- the output data type
- All Implemented Interfaces:
MonitoringService,ParameterConfigurerProvider,Service,ServiceBase
public abstract class AbstractRestProcessService<I,O>
extends AbstractProcessService<I,String,String,O>
Implements an abstract asynchronous process-based service which require a Rest-based communication with
the actual service process for a single pair of input-output types, e.g., via JSON. Call
setupConnectionManager() at the end of your AbstractService.start() method implementation.- Author:
- Marcel Nöhre
-
Nested Class Summary
Nested classes/interfaces inherited from class de.iip_ecosphere.platform.services.environment.AbstractProcessService
AbstractProcessService.RunnableWithStop -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate de.iip_ecosphere.platform.support.http.HttpClientprivate HttpURLConnectionprivate ExecutorServiceFields inherited from interface de.iip_ecosphere.platform.services.environment.switching.ServiceBase
APPLICATION_SEPARATOR, DEFAULT_APPLICATION_INSTANCE_ID -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractRestProcessService(de.iip_ecosphere.platform.transport.serialization.TypeTranslator<I, String> inTrans, de.iip_ecosphere.platform.transport.serialization.TypeTranslator<String, O> outTrans, de.iip_ecosphere.platform.transport.connectors.ReceptionCallback<O> callback, YamlService yaml) Creates an instance of the service with the required type translators. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract StringadjustRestQuery(String input, String inTypeName) Adjusts the input produced byAbstractProcessService.getInputTranslator()to the actual receiver.protected abstract StringadjustRestResponse(String response) The rest response.protected abstract StringgetApiPath(String inTypeName) Returns the HTTP/HTTPS path to the REST API.protected abstract StringReturns the bearer token for authentication.protected HttpURLConnectionReturns the connection instance.protected HttpURLConnectionCreates a new connection and overwrites the existing connection instance.protected voidgetNewConnectionInstanceQuiet(boolean changeState) Get Connection to local server.protected voidHandles the input stream upon process creation.protected voidhandleReception(String data, String inTypeName) Handles the reception ofdata.voidRequests to process the given data item.voidProcesses input.protected voidSets up the connection manager and creates a new httpClient based on a connection pool.protected ServiceStatestop()Preliminary: Stops the service and the background process.protected StringtoSendString(I data, String inTypeName) Turnsdatato an input string of the underlying REST service.protected voidWaits until a connection is established.Methods inherited from class de.iip_ecosphere.platform.services.environment.AbstractProcessService
addProcessSpecCmdArg, attachIngestor, attachMetricsProvider, configure, createAndConfigureProcess, createProcess, createProcess, getCallbacks, getExecutableName, getExecutableName, getExecutablePrefix, getExecutablePrefix, getExecutableSuffix, getInputTranslator, getOsArch, getOutputTranslator, getPid, getProcessId, getProcessSpec, getServiceIn, getServiceSpec, getWaitTimeBeforeDestroy, handleErrorStream, handleOutputStream, notifyCallbacks, processQuiet, redirectIO, redirectIO, selectNotNull, selectNotNull, setInheritIo, waitAndDestroy, waitAndDestroyMethods inherited from class de.iip_ecosphere.platform.services.environment.AbstractRunnablesService
registerMethods inherited from class de.iip_ecosphere.platform.services.environment.AbstractService
activate, addConfigurer, addConfigurer, addConfigurer, addTypeSubstitution, createGenericInstance, createGenericInstance, createGenericInstanceByPlugin, createGenericMultiInstance, createGenericMultiInstance, createGenericMultiInstanceByPlugin, createInstance, createInstance, createInstance, createInstanceByPlugin, getArg, getDescription, getId, getKind, getName, getNetMgtKeyAddress, getResourceAsStream, getState, getStringArg, getSubstitutedType, getTypeCreator, getTypeSubstitutions, getVersion, initializeFrom, isDeployable, isTopLevel, notifyReconfigured, passivate, reconf, reconfigure, reconfigure, rollbackReconfigurationOnFailure, setLibJars, setState, start, transferDataMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface de.iip_ecosphere.platform.services.environment.Service
activate, addTypeSubstitution, createType, createType, getDescription, getKind, getName, getNetMgtKeyAddress, getParameterConfigurer, getParameterNames, getSubstitutedType, getTypeCreator, getTypeSubstitutions, getVersion, isDeployable, isTopLevel, migrate, passivate, reconfigure, switchTo, updateMethods inherited from interface de.iip_ecosphere.platform.services.environment.switching.ServiceBase
getId, getState, setState
-
Field Details
-
connection
-
executor
-
client
private de.iip_ecosphere.platform.support.http.HttpClient client
-
-
Constructor Details
-
AbstractRestProcessService
protected AbstractRestProcessService(de.iip_ecosphere.platform.transport.serialization.TypeTranslator<I, String> inTrans, de.iip_ecosphere.platform.transport.serialization.TypeTranslator<String, O> outTrans, de.iip_ecosphere.platform.transport.connectors.ReceptionCallback<O> callback, YamlService yaml) Creates an instance of the service with the required type translators.- Parameters:
inTrans- the input translatoroutTrans- the output translatorcallback- called when data from the service is availableyaml- the service description
-
-
Method Details
-
getApiPath
Returns the HTTP/HTTPS path to the REST API.- Parameters:
inTypeName- the type name of the input data being processed, may be null or empty to request a default API- Returns:
- the path
-
getConnection
Returns the connection instance.- Returns:
- the connection instance, may be null if service was not started before
-
getBearerToken
Returns the bearer token for authentication.- Returns:
- the bearer token, may be null for none
-
getNewConnectionInstance
Creates a new connection and overwrites the existing connection instance.- Returns:
- the created connection
- Throws:
IOException- if creating the connection fails
-
setupConnectionManager
protected void setupConnectionManager()Sets up the connection manager and creates a new httpClient based on a connection pool. -
getNewConnectionInstanceQuiet
protected void getNewConnectionInstanceQuiet(boolean changeState) Get Connection to local server.- Parameters:
changeState- whether the state shall be changed if the connection creation fails
-
waitForConnection
protected void waitForConnection()Waits until a connection is established. -
process
Description copied from class:AbstractProcessServiceRequests to process the given data item.- Specified by:
processin classAbstractProcessService<I,String, String, O> - Parameters:
data- the data to process- Throws:
IOException- if processing/transferring to the service fails
-
process
Processes input.- Parameters:
data- the data to be processedinTypeName- the symbolic input type name, may be empty if just one is handled- Throws:
IOException- if processing fails
-
toSendString
Turnsdatato an input string of the underlying REST service.- Parameters:
data- the datainTypeName- the symbolic input type name, may be empty if just one is handled- Returns:
- the translated input string, by default via
adjustRestQuery(String, String)andAbstractProcessService.getInputTranslator() - Throws:
IOException- if processing the input fails
-
handleReception
Handles the reception ofdata. By default, appliesadjustRestResponse(String),AbstractProcessService.getOutputTranslator()andAbstractProcessService.notifyCallbacks(Object).- Parameters:
data- the information received from the underlying REST serviceinTypeName- the original type name this reception has been caused by
-
adjustRestQuery
Adjusts the input produced byAbstractProcessService.getInputTranslator()to the actual receiver.- Parameters:
input- the inputinTypeName- the symbolic input type name, may be empty if just one is handled- Returns:
- the adjusted input
-
adjustRestResponse
The rest response.- Parameters:
response- the received response- Returns:
- the adjusted response
-
handleInputStream
Description copied from class:AbstractProcessServiceHandles the input stream upon process creation.- Specified by:
handleInputStreamin classAbstractProcessService<I,String, String, O> - Parameters:
in- the process input stream
-
stop
Description copied from class:AbstractProcessServicePreliminary: Stops the service and the background process.
-