Class PythonAsyncProcessService
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.PythonAsyncProcessService
- All Implemented Interfaces:
GenericMultiTypeService,ParameterConfigurerProvider,Service,ServiceBase
- Direct Known Subclasses:
PythonWsProcessService
Generic command-line-based Python integration for asynchronous processing of multiple data types. Conventions:
- Python is determined by
PythonUtils.getPythonExecutable(). The default is "ServiceEnvironment.py" which must run for this integration with "--mode console". - The Python program runs endless until stopped by this class.
- An asynchronous Python program receives the data via command line input streams based on the input serializer and the symbolic type name.
- Author:
- Holger Eichelberger, SSE
-
Nested Class Summary
Nested classes/interfaces inherited from class de.iip_ecosphere.platform.services.environment.AbstractPythonProcessService
AbstractPythonProcessService.InputHandler, AbstractPythonProcessService.SyncDataIngestor<D> -
Field Summary
FieldsFields inherited from class de.iip_ecosphere.platform.services.environment.AbstractPythonProcessService
TYPE_SEPARATOR_CHARFields inherited from interface de.iip_ecosphere.platform.services.environment.switching.ServiceBase
APPLICATION_SEPARATOR, DEFAULT_APPLICATION_INSTANCE_ID -
Constructor Summary
ConstructorsConstructorDescriptionCreates an abstract service from YAML information.PythonAsyncProcessService(String serviceId, InputStream ymlFile) Creates an instance from a service id and a YAML artifact. -
Method Summary
Modifier and TypeMethodDescriptionvoidactivate()Activates the service.protected voidcreateScanInputThread(Process proc) Creates the input scanning thread.protected static de.iip_ecosphere.platform.support.logging.LoggerReturns the logger.voidMigrates a service.voidPassivates the service.<I> voidRequests asynchronous processing a data item.<I,O> O processSync(String inTypeName, I data, String outTypeName) Requests synchronous processing a data item.voidreconfigure(Map<String, String> values) Reconfigures the service.protected voidsendToService(String type, Object data) Sendstextas input to the service process.voidsetState(ServiceState state) Changes the state.protected ServiceStatestart()Starts the service and the background process.protected ServiceStatestop()Stops the service and the background process.voidSwitches to an interface-compatible service.voidUpdates the service by the service in the givenlocation.Methods inherited from class de.iip_ecosphere.platform.services.environment.AbstractPythonProcessService
addParameterConfigurer, attachIngestor, compose, createAndCustomizeProcess, createScanInputThread, customizePythonArgs, enableFileDeletion, getAvgResponseTime, getHome, getInTypeInfo, getLocationKey, getOutTypeInfo, getOutTypeName, getParameterConfigurer, getParameterNames, getPythonExecutable, getTypeSubstitutionsJson, handleErrorStream, handleResult, initializeFrom, isFileDeletionEnabled, registerInOutRelation, registerInputTypeTranslator, registerOutputTypeTranslator, scanInputStream, startExecutableByName, toJson, unbufferMethods inherited from class de.iip_ecosphere.platform.services.environment.AbstractRunnablesService
registerMethods inherited from class de.iip_ecosphere.platform.services.environment.AbstractService
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, isDeployable, isTopLevel, notifyReconfigured, reconf, reconfigure, rollbackReconfigurationOnFailure, setLibJars, 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.GenericMultiTypeService
processQuiet, processSyncQuietMethods inherited from interface de.iip_ecosphere.platform.services.environment.Service
addTypeSubstitution, createType, createType, getDescription, getKind, getName, getNetMgtKeyAddress, getSubstitutedType, getTypeCreator, getTypeSubstitutions, getVersion, isDeployable, isTopLevelMethods inherited from interface de.iip_ecosphere.platform.services.environment.switching.ServiceBase
getId, getState
-
Field Details
-
proc
-
serviceIn
-
reconfValues
-
-
Constructor Details
-
PythonAsyncProcessService
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
-
PythonAsyncProcessService
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 Details
-
start
Description copied from class:AbstractServiceStarts the service and the background process.- Overrides:
startin classAbstractPythonProcessService- Returns:
- the state to transition to, may be null for none
- Throws:
ExecutionException- if starting the process fails
-
createScanInputThread
Creates the input scanning thread.- Parameters:
proc- the process instance to observe
-
stop
Description copied from class:AbstractServiceStops the service and the background process.- Overrides:
stopin classAbstractPythonProcessService- Returns:
- the state to transition to, may be null for none
-
setState
Description copied from class:AbstractServiceChanges the state. [R133c]- Specified by:
setStatein interfaceServiceBase- Overrides:
setStatein classAbstractService- Parameters:
state- the new state- Throws:
ExecutionException- if changing the state fails for some reason- See Also:
-
migrate
Description 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:
ExecutionException- if migration fails
-
update
Description 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:
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
Description 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:
ExecutionException- if switching the service cannot be performed for some reason
-
reconfigure
Description 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:
ExecutionException- if reconfiguration fails
-
activate
Description copied from interface:ServiceActivates the service. [adaptation]- Specified by:
activatein interfaceService- Overrides:
activatein classAbstractService- Throws:
ExecutionException- in case that activating fails, e.g., because the service is already active
-
passivate
Description copied from interface:ServicePassivates the service. [adaptation]- Specified by:
passivatein interfaceService- Overrides:
passivatein classAbstractService- Throws:
ExecutionException- in case that passivating fails, e.g., because the service is already passive
-
getLogger
protected static de.iip_ecosphere.platform.support.logging.Logger getLogger()Returns the logger.- Returns:
- the logger
-
sendToService
Sendstextas input to the service process.- Parameters:
type- the type of the data to be sentdata- the data to be sent- Throws:
ExecutionException- if sending fails for some reason
-
process
Description 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:
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(String inTypeName, I data, String outTypeName) throws ExecutionException Description copied from interface:GenericMultiTypeServiceRequests synchronous processing a data item.- Type Parameters:
I- the input data typeO- the output data type- Parameters:
inTypeName- the name ofinTypein the configuration modeldata- the data item to be processedoutTypeName- 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:
ExecutionException- if the execution fails for some reason, e.g., because type translators are not registered (@link #registerInputTypeTranslator(Class, Class, TypeTranslator, TypeTranslator)}
-