Version

TimerService

The TimerService interface enables SIP servlet applications to schedule timers that trigger notifications upon expiration. This functionality allows applications to perform time-sensitive operations or handle delayed events. Notifications for expired timers are received through implementations of the TimerListener interface. To use timers, applications must implement this listener and declare it in the SIP deployment descriptor.

SIP servlet containers are mandated to provide a TimerService instance to applications. This instance is made accessible via a ServletContext attribute named javax.servlet.sip.TimerService. By leveraging the TimerService, applications can set, manage, and handle timers within the SIP.

Methods:

createTimer
ServletTimer createTimer(SipApplicationSession appSession,
                         long delay,
                         boolean isPersistent,
                         java.io.Serializable info)

The method schedules a one-time ServletTimer to trigger after a specified delay. This timer is associated with a given SipApplicationSession and optionally stores application-specific information to be delivered upon expiration. This method provides a convenient way to manage time-sensitive actions within a SIP application, with optional persistence and the ability to attach custom data for processing during timer expiration.
Parameters:
appSession: The SipApplicationSession to which the new ServletTimer will be associated.
delay: The time, in milliseconds, before the timer expires.
isPersistent: Specifies whether the timer should persist across system restarts (true) or not (false).
info: Optional application-specific data to be passed along with the timer expiration notification. This can be null.
Returns:
A newly created ServletTimer object, scheduled to expire after the specified delay.
Exception:
java.lang.IllegalStateException: Thrown if the specified SipApplicationSession is invalid.

createTimer
ServletTimer createTimer(SipApplicationSession appSession,
                         long delay,
                         long period,
                         boolean fixedDelay,
                         boolean isPersistent,
                         java.io.Serializable info)

The createTimer method schedules a repeating ServletTimer to expire after a specified delay and subsequently at regular intervals. The timer can be configured for either fixed-delay or fixed-rate execution, depending on the application's requirements. This method is ideal for scheduling recurring tasks within SIP applications. It provides flexibility for setting up recurring tasks, accommodating both delay-sensitive and frequency-sensitive requirements, while offering persistence for reliable operation across system restarts.
Parameters:
appSession: The SipApplicationSession to which the new ServletTimer will be associated.
delay: The initial delay, in milliseconds, before the timer first expires.
period: The interval, in milliseconds, between successive timer expirations.
fixedDelay: Determines the scheduling mode:

  • true: Fixed-delay mode. Each execution is scheduled relative to the actual completion time of the previous execution, causing delays in case of longer execution times.
  • false: Fixed-rate mode. Each execution is scheduled relative to the initial execution time, ensuring a consistent frequency, even if prior executions are delayed.

isPersistent: Specifies whether the timer should persist across system restarts (true) or not (false).
info: Optional application-specific data to be delivered with the timer expiration notification. This can be null.
Returns:
A newly created ServletTimer object, scheduled to execute repeatedly at the specified intervals.
Exceptions:
java.lang.IllegalStateException: Thrown if the specified SipApplicationSession is invalid.

Start innovating with Mobius

What's next? Let's talk!

Mobius Software

As a company you'll get:

  • Get started quickly

  • Support any business model

  • Join millions of businesses

Questions? websupport@mobius.com