Skip navigation links


javax.servlet.sip
Interface ServletTimer


public interface ServletTimer

Created by the TimerService for servlet applications wishing to schedule future tasks.

See Also:
TimerService, TimerListener

Method Summary
 void cancel()
          Cancels this timer.
 SipApplicationSession getApplicationSession()
          Returns the application session associated with this ServletTimer.
 java.lang.String getId()
          Returns a string containing the unique identifier assigned to this timer task.
 java.io.Serializable getInfo()
          Get the information associated with the timer at the time of creation.
 long getTimeRemaining()
          Get the number of milliseconds that will elapse before the next scheduled timer expiration.
 long scheduledExecutionTime()
          Returns the scheduled expiration time of the most recent actual expiration of this timer.

 

Method Detail

getId

java.lang.String getId()
Returns a string containing the unique identifier assigned to this timer task. The identifier is assigned by the servlet container and is implementation dependent.
Returns:
a string specifying the identifier assigned to this session
Since:
1.1

getApplicationSession

SipApplicationSession getApplicationSession()
Returns the application session associated with this ServletTimer.
Returns:
application session associated with this ServletTimer

getInfo

java.io.Serializable getInfo()
Get the information associated with the timer at the time of creation.
Returns:
the Serializable object that was passed in at timer creation, or null if the info argument passed in at timer creation was null.

scheduledExecutionTime

long scheduledExecutionTime()
Returns the scheduled expiration time of the most recent actual expiration of this timer.

This method is typically invoked from within TimerListener.timerFired to determine whether the timer callback was sufficiently timely to warrant performing the scheduled activity:

   public void run() {
       if (System.currentTimeMillis() - scheduledExecutionTime() >=
           MAX_TARDINESS)
               return;  // Too late; skip this execution.
       // Perform the task
   }
 

This method is typically not used in conjunction with fixed-delay execution repeating tasks, as their scheduled execution times are allowed to drift over time, and so are not terribly significant.

Returns:
the time at which the most recent expiration of this timer was scheduled to occur, in the format returned by Date.getTime(). The return value is undefined if the timer has yet to expire for the first time.

cancel

void cancel()
Cancels this timer. If the task has been scheduled for one-time execution and has not yet expired, or has not yet been scheduled, it will never run. If the task has been scheduled for repeated execution, it will never expire again.

Note that calling this method on a repeating ServletTimer from within the timerFired method of a TimerListener absolutely guarantees that the timer will not fire again (unless rescheduled).

This method may be called repeatedly; the second and subsequent calls have no effect.


getTimeRemaining

long getTimeRemaining()
Get the number of milliseconds that will elapse before the next scheduled timer expiration. For a one-time timer that has already expired (i.e., current time > scheduled expiry time) this method will return the time remaining as a negative value.
Returns:
the number of milliseconds that will elapse before the next scheduled timer expiration.

Skip navigation links

Copyright 1996, 2010, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.

Java SIP Servlet API 1.1 Reference

Part Number E17883-01