Mastering PowerBuilder

HomePrevious Lesson: Jaguar shared components versus PowerBuilder shared objects
Next Lesson: Instance Pooling

Service Component

A Jaguar Service component performs background processing for Jaguar clients as well as for other Jaguar components. When marked, PowerBuilder installs the component as a service component in Jaguar at deployment time. This is equivalent to adding the component to the list of services for the server by modifying its com.sybase.jaguar.server.services property. Jaguar loads service components at startup time.

PowerBuilder wizards include three additional functions for a service component. Using these functions you can control the behavior of background processes associated with the service:

Start(): This function is called whenever the component is loaded by Jaguar. Typically, startup initialization is done in this function.

Run(): The Jaguar server 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, you need to declare an external function for JagSleep in PowerBuilder. Here's the syntax you need to use for the function declaration:
subroutine JagSleep (Long seconds) LIBRARY "libjdispatch.dll"

Stop(): This function works exactly in the opposite direction to Start() function. This is where you write logic to stop the execution of the background process coded in the Run() function. You may also want to include clean up logic to release any resources that were allocated in the Start() function.
HomePrevious Lesson: Jaguar shared components versus PowerBuilder shared objects
Next Lesson: Instance Pooling