The first thing needed to implement a server, is to import the required modules and classes:
Code Block |
---|
language | bashpy |
---|
title | Environment Preparation |
---|
|
#Client stubs and definitions, such as structs, enums, etc.
import <Module>
#Skeleton infrastructure for server implementation
import <Module>__POA
#Base component implementation
from Acspy.Servants.ACSComponent import ACSComponent
#Services provided by the container to the component
from Acspy.Servants.ContainerServices import ContainerServices
#Basic component lifecycle (initialize, execute, cleanUp and aboutToAbort methods)
from Acspy.Servants.ComponentLifecycle import ComponentLifecycle
#Error definitions for catching exceptions
import ServiceErr
import <Interface>Err
#Error definitions for creating and raising exceptions
import ServiceErrImpl
import <Interface>ErrImpl |
Besides this, there's the need to create the class using the mentioned infrastructure provided by some of the imported classes:
Code Block |
---|
language | bashpy |
---|
title | Environment Preparation |
---|
|
class <Name>(<Module>__POA.<InterfaceName>, ACSComponent, ContainerServices, ComponentLifecycle):
def __init__(self):
ACSComponent.__init__(self)
ContainerServices.__init__(self)
self._logger = self.getLogger()
... #Custom implementation for the server constructor |
To access a struct, enum, typedef or definition in a module or in an interface, simply do the following:
Code Block |
---|
language | bashpy |
---|
title | Environment Preparation |
---|
|
#From IDL <Module>::<EnumName>::READY
<Module>.READY
#From IDL <Module>::<Interface>::<Enumname>::OFFLINE
Observatory.Service.OFFLINE |
To retrieve a component to interact with, simply do the following:
Code Block |
---|
language | bashpy |
---|
title | Environment Preparation |
---|
|
#By Name
comp = self.getComponent("<Name>")
#By Interface. Must be at least one component configured as default!
comp = self.getDefaultComponent("IDL:alma/<Module>/<Interface>:1.0") |
For logging, as you saw in the class constructor, there's a facility provided by the component. To use it, simply do as follows:
Code Block |
---|
language | bashpy |
---|
title | Environment Preparation |
---|
|
logger = self.getLogger()
logger.logTrace("...")
logger.logDebug("...")
logger.logInfo("...")
logger.logWarning("...")
logger.logError("...") |
For catching and raising exceptions:
Code Block |
---|
language | bashpy |
---|
title | Environment Preparation |
---|
|
#For catching exceptions
except <Interface>Err.<ExceptionName>Ex as e:
#For raising exceptions
raise <Interface>ErrImpl.<ExceptionName>ExImpl().get<ExceptionName>Ex()
#For raising exceptions with parameters
err = <Interface>ErrImpl.<ExceptionName>ExImpl()
err.set<ParamName>(<Value>)
raise err.get<ExceptionName>Ex()
#For logging an error message from the exceptions
err = <Interface>ErrImpl.<ExceptionName>ExImpl()
err.log()
raise err.get<ExceptionName>Ex() |
...