Container-managed Lifecycle

Services hosted in the GridServer environment are virtualized—provisioned dynamically on Engines at the behest of the GridServer Manager to satisfy demand. In this model, Service initialization and destruction happens automatically, but proper start-up and clean-up operations can be performed on the Service by registering the right methods to call on the Service to accomplish these tasks. The following simple class demonstrates a Service that connects to a hypothetical database:

public class DBCalculator {
    public void initDBConnection(Properties connProps, int someVal) {
        _connection = new Connection(Properties props);
    }
    public Example calculate(String arg1, …) { … }
    public void close() {
        if (_connection != null) _connection.close();
    }
    private Connection _connection;
}

When a class is registered as a Service Type, it is possible to specify in the ContainerBinding section of the registry page which methods are used for initialization and destruction of the Service. In this example, initDBConnection is specified as the “initMethod” field and close is specified in the “destroyMethod” field. Since initDBConnection takes two arguments, a Properties object and an int, the client-side proxy class has a constructor with the same argument list:

public class DBCalculatorProxy {
public DBCalculatorProxy(Properties connProps, int someVal) { … }

}

The “close” method is listed as the destroyMethod, and is exposed on the client-side proxy as a method named “destroy.”