You are viewing an old version of this page. View the current version.
Compare with Current
View Page History
« Previous
Version 4
Next »
Introduction
On this day we will focus on implementing the logic for our component. By the end of the day, we expect the groups to:
- Learn the details of their interfaces and the interaction with other components as described in the first session and ACS Workshop - Project Details confluence page
- Learn about lifecycle methods
- Learn how to interact with other components
- Logic implementation on the methods
- Adding logging to the implementations
- Start the error handling (catch and throw) of ACS exceptions
Guides
As a guide, we're going to show you sample code for logging, to define exceptions, throw and catch exceptions.
Component Details
The component details will be presented in the first session from ACS Workshop - Project Details page to describe the interfaces and interactions of the project's components.
Lifecycle Methods
The ACS components have a couple of methods associated with its lifecycle that automatically gets executed at different phases of the component initialization and deactivation.
- initialize():
- Called to give the component time to initialize itself. For instance, the component could retrieve connections, read in configuration files/parameters, build up in-memory tables, etc.
- In fact, this method might be called quite some time before functional requests can be sent to the component
- execute():
- cleanUp():
- aboutToAbort():
Called when due to some error condition the component is about to be forcefully removed some unknown amount of time later (usually not very much...).
The component should make an effort to die as neatly as possible
Because of its urgency, this method will be called asynchronously to the execution of any other method of the component
Implementing Lifecycle functionality
Python
class <name>(...):
...
def initialize():
#Assign variable values
#Initialize data
...
def execute():
#Retrieve components
#Consider ready to receive calls (Change states if appropriate)
...
def cleanUp():
#Release components
#Release resources
...
def aboutToAbort():
#Do any critical clean up
#Continue with less critical stuff such as releasing components and other activities similar to cleanUp
...
...
Java
public class <name> ... {
...
public void initialize() {
//Assign variable values
//Initialize data
...
}
public void execute() {
//Retrieve components
//Consider ready to receive calls (Change states if appropriate)
...
}
public void cleanUp() {
//Release components
//Release resources
...
}
public void aboutToAbort() {
//Do any critical clean up
//Continue with less critical stuff such as releasing components and other activities similar to cleanUp
...
}
...
}
C++
class <name> : ... {
...
void initialize();
void execute();
void cleanUp();
void aboutToAbort();
...
};
void <name>::initialize() {
//Assign variable values
//Initialize data
...
}
void <name>::execute() {
//Retrieve components
//Consider ready to receive calls (Change states if appropriate)
...
}
void <name>::cleanUp() {
//Release components
//Release resources
...
}
void <name>::aboutToAbort() {
//Do any critical clean up
//Continue with less critical stuff such as releasing components and other activities similar to cleanUp
...
}
Retrieving and Releasing Components
During component interaction it will be needed to request and release components. When interacting with components from other components, you need to obtain the container services references to make the request to the Manager. Here we will show how to retrieve two types of components:
- Component By Name
- Default Component (By IDL)
Example Request and Release
Python
#By Name
comp = self.getComponent("<Name>")
#By Interface. Must be at least one component configured as default!
comp = self.getDefaultComponent("IDL:<prefix>/<Module>/<Interface>:1.0")
#Release Components
self.releaseComponent(comp.name())
Java
//Shared
import alma.<Module>.<Interface>;
import alma.<Module>.<Interface>Helper;
//By Name
<Interface> comp = <Interface>Helper.narrow(this.m_containerServices.getComponent("<Name>"));
//By Interface. Must be at least one component configured as default!
<Interface> comp = <Interface>Helper.narrow(this.m_containerServices.getDefaultComponent("IDL:<prefix>/<Module>/<Interface>:1.0"));
//Release Components
m_containerServies.releaseComponent(comp.name());
C++
//By Name
<Module>::<Interface>_var comp = this->getContainerServices()->getComponent<<Module>::<Interface>>("<Name>");
//By Interface. Must be at least one component configured as default!
<Module>::<Interface>_var comp = this->getContainerServices()->getDefaultComponent<<Module>::<Interface>>("IDL:<prefix>/<Module>/<Interface>:1.0");
//Release Components
this->getContainerServices()->releaseComponent(comp->name());
Logging
ACS Logging has two main benefits:
- Provides a standard mechanism for printing log messages
- Logs go to the "Remote Logger" for distribution of logs and storage
Example Logging
Python
logger = self.getLogger()
logger.logTrace("...")
logger.logDebug("...")
logger.logInfo("...")
logger.logWarning("...")
logger.logError("...")
#An example
logger.info("A real log with a string '%s' and an int (%d)" % ("Log Entry", 3))
Java
m_logger.finer("...");
m_logger.fine("...");
m_logger.info("...");
m_logger.warning("...");
m_logger.severe("...");
#An example
m_logger.info("A real log with a string '" + "Log Entry" + "' and an int (" + String.valueOf(3) + ")");
C++
ACS_TRACE("...");
ACS_DEBUG("...");
ACS_SHORT_LOG((LM_INFO, "..."));
ACS_SHORT_LOG((LM_WARNING, "..."));
ACS_SHORT_LOG((LM_ERROR, "..."));
//An example
ACS_SHORT_LOG((LM_INFO, "A real log with a string '%s' and an int (%d)", "Log Entry", 3));
Error Handling
Error Handling in ACS Components has 4 pieces:
- Error Definitions (XML)
- Error Declarations (IDL)
- Throwing Exceptions
- Handling Exceptions
Error Definitions
Error Declarations
Throwing Exceptions
Handling Exceptions