Next: Unit Tests for the
Up: Implementing OPC Server Functionality
Previous: Handling Concurrent Requests
Contents
The Twisted framework uses such an event-driven system and uses the
so-called ``deferred'' object for building function chains. It is
possible to attach ``callbacks'' and ``errbacks'' to such deferreds,
which will be executed when the deferred is ``called back''
(``fired'').
A sample program is shown in listing 36, which
depicts a simple function that is added to a deferred and fired
five seconds after the program started.
language=C
Deferreds have various additional capabilities such as the following:
- Error Handling:
- Apart from adding callback functions to a
deferred, so-called ``errbacks'' can be added. These errbacks will
be executed in case a callback raised an error. The errback may
then either catch this error, in which case the next callback
is executed or re-raise an error, which leads to the execution
of the following errback.
- Returning Deferreds:
- The return values of a callback function
will be used as function arguments of the next function in the
callback chain. In case a callback function needs to wait for another
event, it is possible to create another deferred, add some callbacks
or errbacks and return it instead of the return values. The last
function in the callback chain of this ``inner'' deferred will then
return the arguments for the callback in the ``outer'' chain.
- Waiting for Multiple Deferreds:
- Twisted provides functions
that enable waiting for multiple deferreds. For instance, this
feature can be used if a function has to wait for multiple requests,
such as depicted in figure 63.
Apart from solving concurrency issues, Twisted implements libraries
for various Internet protocols, such as TCP, HTTP, SMTP, Secure Shell
(SSH), XML-RPC and many more. These libraries are of much use for the
OPC Server design as HTTP will be used for transporting SOAP messages
and ESD messages is based on a simple line-based TCP protocol. More
information about the Twisted framework can be found in
[FET06].
Next: Unit Tests for the
Up: Implementing OPC Server Functionality
Previous: Handling Concurrent Requests
Contents
Hermann Himmelbauer
2006-09-27