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

RefreshTask

public class RefreshTask extends TimerTask
Refreshs the transaction state. This code is in the public domain.

Fields Summary
private gov.nist.siplite.message.Request
request
The current request to be processed.
private javax.microedition.sip.SipClientConnection
sipClientConnection
The associated connection client.
private javax.microedition.sip.SipConnectionNotifier
sipConnectionNotifier
The connection state notifier.
private javax.microedition.sip.SipRefreshListener
sipRefreshListener
The current refresh event listener.
private String
taskId
The task identifier.
Constructors Summary
public RefreshTask(String id, gov.nist.siplite.message.Request rq, javax.microedition.sip.SipConnectionNotifier scn, javax.microedition.sip.SipRefreshListener listener, javax.microedition.sip.SipClientConnection scc)
Creates a new instance of RefreshTask

param
id the task identifier
param
rq the request to resend
param
scn the connection used to send the request
param
listener the callback interface used listening for refresh event on this task
param
scc the connection to update


                                                      
     
                       
                       
                       
                       
                        
        taskId = id;
        request = rq;
        sipConnectionNotifier = scn;
        sipRefreshListener = listener;
        sipClientConnection = scc;
    
Methods Summary
public gov.nist.siplite.header.CallIdHeadergetNewCallId()
Gets the new caller identifier.

return
the caller identifier

        return ((SipConnectionNotifierImpl)sipConnectionNotifier).
                                getSipProvider().getNewCallId();
    
public synchronized gov.nist.siplite.message.RequestgetRequest()
Returns the request to refresh

return
the request to refresh

        return request;
    
public javax.microedition.sip.SipClientConnectiongetSipClientConnection()
Return the sipClientconnection on which is enabled the listener

return
the sipClientconnection on which is enabled the listener

        return sipClientConnection;
    
public javax.microedition.sip.SipConnectionNotifiergetSipConnectionNotifier()
Return the callback interface listening for events on this task

return
the callback interface listening for events on this task

        return sipConnectionNotifier;
    
public javax.microedition.sip.SipRefreshListenergetSipRefreshListener()
Return the callback interface listening for events on this task

return
the callback interface listening for events on this task

        return sipRefreshListener;
    
public java.lang.StringgetTaskId()
Returns the task identifier

return
the task identifier

        return taskId;
    
public voidrun()
Run the refresh thread.

see
java.lang.Runnable#run()

        Request clonedRequest = (Request)request.clone();
        // setRequestHeaders(clonedRequest);
        request = null;

        try {
            updateAndSendRequest(clonedRequest);
        } catch (Exception ex) {
            if (Logging.REPORT_LEVEL <= Logging.WARNING) {
                Logging.report(Logging.WARNING, LogChannels.LC_JSR180,
                           "RefreshTask.run(): can't send a message: " + ex);
            }
        }
    
public synchronized voidsetRequestHeaders(gov.nist.siplite.message.Request clonedRequest)
Sets appropriate CSeq and Via headers in the given request preparing it for sending.

param
clonedRequest the request to modify

        // RFC 3261, section 10.2.4, Refreshing Bindings:
        // "A UA SHOULD use the same Call-ID for all registrations during a
        // single boot cycle".
        //
        // Call-Id header was added in SipClientConnectionImpl.send()
        // when the initial request was sent. This is the reason why
        // Call-Id header is not added here.

        // Update the CSeq header. RFC 3261, p. 58:
        // A UA MUST increment the CSeq value by one for each
        // REGISTER request with the same Call-ID.
        CSeqHeader cseq = clonedRequest.getCSeqHeader();

        if (cseq != null) {
            cseq.setSequenceNumber(cseq.getSequenceNumber() + 1);
        } else {
            // log an error
            if (Logging.REPORT_LEVEL <= Logging.ERROR) {
                Logging.report(Logging.ERROR, LogChannels.LC_JSR180,
                               "RefreshTask.run(): The request doesn't " +
                               "contain CSeq header!");
            }
        }

        // ViaHeader
        clonedRequest.removeHeader(ViaHeader.NAME);

        Vector viaHeaders = new Vector();
        try {
            ViaHeader viaHeader = StackConnector
                                  .headerFactory
                                  .createViaHeader(
                                      sipConnectionNotifier.getLocalAddress(),
                                      sipConnectionNotifier.getLocalPort(),
                                      ((SipConnectionNotifierImpl)
                                       sipConnectionNotifier)
                                      .getSipProvider().getListeningPoint()
                                      .getTransport(),
                                      null);
            viaHeaders.addElement(viaHeader);
        } catch (ParseException ex) {
            if (Logging.REPORT_LEVEL <= Logging.WARNING) {
                Logging.report(Logging.WARNING, LogChannels.LC_JSR180,
                        "RefreshTask.run(): can't create Via header: " + ex);
            }
        } catch (IOException ioe) {
            if (Logging.REPORT_LEVEL <= Logging.WARNING) {
                Logging.report(Logging.WARNING, LogChannels.LC_JSR180,
                       "RefreshTask.run(): can't create Via header: " + ioe);
            }
        }

        try {
            clonedRequest.setVia(viaHeaders);
        } catch (SipException ex) {
            if (Logging.REPORT_LEVEL <= Logging.WARNING) {
                Logging.report(Logging.WARNING, LogChannels.LC_JSR180,
                       "RefreshTask.run(): can't set Via header: " + ex);
            }
        }
    
public synchronized voidupdateAndSendRequest(gov.nist.siplite.message.Request updatedRequest)
Updates the request in the sipClientConnection and sends it.

param
updatedRequest the updated request
throws
IOException if the message could not be sent or because of network failure
throws
InterruptedIOException if a timeout occurs while either trying to send the message or if this Connection object is closed during this send operation
throws
SipException INVALID_STATE if the message cannot be sent in this state.
INVALID_MESSAGE there was an error in message format

        request = updatedRequest;
        setRequestHeaders(request);
        ((SipClientConnectionImpl)sipClientConnection).
        updateAndSendRequestFromRefresh(request);
    
public synchronized java.io.OutputStreamupdateRequestAndOpenOutputStream(gov.nist.siplite.message.Request updatedRequest)
Updates the request in the sipClientConnection and calls SipClientConnection.openContentOutputStream() to fill the new message body content.

param
updatedRequest the updated request
return
OutputStream to write body content
throws
IOException if the OutputStream can not be opened, because of an I/O error occurred.
throws
SipException INVALID_STATE the OutputStream can not be opened in this state (e.g. no message initialized). UNKNOWN_LENGTH Content-Length header not set. UNKNOWN_TYPE Content-Type header not set.


        request = updatedRequest;
        setRequestHeaders(request);
        return ((SipClientConnectionImpl)sipClientConnection).
                    updateRequestAndOpenOutputStream(request);