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,java.lang.String,java.lang.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,java.lang.String,java.lang.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. CallsetupConnectionManager()at the end of yourAbstractService.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
Fields Modifier and Type Field Description private org.apache.http.impl.client.CloseableHttpClientclientprivate java.net.HttpURLConnectionconnectionprivate java.util.concurrent.ExecutorServiceexecutor-
Fields inherited from interface de.iip_ecosphere.platform.services.environment.switching.ServiceBase
APPLICATION_SEPARATOR, DEFAULT_APPLICATION_INSTANCE_ID
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractRestProcessService(de.iip_ecosphere.platform.transport.serialization.TypeTranslator<I,java.lang.String> inTrans, de.iip_ecosphere.platform.transport.serialization.TypeTranslator<java.lang.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
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract java.lang.StringadjustRestQuery(java.lang.String input)Adjusts the input produced byAbstractProcessService.getInputTranslator()to the actual receiver.protected abstract java.lang.StringadjustRestResponse(java.lang.String response)The rest response.protected abstract java.lang.StringgetApiPath()Returns the HTTP/HTTPS path to the REST API.protected abstract java.lang.StringgetBearerToken()Returns the bearer token for authentication.protected java.net.HttpURLConnectiongetConnection()Returns the connection instance.protected java.net.HttpURLConnectiongetNewConnectionInstance()Creates a new connection and overwrites the existing connection instance.protected voidgetNewConnectionInstanceQuiet(boolean changeState)Get Connection to local server.protected voidhandleInputStream(java.io.InputStream in)Handles the input stream upon process creation.voidprocess(I data)Requests to process the given data item.voidredirectRest(java.net.HttpURLConnection connection, de.iip_ecosphere.platform.transport.connectors.ReceptionCallback<O> callback)Redirects rest answers to the reception callback.protected voidsetupConnectionManager()Sets up the connection manager and creates a new httpClient based on a connection pool.protected ServiceStatestop()Preliminary: Stops the service and the background process.-
Methods inherited from class de.iip_ecosphere.platform.services.environment.AbstractProcessService
addProcessSpecCmdArg, attachIngestor, attachMetricsProvider, configure, createAndConfigureProcess, createProcess, createProcess, getExecutableName, getExecutableName, getExecutablePrefix, getExecutablePrefix, getExecutableSuffix, getInputTranslator, getOsArch, getOutputTranslator, getPid, getProcessId, getProcessSpec, getServiceIn, getServiceSpec, getWaitTimeBeforeDestroy, handleErrorStream, handleOutputStream, notifyCallbacks, processQuiet, redirectIO, selectNotNull, selectNotNull, setInheritIo, waitAndDestroy, waitAndDestroy
-
Methods inherited from class de.iip_ecosphere.platform.services.environment.AbstractRunnablesService
register
-
Methods inherited from class de.iip_ecosphere.platform.services.environment.AbstractService
activate, addConfigurer, addConfigurer, addConfigurer, createInstance, createInstance, createInstance, getDescription, getId, getKind, getName, getNetMgtKeyAddress, getResourceAsStream, getState, getVersion, initializeFrom, isDeployable, isTopLevel, notifyReconfigured, passivate, reconf, reconfigure, reconfigure, rollbackReconfigurationOnFailure, setLibJars, setState, start
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface de.iip_ecosphere.platform.services.environment.Service
activate, getDescription, getKind, getName, getNetMgtKeyAddress, getParameterConfigurer, getParameterNames, getVersion, isDeployable, isTopLevel, migrate, passivate, reconfigure, switchTo, update
-
Methods inherited from interface de.iip_ecosphere.platform.services.environment.switching.ServiceBase
getId, getState, setState
-
-
-
-
Constructor Detail
-
AbstractRestProcessService
protected AbstractRestProcessService(de.iip_ecosphere.platform.transport.serialization.TypeTranslator<I,java.lang.String> inTrans, de.iip_ecosphere.platform.transport.serialization.TypeTranslator<java.lang.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 Detail
-
getApiPath
protected abstract java.lang.String getApiPath()
Returns the HTTP/HTTPS path to the REST API.- Returns:
- the path
-
getConnection
protected java.net.HttpURLConnection getConnection()
Returns the connection instance.- Returns:
- the connection instance, may be null if service was not started before
-
getBearerToken
protected abstract java.lang.String getBearerToken()
Returns the bearer token for authentication.- Returns:
- the bearer token, may be null for none
-
getNewConnectionInstance
protected java.net.HttpURLConnection getNewConnectionInstance() throws java.io.IOExceptionCreates a new connection and overwrites the existing connection instance.- Returns:
- the created connection
- Throws:
java.io.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
-
process
public void process(I data) throws java.io.IOException
Description copied from class:AbstractProcessServiceRequests to process the given data item.- Specified by:
processin classAbstractProcessService<I,java.lang.String,java.lang.String,O>- Parameters:
data- the data to process- Throws:
java.io.IOException- if processing/transferring to the service fails
-
adjustRestQuery
protected abstract java.lang.String adjustRestQuery(java.lang.String input)
Adjusts the input produced byAbstractProcessService.getInputTranslator()to the actual receiver.- Parameters:
input- the input- Returns:
- the adjusted input
-
adjustRestResponse
protected abstract java.lang.String adjustRestResponse(java.lang.String response)
The rest response.- Parameters:
response- the received response- Returns:
- the adjusted response
-
redirectRest
public void redirectRest(java.net.HttpURLConnection connection, de.iip_ecosphere.platform.transport.connectors.ReceptionCallback<O> callback)Redirects rest answers to the reception callback.- Parameters:
connection- the connection to redirectcallback- the callback to use- See Also:
adjustRestResponse(String)
-
handleInputStream
protected void handleInputStream(java.io.InputStream in)
Description copied from class:AbstractProcessServiceHandles the input stream upon process creation.- Specified by:
handleInputStreamin classAbstractProcessService<I,java.lang.String,java.lang.String,O>- Parameters:
in- the process input stream
-
stop
protected ServiceState stop()
Description copied from class:AbstractProcessServicePreliminary: Stops the service and the background process.- Overrides:
stopin classAbstractProcessService<I,java.lang.String,java.lang.String,O>- Returns:
- the state to transition to, may be null for none
-
-