The SIP Servlet Tutorial

Managing SIP Timers

The container provides a javax.servlet.sip.TimerService implementation that allows you to create timers, which are javax.servlet.sip.ServletTimer instances. The TimerService interface defines the following methods for creating timers:

Table 1–15 TimerService Timer Creation Methods

Method 

Description 

createTimer(SipApplicationSession session, long delay, boolean isPersistent, Serializable info)

Creates a single, optionally persistent timer associated with the specified SIP application session. The delay parameter is the time in milliseconds before a timer fires. The info parameter is the application information delivered when the timer expires.

createTimer(SipApplicationSession session, long delay, long period, boolean fixedDelay, boolean isPersistent, Serializable info)

Creates a recurring, optionally persistent timer associated with the specified SIP application session. The delay parameter is the time in milliseconds before the timer first fires. The period parameter is the time in milliseconds after the first timer firing that the timer will fire again. The fixedDelay parameter specifies whether the timer is fixed-delay or fixed-rate. The info parameter is the application information delivered when the timer expires.

The ServletTimer interface defines the following methods for managing a particular timer:

Table 1–16 TimerService Timer Management Methods

Method 

Description 

cancel()

Cancels the timer. 

getApplicationSession()

Returns the SipApplicatonSession instance the timer is associated with.

getId()

Returns the ID of the timer as a String. 

getInfo()

Returns a Serializable object of the information specified when the timer was created.

getTimeRemaining()

Returns a long representing the number of milliseconds until the timer is scheduled to next fire.

scheduledExecutionTime()

Returns a long representing the most recent time the timer was scheduled to fire. If the timer has not yet fired, the return value is undefined.

For more information on the TimerService interface, see the SIP Servlet 1.1 Javadocs.