gov.nist.javax.sip.stack
Class ConnectionOrientedMessageChannel

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

public abstract class ConnectionOrientedMessageChannel
extends MessageChannel
implements SIPMessageListener, Runnable, RawMessageChannel

Author:
[email protected]

Field Summary
protected  boolean isCached
           
protected  boolean isRunning
           
protected  String key
           
protected  String myAddress
           
protected  InputStream myClientInputStream
           
protected  PipelinedMsgParser myParser
           
protected  int myPort
           
protected  Socket mySock
           
protected  Thread mythread
           
protected  InetAddress peerAddress
           
protected  int peerPort
           
protected  int peerPortAdvertisedInHeaders
           
protected  String peerProtocol
           
protected  SIPTransactionStack sipStack
           
 
Fields inherited from class gov.nist.javax.sip.stack.MessageChannel
messageProcessor, useCount
 
Constructor Summary
ConnectionOrientedMessageChannel(SIPTransactionStack sipStack)
           
 
Method Summary
 void cancelPingKeepAliveTimeoutTaskIfStarted()
           
 void close()
          Close the message channel.
protected abstract  void close(boolean b)
           
 long getKeepAliveTimeout()
           
 String getKey()
          Get an identifying key.
 String getPeerAddress()
          get the address of the client that sent the data to us.
protected  InetAddress getPeerInetAddress()
           
 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 getViaHost()
          Get the host to assign to outgoing messages.
 int getViaPort()
          Get the port for outgoing messages sent from the channel.
 boolean isReliable()
          Returns "true" as this is a reliable transport.
 void processMessage(SIPMessage sipMessage)
          Gets invoked by the parser as a callback on successful message parsing (i.e.
 void processMessage(SIPMessage sipMessage, InetAddress address)
           
 void rescheduleKeepAliveTimeout(long newKeepAliveTimeout)
           
 void run()
          This gets invoked when thread.start is called from the constructor.
protected abstract  void sendMessage(byte[] msg, boolean b)
           
 void sendMessage(SIPMessage sipMessage)
          Return a formatted message to the client.
 void sendSingleCLRF()
           
 void setKeepAliveTimeout(long keepAliveTimeout)
           
protected  void uncache()
          Hook method, overridden by subclasses
 
Methods inherited from class gov.nist.javax.sip.stack.MessageChannel
createBadReqRes, getEncapsulatedClientTransaction, getHost, getHostPort, getKey, getKey, getMessageProcessor, getPeerHostPort, getPort, getRawIpSourceAddress, getTransport, getViaHeader, getViaHostPort, isSecure, logMessage, logResponse, sendMessage, sendMessage, sendMessage, setEncapsulatedClientTransaction
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface gov.nist.javax.sip.parser.ParseExceptionListener
handleException
 

Field Detail

sipStack

protected SIPTransactionStack sipStack

mySock

protected Socket mySock

myParser

protected PipelinedMsgParser myParser

key

protected String key

myClientInputStream

protected InputStream myClientInputStream

isRunning

protected boolean isRunning

isCached

protected boolean isCached

mythread

protected Thread mythread

myAddress

protected String myAddress

myPort

protected int myPort

peerAddress

protected InetAddress peerAddress

peerPortAdvertisedInHeaders

protected int peerPortAdvertisedInHeaders

peerPort

protected int peerPort

peerProtocol

protected String peerProtocol
Constructor Detail

ConnectionOrientedMessageChannel

public ConnectionOrientedMessageChannel(SIPTransactionStack sipStack)
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

close

protected abstract void close(boolean b)

getSIPStack

public SIPTransactionStack getSIPStack()
Get my SIP Stack.

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

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.

getPeerInetAddress

protected InetAddress getPeerInetAddress()
Specified by:
getPeerInetAddress in class MessageChannel

getPeerProtocol

public String getPeerProtocol()
Specified by:
getPeerProtocol in class MessageChannel

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

protected abstract void sendMessage(byte[] msg,
                                    boolean b)
                             throws IOException
Throws:
IOException

processMessage

public void processMessage(SIPMessage sipMessage,
                           InetAddress address)

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 - Message to process (this calls the application for processing the message). Jvb: note that this code is identical to TCPMessageChannel, refactor some day
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

uncache

protected void uncache()
Description copied from class: MessageChannel
Hook method, overridden by subclasses

Overrides:
uncache in class MessageChannel

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

sendSingleCLRF

public void sendSingleCLRF()
                    throws Exception
Specified by:
sendSingleCLRF in interface SIPMessageListener
Throws:
Exception

cancelPingKeepAliveTimeoutTaskIfStarted

public void cancelPingKeepAliveTimeoutTaskIfStarted()

setKeepAliveTimeout

public void setKeepAliveTimeout(long keepAliveTimeout)

getKeepAliveTimeout

public long getKeepAliveTimeout()

rescheduleKeepAliveTimeout

public void rescheduleKeepAliveTimeout(long newKeepAliveTimeout)


Copyright © 2012. All Rights Reserved.