What is adapter::Service::start() for?

Asked by Bob

Both Adapter::Service and Adapter::Xaction have declared the method named start(), and from the example code, it seems that Adapter::Xaction::start() is always used to adapt the http message, is that ture?

if so, what is the Adapter::Service::start() used for? When should I use Adapter::Service::start()?

Question information

Language:
English Edit question
Status:
Solved
For:
eCAP Edit question
Assignee:
No assignee Edit question
Solved by:
Alex Rousskov
Solved:
Last query:
Last reply:
Revision history for this message
Alex Rousskov (rousskov) said :
#1

The host application calls adapter::Service::start() after calling adapter::Service::configure() and before making the first adapter::Service::makeXaction() call. The host application also calls adapter::Service::start() if it wants to resume using a previously stopped Service (i.e., after the adapter::Service::stop() call).

A typical adapter::Service call sequence (without taking reconfiguration, suspension, and retirement into account) looks like this:

Service()
configure()
start()
wantsUri() && makeXaction()
wantsUri() && makeXaction()
wantsUri() && makeXaction()
...
stop()
~Service()

Revision history for this message
Alex Rousskov (rousskov) said :
#2

Forgot to mention that overriding the adapter::Service::start() method is optional, as indicated by providing a default implementation in the libecap library. If you do not need to prepare your Service for makeXaction() calls, then you do not need to override it.

Revision history for this message
Bob (362061693-k) said :
#3

well, Adapter::Service::configure() method is used to read or write the host application configuration file, say squid.conf?

Revision history for this message
Bob (362061693-k) said :
#4

libecap::adapter::Service::start() is an inline method which doesn't do anything, and is this means the default implementation?

but I am not very clear about what you said as the following:
----------------------------------------------------------------
The host application also calls adapter::Service::start() if it wants to resume using a previously stopped Service (i.e., after the adapter::Service::stop() call).
--------------------------------

I don't understand in which context the above situation you mentioned will happen, and even it happens, you said that the host application wants to resume a previously stopped Service, however why the adapter being written should provide a start() for an unexpected resuming exectued by the host? I am confused!

Revision history for this message
Alex Rousskov (rousskov) said :
#5

> I don't understand in which context the above situation you mentioned will happen

It might happen, for example, if the host application was reconfigured to disable eCAP services and then was reconfigured again to enable them.

> why the adapter being written should provide a start() for an unexpected resuming exectued by the host?

The adapter may want to override the Service::start() method if it needs to do something special to prepare for future makeXaction() calls. For example, the service might need to allocate a container to keep track of those future transactions.

Revision history for this message
Bob (362061693-k) said :
#6

The adapter may want to override the Service::start() method if it needs to do something special to prepare for future makeXaction() calls. For example, the service might need to allocate a container to keep track of those future transactions
--------------------------------------------------

does it mean that Service::start() can be used to maintain the state to some extent? namely Adapter::Xaction instance just exist for a short time to adapt the message, but Adapter::Service can persist all the time even if the current messsage is adapted over?

Revision history for this message
Best Alex Rousskov (rousskov) said :
#7

Yes, adapter::Service objects should persist throughout the host application lifetime.

Revision history for this message
Bob (362061693-k) said :
#8

I see :)

Revision history for this message
Bob (362061693-k) said :
#9

Thanks Alex Rousskov, that solved my question.