FileDocCategorySizeDatePackage
RefreshManager.javaAPI DocphoneME MR2 API (J2ME)5412Wed May 02 18:00:42 BST 2007gov.nist.microedition.sip

RefreshManager

public class RefreshManager extends Object
Refresh manager. This code is in the public domain.

Fields Summary
private static RefreshManager
instance
The unique instance of this class.
private Hashtable
refreshTable
The hashtable keeping a mapping between the refreshID and the refresh Tasks.
private int
idGenerator
generator of task id .
Constructors Summary
private RefreshManager()
Creates a new instance of the RefreshManager.


                
      
        refreshTable = new Hashtable();
    
Methods Summary
public intcreateRefreshTask(gov.nist.siplite.message.Request request, javax.microedition.sip.SipConnectionNotifier sipConnectionNotifier, javax.microedition.sip.SipRefreshListener sipRefreshListener, javax.microedition.sip.SipClientConnection sipClientConnection)
Creates a new RefreshTask with a specific id, schedules it and keep the mapping between this newly created task and the id.

param
request for which a refresh task must be created
param
sipConnectionNotifier used to send the request
param
sipRefreshListener the callback interface used listening for refresh event on this task
param
sipClientConnection the connection to update
return
the id of the newly created task

        int taskId = ++idGenerator;
        RefreshTask refreshTask = new RefreshTask(
                String.valueOf(taskId),
                request,
                sipConnectionNotifier,
                sipRefreshListener,
                sipClientConnection);
        refreshTable.put(String.valueOf(taskId), refreshTask);
        return taskId;
    
public static synchronized gov.nist.microedition.sip.RefreshManagergetInstance()
Returns the instance of RefreshManager.

return
the instance of RefreshManager singleton

        if (instance == null)
            instance = new RefreshManager();
        return instance;
    
public RefreshTaskgetTask(java.lang.String taskId)
Return the task mapping the taskId

param
taskId - the id of the task to retrieve
return
the Refresh task mapping the taskId

        return (RefreshTask)refreshTable.get(taskId);
    
public voidremoveTask(java.lang.String taskId)
Removes a task

param
taskId - the task id of the task to remove

        refreshTable.remove(taskId);
    
public voidscheduleTask(java.lang.String taskId, int expires)
Schedules the task whose id is given in parameter for the expires

param
taskId - the id of the task to schedule
param
expires - the expires time,so the delay until when the stack must schedule the task. If it is -1, it means that the expires has already been given when the task was created.

        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
            Logging.report(Logging.INFORMATION, LogChannels.LC_JSR180,
                "schedule the next register in " + expires + " sec");
        }

        RefreshTask refreshTask = (RefreshTask)refreshTable.get(taskId);
        if (refreshTask == null)
            return;
        if (expires == -1)
            return;
        if (expires >= 0) {
            // The timer to shcedule the tasks
            Timer timer = new Timer();
            // Once the task has been processed, it can be scheduled again
            // so a new one is created
            refreshTask = new RefreshTask(
                    refreshTask.getTaskId(),
                    refreshTask.getRequest(),
                    refreshTask.getSipConnectionNotifier(),
                    refreshTask.getSipRefreshListener(),
                    refreshTask.getSipClientConnection());
            refreshTable.put(taskId, refreshTask);
            timer.schedule(refreshTask, expires * 1000);
        }