Class PythonSyncProcessService
- java.lang.Object
-
- de.iip_ecosphere.platform.services.environment.AbstractService
-
- de.iip_ecosphere.platform.services.environment.AbstractRunnablesService
-
- de.iip_ecosphere.platform.services.environment.AbstractPythonProcessService
-
- de.iip_ecosphere.platform.services.environment.PythonSyncProcessService
-
- All Implemented Interfaces:
GenericMultiTypeService,ParameterConfigurerProvider,Service,ServiceBase
public class PythonSyncProcessService extends AbstractPythonProcessService
Generic command-line-based Python integration for multiple data types. Conventions:- Python is determined by
PythonUtils.getPythonExecutable(). The default is "ServiceEnvironment.py" which must run for this integration with "--mode console". - A synchronous Python program receives the data including the symbolic type name as last (for "ServiceEnvironment.py" qualified by "--data") command line argument and returns the result on the command line including the symbolic type name.
- The Python program runs until the input data is processed.
- Author:
- Holger Eichelberger, SSE
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class de.iip_ecosphere.platform.services.environment.AbstractPythonProcessService
AbstractPythonProcessService.AbstractTypeInfo<T>, AbstractPythonProcessService.InputHandler, AbstractPythonProcessService.InTypeInfo<T>, AbstractPythonProcessService.OutTypeInfo<T>, AbstractPythonProcessService.SyncDataIngestor<D>
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,java.lang.String>reconfValuesprivate inttimeoutprivate java.util.concurrent.TimeUnittimeoutUnit-
Fields inherited from class de.iip_ecosphere.platform.services.environment.AbstractPythonProcessService
TYPE_SEPARATOR_CHAR
-
Fields inherited from interface de.iip_ecosphere.platform.services.environment.switching.ServiceBase
APPLICATION_SEPARATOR, DEFAULT_APPLICATION_INSTANCE_ID
-
-
Constructor Summary
Constructors Constructor Description PythonSyncProcessService(YamlService yaml)Creates an abstract service from YAML information.PythonSyncProcessService(java.lang.String serviceId, java.io.InputStream ymlFile)Creates an instance from a service id and a YAML artifact.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static org.slf4j.LoggergetLogger()Returns the logger.voidmigrate(java.lang.String resourceId)Migrates a service.<I> voidprocess(java.lang.String inType, I data)Requests asynchronous processing a data item.private <I,O>
OprocessImpl(java.lang.String inType, I data)Requests processing a data item.<I,O>
OprocessSync(java.lang.String inType, I data, java.lang.String outType)Requests synchronous processing a data item.voidreconfigure(java.util.Map<java.lang.String,java.lang.String> values)Reconfigures the service.voidswitchTo(java.lang.String targetId)Switches to an interface-compatible service.voidupdate(java.net.URI location)Updates the service by the service in the givenlocation.-
Methods inherited from class de.iip_ecosphere.platform.services.environment.AbstractPythonProcessService
addParameterConfigurer, attachIngestor, compose, createAndCustomizeProcess, createScanInputThread, getAvgResponseTime, getHome, getInTypeInfo, getLocationKey, getOutTypeInfo, getParameterConfigurer, getParameterNames, getPythonExecutable, handleErrorStream, handleResult, initializeFrom, registerInputTypeTranslator, registerOutputTypeTranslator, scanInputStream, start, startExecutableByName, stop, toJson
-
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, isDeployable, isTopLevel, notifyReconfigured, passivate, reconf, reconfigure, rollbackReconfigurationOnFailure, setLibJars, setState
-
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.GenericMultiTypeService
processQuiet, processSyncQuiet
-
Methods inherited from interface de.iip_ecosphere.platform.services.environment.Service
activate, getDescription, getKind, getName, getNetMgtKeyAddress, getVersion, isDeployable, isTopLevel, passivate
-
Methods inherited from interface de.iip_ecosphere.platform.services.environment.switching.ServiceBase
getId, getState, setState
-
-
-
-
Constructor Detail
-
PythonSyncProcessService
public PythonSyncProcessService(java.lang.String serviceId, java.io.InputStream ymlFile)Creates an instance from a service id and a YAML artifact.- Parameters:
serviceId- the service idymlFile- the YML file containing the YAML artifact with the service descriptor
-
PythonSyncProcessService
public PythonSyncProcessService(YamlService yaml)
Creates an abstract service from YAML information.- Parameters:
yaml- the service information as read from YAML. By default, the Python executable is "ServiceEnvironment.py", which can be overridden byYamlProcess.getExecutable().YamlProcess.getHomePath()is set to the home path where the executable was extracted to. Further,YamlProcess.getCmdArg()are taken over if given.
-
-
Method Detail
-
migrate
public void migrate(java.lang.String resourceId) throws java.util.concurrent.ExecutionExceptionDescription copied from interface:ServiceMigrates a service. However, it may be required to migrate/move the containing artifact. [adaptation]- Parameters:
resourceId- the target resource id, e.g., a device- Throws:
java.util.concurrent.ExecutionException- if migration fails
-
update
public void update(java.net.URI location) throws java.util.concurrent.ExecutionExceptionDescription copied from interface:ServiceUpdates the service by the service in the givenlocation. This operation is responsible for stopping the running service (if needed), replacing it, starting the new service.- Parameters:
location- the location of the new service, e.g., an URL- Throws:
java.util.concurrent.ExecutionException- if the given service cannot be updated for some reason, e.g., because the replacement service is not an evolved version of the running service
-
switchTo
public void switchTo(java.lang.String targetId) throws java.util.concurrent.ExecutionExceptionDescription copied from interface:ServiceSwitches to an interface-compatible service. This method cares for stopping the old service, performing a handover if adequate, starting thetargetservice. [adaptation]- Parameters:
targetId- the id of the target service- Throws:
java.util.concurrent.ExecutionException- if switching the service cannot be performed for some reason
-
reconfigure
public void reconfigure(java.util.Map<java.lang.String,java.lang.String> values) throws java.util.concurrent.ExecutionExceptionDescription copied from interface:ServiceReconfigures the service. [adaptation]- Specified by:
reconfigurein interfaceService- Overrides:
reconfigurein classAbstractService- Parameters:
values- the (service-specific) name-value mapping that shall lead to a reconfiguration of the service; values come either as primitive values or as JSON structures complying with the parameter descriptor. The service is responsible for correct JSON de-serialization according to the respective descriptor.- Throws:
java.util.concurrent.ExecutionException- if reconfiguration fails
-
getLogger
protected static org.slf4j.Logger getLogger()
Returns the logger.- Returns:
- the logger
-
processImpl
private <I,O> O processImpl(java.lang.String inType, I data) throws java.util.concurrent.ExecutionExceptionRequests processing a data item.- Type Parameters:
I- the input data typeO- the output data type- Parameters:
inType- the name ofinTypein the configuration modeldata- the data item to be processed- Returns:
- the output, always null in case of asynchronous processing as the result is passed to a registered ingestor
- Throws:
java.util.concurrent.ExecutionException- if the execution fails for some reason, e.g., because type translators are not registered (@link #registerInputTypeTranslator(Class, Class, TypeTranslator, TypeTranslator)}
-
process
public <I> void process(java.lang.String inType, I data) throws java.util.concurrent.ExecutionExceptionDescription copied from interface:GenericMultiTypeServiceRequests asynchronous processing a data item.- Type Parameters:
I- the input data type- Parameters:
inType- the name ofinTypein the configuration modeldata- the data item to be processed- Throws:
java.util.concurrent.ExecutionException- if the execution fails for some reason, e.g., because type translators are not registered (@link #registerInputTypeTranslator(Class, Class, TypeTranslator, TypeTranslator)}
-
processSync
public <I,O> O processSync(java.lang.String inType, I data, java.lang.String outType) throws java.util.concurrent.ExecutionExceptionDescription copied from interface:GenericMultiTypeServiceRequests synchronous processing a data item.- Type Parameters:
I- the input data typeO- the output data type- Parameters:
inType- the name ofinTypein the configuration modeldata- the data item to be processedoutType- the name ofoutTypein the configuration model- Returns:
- the output, always null in case of asynchronous processing as the result is passed to a registered ingestor
- Throws:
java.util.concurrent.ExecutionException- if the execution fails for some reason, e.g., because type translators are not registered (@link #registerInputTypeTranslator(Class, Class, TypeTranslator, TypeTranslator)}
-
-