Managing the life cycle of Business Entities and Business Tasks

Every request to a Business Entity or Business Task should be done through the Service Interface class (or the Service Adapter when working on the client). The Service Interface uses the Service Manager class as a factory or registry for Business Services. By default the Service Manager does only start Business Tasks (Business Entities or Business Tasks) and never shuts them down. This can be desirable to reduce the start up time of Business Services, especially when used frequently. However in large applications (e.g. large number of Business Entities) this may lead to a huge memory consumption of the AppServer agents when only a small number of Business Entities are requested frequently and other Business Entities are only requested occasionally.

Defining Business Services Life Time

The Service Manager uses an (optional) service of the IServiceManagerLifeCycleProvider type. This type returns a temp-table with the following structure to the Service Manager:

ttServiceLifeCycleDefinition Temp-Table from Consultingwerk/OERA/ttServiceLifeCycleDefinition.i
DEFINE TEMP-TABLE ttServiceLifeCycleDefinition NO-UNDO
    FIELD ServiceNamePattern      AS CHARACTER
    FIELD StopAfterEachRequest    AS LOGICAL INIT ?
    FIELD TimeoutAfterLastRequest AS INTEGER INIT ?
    FIELD TimeoutAfterStart       AS INTEGER INIT ?
    .

Description of the field values:

Field NameDescription
ServiceNamePatternCharacter Value defining the Business Service Names that this rule applies to. Supported are either complete class names (when the Service Name Pattern does not contain a *), whole packages or BEGINS matches (when the Service Name Pattern does end with the *) or MATCHES (when the Service Name Pattern contains the * at any position)
StopAfterEachRequestLogical value (true/false), matching Business Services will be stopped after every request.
TimeoutAfterLastRequestInteger value, the number of seconds that a Business Service should be stopped after the last request (60 seconds = 1 minute, 900 seconds = 15 minutes, 1800 seconds = 30 minutes, 3600 seconds = 1 hour, 86400 seconds  = 1 day)
TimeoutAfterStartInteger value, the number of seconds that a Business Service should be stopped after it was started

Exactly one value of StopAfterEachRequest, TimeoutAfterLastRequest and TimeoutAfterStart must be set.

The default implementation ServiceManagerLifeCycleProvider does import the contents of this temp-table from an XML file. The default file name is .servicelifecycledefinition.xml or the value of the "ServiceLifeCycleDefinition" setting from the IConfigurationProvider service.

Sample .servicelifecycledefinition.xml file
<?xml version="1.0"?>
<ttServiceLifeCycleDefinition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <ttServiceLifeCycleDefinitionRow>
    <ServiceNamePattern>Consultingwerk.*</ServiceNamePattern>
    <StopAfterEachRequest xsi:nil="true"/>
    <TimeoutAfterLastRequest>60</TimeoutAfterLastRequest>
    <TimeoutAfterStart xsi:nil="true"/>
  </ttServiceLifeCycleDefinitionRow>
  <ttServiceLifeCycleDefinitionRow>
    <ServiceNamePattern>Consultingwerk.SmartComponentsDemo.*</ServiceNamePattern>
    <StopAfterEachRequest>true</StopAfterEachRequest>
    <TimeoutAfterLastRequest xsi:nil="true"/>
    <TimeoutAfterStart xsi:nil="true"/>
  </ttServiceLifeCycleDefinitionRow>
</ttServiceLifeCycleDefinition>

Configuring the AppServer

The AppServer needs to launch the IServiceManagerLifeCycleProvider service prior to the first request to any Business Service.

The AppServer does further require the use of the deactivate Procedure Consultingwerk\Framework\Server\as_deactivate.p. As we do not need this file for any other purpose you may have to add this procedure to your AppServer configuration to manage this feature.

Logging

The Service Manager does support the "ServiceManager" custom log entry type and writes messages to the current client logfile whenever a Business Service is started or stopped.

 

IServiceManagerLifeCycleProvider