A service component performs background processing for EAServer clients and other EAServer components. EAServer loads service components at server start-up time.
When you mark a component as a service component in one of the PowerBuilder wizards, PowerBuilder installs the component as a service in EAServer at deployment time. This is equivalent to adding the component to the list of services for the server by modifying its com.sybase.EAServer.server.services property.
When you create a service component, the wizard marks the component as shared. If you want more than one instance of a service component, you can change that setting in the Project painter. Select the number of instances you want in the Create Instances spin control on the Components page of the EAServer Component Generator property sheet in the Project painter. Notice that when you change the number of instances to a number greater than one, the Concurrency and Automatic Demarcation/Deactivation are checked. This is to ensure that the component does not encounter threading issues in EAServer. For more information, see “Threading issues and component types”.
The PowerBuilder wizards include three additional functions for a service component. These functions are defined in the CTSServices::GenericServices interface and allow you to control the behavior of background processes associated with the service:
Start EAServer calls the Start function after the service component has been loaded. You can add logic to this function to perform start-up initialization for the service.
Run EAServer calls the Run function after the first invocation of the Start function returns. The Run function allows you to perform repetitive tasks as a background process. The Run function must periodically suspend its own execution by calling the JagSleep C function. The JagSleep function frees the CPU to perform other tasks. To use the JagSleep function, declare an external function for JagSleep in PowerBuilder. Here is the syntax to use for the function declaration:
subroutine JagSleep (Long seconds) LIBRARY "libjdispatch.dll"
Stop This function allows you to stop the execution of the background process coded in the Run function. You can implement a service-manager client for your service that calls Stop, Start, and Run so that the service can be restarted without restarting EAServer. The script for the Stop function can also clean up any resources that were allocated in the Start function.