Service lifecycle

Symphony triggers state changes for the ServiceContainer as illustrated in the following diagram. The calls indicated on the diagram are calls made in the service, with the exception of Register() which is an internal call made by the system.

The arrows indicate a normal return of the method.

Note:

OnSessionEnter( ) and OnSessionLeave( ) are not called if the client does not relay common data when creating a session. OnSessionUpdate( ) is not called if the client does not relay common data updates to the session.

Service instance lifecycle

A service instance is an executing instance of a service. There can be many instances of a service at any one time. Service instances are created by service instance managers.

Service instances can be started either before or when they are assigned to a session. They can stay running to compute multiple tasks of the same session to use the data and state information cached in memory for better performance. They can either exit or continue running when their serviced session is finished.

A service is transient if the service instances start and exit per session. A service is persistent if the service instances stay and serve multiple sessions. A persistent service is a long-running process like a daemon, which has to be more carefully programmed to avoid any accumulated problems such as memory leaks.

By default, the service instances in Symphony persist for multiple sessions. To make a service instance transient, you can return a control code from onSessionLeave() to tell Symphony to restart the service instance once it leaves the current session. This can also be used when you want to clean up any accumulated problems by restarting your service from time to time.

Timeouts that affect service instance life cycle

The service instance lifecycle can be affected by different configured timeouts. If an application has timeouts configured, then Symphony will take action if an operation exceeds the configured timeout. In this case, Symphony terminates the service instance, causing the cleanup methods not to execute under the following circumstances:


Method

Not called

onDestroyService()

  • When an invocation of one of the following service methods times out:

    • SessionEnter

    • SessionUpdate

    • Invoke

    • SessionLeave

  • When a task cannot complete before the suspendGracePeriod expires.

  • When a task cannot complete before the taskCleanupPeriod expires.

  • When a resource on which the service instance is running is reclaimed, and the service instance cannot clean up before the applied reclaim grace period expires.

  • When the application is disabled or unregistered and the service instance cannot clean up before the cleanupTimeout expires.

  • When a middleware component becomes unavailable and the service instance cannot clean up before the cleanupTimeout expires.

onSessionLeave()

  • When an invocation of one of the following service methods times out:

    • SessionUpdate

    • Invoke

  • When a task cannot complete before the suspendGracePeriod expires.

  • When a task cannot complete before the taskCleanupPeriod expires.

  • When a resource on which the service instance is running is reclaimed, and the service instance cannot clean up before the applied reclaim grace period expires.

  • When the application is disabled or unregistered and the service instance cannot clean up before the cleanupTimeout expires.

  • When a middleware component becomes unavailable and the service instance cannot clean up before the cleanupTimeout expires.