NIST-SIP: The Reference Implementation for JAIN-SIP 1.2

gov.nist.javax.sip.stack
Class TCPMessageChannel

java.lang.Object
  extended by gov.nist.javax.sip.stack.MessageChannel
      extended by gov.nist.javax.sip.stack.TCPMessageChannel
All Implemented Interfaces:
ParseExceptionListener, SIPMessageListener, RawMessageChannel, Runnable

public class TCPMessageChannel
extends MessageChannel
implements SIPMessageListener, Runnable, RawMessageChannel

This is a stack abstraction for TCP connections. This abstracts a stream of parsed messages. The SIP sipStack starts this from the main SIPStack class for each connection that it accepts. It starts a message parser in its own thread and talks to the message parser via a pipe. The message parser calls back via the parseError or processMessage functions that are defined as part of the SIPMessageListener interface.

Version:
1.2 $Revision: 1.54 $ $Date: 2009/07/29 20:38:14 $
Author:
M. Ranganathan
See Also:
PipelinedMsgParser

Method Summary
 void close()
          Close the message channel.
 boolean equals(Object other)
          Equals predicate.
 String getKey()
          Get an identifying key.
 String getPeerAddress()
          get the address of the client that sent the data to us.
 InetAddress getPeerPacketSourceAddress()
           
 int getPeerPacketSourcePort()
           
 int getPeerPort()
          Get the port of the peer to whom we are sending messages.
 String getPeerProtocol()
           
 SIPTransactionStack getSIPStack()
          Get my SIP Stack.
 String getTransport()
          get the transport string.
 String getViaHost()
          Get the host to assign to outgoing messages.
 int getViaPort()
          Get the port for outgoing messages sent from the channel.
 void handleException(ParseException ex, SIPMessage sipMessage, Class hdrClass, String header, String message)
          Exception processor for exceptions detected from the parser.
 boolean isReliable()
          Returns "true" as this is a reliable transport.
 boolean isSecure()
          TCP Is not a secure protocol.
 void processMessage(SIPMessage sipMessage)
          Gets invoked by the parser as a callback on successful message parsing (i.e. no parser errors).
 void run()
          This gets invoked when thread.start is called from the constructor.
 void sendMessage(byte[] message, InetAddress receiverAddress, int receiverPort, boolean retry)
          Send a message to a specified address.
 void sendMessage(SIPMessage sipMessage)
          Return a formatted message to the client.
 
Methods inherited from class gov.nist.javax.sip.stack.MessageChannel
getHost, getHostPort, getKey, getKey, getMessageProcessor, getPeerHostPort, getPort, getRawIpSourceAddress, getViaHeader, getViaHostPort, logResponse, sendMessage, sendMessage
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isReliable

public boolean isReliable()
Returns "true" as this is a reliable transport.

Specified by:
isReliable in class MessageChannel
Returns:
True if reliable, false if not.

close

public void close()
Close the message channel.

Specified by:
close in class MessageChannel

getSIPStack

public SIPTransactionStack getSIPStack()
Get my SIP Stack.

Specified by:
getSIPStack in class MessageChannel
Returns:
The SIP Stack for this message channel.

getTransport

public String getTransport()
get the transport string.

Specified by:
getTransport in class MessageChannel
Returns:
"tcp" in this case.

getPeerAddress

public String getPeerAddress()
get the address of the client that sent the data to us.

Specified by:
getPeerAddress in class MessageChannel
Returns:
Address of the client that sent us data that resulted in this channel being created.

getPeerProtocol

public String getPeerProtocol()

sendMessage

public void sendMessage(SIPMessage sipMessage)
                 throws IOException
Return a formatted message to the client. We try to re-connect with the peer on the other end if possible.

Specified by:
sendMessage in class MessageChannel
Parameters:
sipMessage - Message to send.
Throws:
IOException - If there is an error sending the message

sendMessage

public void sendMessage(byte[] message,
                        InetAddress receiverAddress,
                        int receiverPort,
                        boolean retry)
                 throws IOException
Send a message to a specified address.

Parameters:
message - Pre-formatted message to send.
receiverAddress - Address to send it to.
receiverPort - Receiver port.
Throws:
IOException - If there is a problem connecting or sending.

handleException

public void handleException(ParseException ex,
                            SIPMessage sipMessage,
                            Class hdrClass,
                            String header,
                            String message)
                     throws ParseException
Exception processor for exceptions detected from the parser. (This is invoked by the parser when an error is detected).

Specified by:
handleException in interface ParseExceptionListener
Parameters:
sipMessage - -- the message that incurred the error.
ex - -- parse exception detected by the parser.
header - -- header that caused the error.
message - -- message where this header was detected.
Throws:
ParseException - Thrown if we want to reject the message.

processMessage

public void processMessage(SIPMessage sipMessage)
                    throws Exception
Gets invoked by the parser as a callback on successful message parsing (i.e. no parser errors).

Specified by:
processMessage in interface SIPMessageListener
Specified by:
processMessage in interface RawMessageChannel
Parameters:
sipMessage - Mesage to process (this calls the application for processing the message).
Throws:
Exception
See Also:
for the method that gets called on parse exception.

run

public void run()
This gets invoked when thread.start is called from the constructor. Implements a message loop - reading the tcp connection and processing messages until we are done or the other end has closed.

Specified by:
run in interface Runnable

equals

public boolean equals(Object other)
Equals predicate.

Overrides:
equals in class Object
Parameters:
other - is the other object to compare ourselves to for equals

getKey

public String getKey()
Get an identifying key. This key is used to cache the connection and re-use it if necessary.

Specified by:
getKey in class MessageChannel

getViaHost

public String getViaHost()
Get the host to assign to outgoing messages.

Specified by:
getViaHost in class MessageChannel
Returns:
the host to assign to the via header.

getViaPort

public int getViaPort()
Get the port for outgoing messages sent from the channel.

Specified by:
getViaPort in class MessageChannel
Returns:
the port to assign to the via header.

getPeerPort

public int getPeerPort()
Get the port of the peer to whom we are sending messages.

Specified by:
getPeerPort in class MessageChannel
Returns:
the peer port.

getPeerPacketSourcePort

public int getPeerPacketSourcePort()
Specified by:
getPeerPacketSourcePort in class MessageChannel

getPeerPacketSourceAddress

public InetAddress getPeerPacketSourceAddress()
Specified by:
getPeerPacketSourceAddress in class MessageChannel

isSecure

public boolean isSecure()
TCP Is not a secure protocol.

Specified by:
isSecure in class MessageChannel

NIST-SIP: The Reference Implementation for JAIN-SIP 1.2

A product of the NIST/ITL Advanced Networking Technologies Division.
See conditions of use.
Submit a bug report or feature request.