Chapter 9. Lifecycle Management

Since OGSI includes a factory/instance model, we are faced with services which have non-trivial lifecycles. In plain web services, the lifecycle of a service was pretty simple: the service is created when the container is started, and it is destroyed when the container is stopped. Managing its lifecycle wasn't really a big deal. However, since Grid Services are potentially transient, and we can have instances popping in and out of our container at any given time, the management and control of their lifecycle is no longer trivial.

But, what exactly do we refer to when we say 'lifecycle'? In most object systems, instances are usually said to have a lifecycle. On one hand, this refers to the time between instance creation and destruction. On the other hand, lifecycle is also understood in a broader sense: some instances will need to outlive not only the lifetime of their clients, but also the lifetime of the server they are contained in. This means that if the server is restarted, the instance should be loaded with the exact same internal values it had right before the server was stopped.

GT3 provides us the necessary tools to manage the lifecycle of Grid Services. For example, we can tell our instance to run some code right before it is created and right before it is destroyed (to load and unload its internal values to secondary storage). In this section we will see some of the lifecycle management tools we can find in GT3.

Since lifecycle is specially important in transient services, we'll add lifecycle management to the transient services example. However, the code we'll use will be a combination of the transient services example and the logging example seen in the previous section. We'll reuse the logging example's implementation (which already includes some logging instructions which will come in handy) but will use a deployment descriptor for transient services. Although much of the code will be presented as a modification of previously existing code, all instructions will be given relative to a new directory that includes all the modified code (with lifecycle management):