8.3.1 Starting a Reaction Service Client

As defined by the standard OSGi lifecycle, the first method to be called on starting a bundle is the bundle activator's start method. The implementation used by the example client activator is shown in Listing 8.4. In this case a new OSGi service tracker is created for the Reaction service, with the lifecycle wrapper being set up to receive notifications of status changes to the Reaction service. At this stage it is not known if the Reaction service is available, so it is not possible to call the lifecycle startup method.


\begin{listing}
% latex2html id marker 1766\begin{verbatim}public synchroniz...
...;
}\end{verbatim}
\caption{Reaction Client Activator Start Method}
\end{listing}

Once the client bundle has been started, the OSGi framework will attempt to bind the client to a running instantiation of the Reaction service. If successful, this is notified using the service tracker's addingService callback method. The example used by the example lifecycle wrapper is shown in Listing 8.5. If a lifecycle handler is not already running, this method will create one and then invoke its startup method. By calling the startup method, the wrapper is indicating to the lifecycle handler than the client bundle has been correctly started and bound to a running Reaction service.


\begin{listing}
% latex2html id marker 1776\begin{verbatim}public synchroniz...
...n reactor;
}\end{verbatim}
\caption{Reaction Service Added Method}
\end{listing}