Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.protocol.sip
Class SipStackSharing

java.lang.Object
  extended by net.java.sip.communicator.impl.protocol.sip.SipStackSharing
All Implemented Interfaces:
EventListener, javax.sip.SipListener, NetworkConfigurationChangeListener

public class SipStackSharing
extends Object
implements javax.sip.SipListener, NetworkConfigurationChangeListener

This class is the SipListener for all JAIN-SIP SipProviders. It is in charge of dispatching the received messages to the suitable ProtocolProviderServiceSipImpls registered with addSipListener. It also contains the JAIN-SIP pieces which are common between all ProtocolProviderServiceSipImpls (namely 1 SipStack, 2 SipProviders, 3 ListeningPoints).

Author:
Emil Ivov, Lubomir Marinov, Alan Kelly, Sebastien Mazy

Field Summary
static String CONTACT_ADDRESS_CUSTOM_PARAM_NAME
          We set a custom parameter in the contact address for registrar accounts, so as to ease dispatching of incoming requests in case several accounts have the same username in their contact address, eg: sip:username@192.168.0.1:5060;transport=udp;registering_acc=example_com
(package private)  Map<String,TimerTask> resetListeningPointsTimers
          List of currently waiting timers that will monitor the protocol provider
 
Constructor Summary
SipStackSharing()
          Constructor for this class.
 
Method Summary
 void addSipListener(ProtocolProviderServiceSipImpl listener)
          Adds this listener as a candidate recipient for the dispatching of new messages received from the JAIN-SIP SipProviders.
 void configurationChanged(ChangeEvent event)
          Listens for network changes and if we have a down interface and we have a tcp/tls provider which is staying for 20 seconds in unregistering state, it cannot unregister cause its using the old address which is currently down, and we must recreate its listening points so it can further reconnect.
 javax.sip.SipProvider getJainSipProvider(String transport)
          Returns the JAIN-SIP SipProvider in charge of this transport.
 InetSocketAddress getLocalAddressForDestination(InetAddress dst, int dstPort, InetAddress localAddress, String transport)
          Returns a local address to use with the specified TCP destination.
 javax.sip.ListeningPoint getLP(String transport)
          Returns the JAIN-SIP ListeningPoint associated to the given transport string.
static javax.sip.ServerTransaction getOrCreateServerTransaction(javax.sip.RequestEvent event)
          Safely returns the transaction from the event if already exists.
 void processDialogTerminated(javax.sip.DialogTerminatedEvent event)
          Dispatches the event received from a JAIN-SIP SipProvider to one of our "candidate recipient" listeners.
 void processIOException(javax.sip.IOExceptionEvent event)
          Dispatches the event received from a JAIN-SIP SipProvider to one of our "candidate recipient" listeners.
 void processRequest(javax.sip.RequestEvent event)
          Dispatches the event received from a JAIN-SIP SipProvider to one of our "candidate recipient" listeners.
 void processResponse(javax.sip.ResponseEvent event)
          Dispatches the event received from a JAIN-SIP SipProvider to one of our "candidate recipient" listeners.
 void processTimeout(javax.sip.TimeoutEvent event)
          Dispatches the event received from a JAIN-SIP SipProvider to one of our "candidate recipient" listeners.
 void processTransactionTerminated(javax.sip.TransactionTerminatedEvent event)
          Dispatches the event received from a JAIN-SIP SipProvider to one of our "candidate recipient" listeners.
 void removeSipListener(ProtocolProviderServiceSipImpl listener)
          This listener will no longer be a candidate recipient for the dispatching of new messages received from the JAIN-SIP SipProviders.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONTACT_ADDRESS_CUSTOM_PARAM_NAME

public static final String CONTACT_ADDRESS_CUSTOM_PARAM_NAME
We set a custom parameter in the contact address for registrar accounts, so as to ease dispatching of incoming requests in case several accounts have the same username in their contact address, eg: sip:username@192.168.0.1:5060;transport=udp;registering_acc=example_com

See Also:
Constant Field Values

resetListeningPointsTimers

Map<String,TimerTask> resetListeningPointsTimers
List of currently waiting timers that will monitor the protocol provider

Constructor Detail

SipStackSharing

SipStackSharing()
          throws OperationFailedException
Constructor for this class. Creates the JAIN-SIP stack.

Throws:
OperationFailedException - if creating the stack fails.
Method Detail

addSipListener

public void addSipListener(ProtocolProviderServiceSipImpl listener)
                    throws OperationFailedException
Adds this listener as a candidate recipient for the dispatching of new messages received from the JAIN-SIP SipProviders.

Parameters:
listener - a new possible target for the dispatching process.
Throws:
OperationFailedException - if creating one of the underlying SipProviders fails for whatever reason.

removeSipListener

public void removeSipListener(ProtocolProviderServiceSipImpl listener)
This listener will no longer be a candidate recipient for the dispatching of new messages received from the JAIN-SIP SipProviders.

Parameters:
listener - possible target to remove for the dispatching process.

getLP

public javax.sip.ListeningPoint getLP(String transport)
Returns the JAIN-SIP ListeningPoint associated to the given transport string.

Parameters:
transport - a string like "UDP", "TCP" or "TLS".
Returns:
the LP associated to the given transport.

getJainSipProvider

public javax.sip.SipProvider getJainSipProvider(String transport)
Returns the JAIN-SIP SipProvider in charge of this transport.

Parameters:
transport - a String like "TCP", "UDP" or "TLS"
Returns:
the corresponding SipProvider

processDialogTerminated

public void processDialogTerminated(javax.sip.DialogTerminatedEvent event)
Dispatches the event received from a JAIN-SIP SipProvider to one of our "candidate recipient" listeners.

Specified by:
processDialogTerminated in interface javax.sip.SipListener
Parameters:
event - the event received for a SipProvider.

processIOException

public void processIOException(javax.sip.IOExceptionEvent event)
Dispatches the event received from a JAIN-SIP SipProvider to one of our "candidate recipient" listeners.

Specified by:
processIOException in interface javax.sip.SipListener
Parameters:
event - the event received for a SipProvider.

processRequest

public void processRequest(javax.sip.RequestEvent event)
Dispatches the event received from a JAIN-SIP SipProvider to one of our "candidate recipient" listeners.

Specified by:
processRequest in interface javax.sip.SipListener
Parameters:
event - the event received for a SipProvider.

processResponse

public void processResponse(javax.sip.ResponseEvent event)
Dispatches the event received from a JAIN-SIP SipProvider to one of our "candidate recipient" listeners.

Specified by:
processResponse in interface javax.sip.SipListener
Parameters:
event - the event received for a SipProvider.

processTimeout

public void processTimeout(javax.sip.TimeoutEvent event)
Dispatches the event received from a JAIN-SIP SipProvider to one of our "candidate recipient" listeners.

Specified by:
processTimeout in interface javax.sip.SipListener
Parameters:
event - the event received for a SipProvider.

processTransactionTerminated

public void processTransactionTerminated(javax.sip.TransactionTerminatedEvent event)
Dispatches the event received from a JAIN-SIP SipProvider to one of our "candidate recipient" listeners.

Specified by:
processTransactionTerminated in interface javax.sip.SipListener
Parameters:
event - the event received for a SipProvider.

getOrCreateServerTransaction

public static javax.sip.ServerTransaction getOrCreateServerTransaction(javax.sip.RequestEvent event)
                                                                throws javax.sip.TransactionAlreadyExistsException,
                                                                       javax.sip.TransactionUnavailableException
Safely returns the transaction from the event if already exists. If not a new transaction is created.

Parameters:
event - the request event
Returns:
the server transaction
Throws:
javax.sip.TransactionAlreadyExistsException - if transaction exists
javax.sip.TransactionUnavailableException - if unavailable

getLocalAddressForDestination

public InetSocketAddress getLocalAddressForDestination(InetAddress dst,
                                                       int dstPort,
                                                       InetAddress localAddress,
                                                       String transport)
                                                throws IOException
Returns a local address to use with the specified TCP destination. The method forces the JAIN-SIP stack to create s and binds (if necessary) and return a socket connected to the specified destination address and port and then return its local address.

Parameters:
dst - the destination address that the socket would need to connect to.
dstPort - the port number that the connection would be established with.
localAddress - the address that we would like to bind on (null for the "any" address).
transport - the transport that will be used TCP ot TLS
Returns:
the SocketAddress that this handler would use when connecting to the specified destination address and port.
Throws:
IOException - if we fail binding the local socket

configurationChanged

public void configurationChanged(ChangeEvent event)
Listens for network changes and if we have a down interface and we have a tcp/tls provider which is staying for 20 seconds in unregistering state, it cannot unregister cause its using the old address which is currently down, and we must recreate its listening points so it can further reconnect.

Specified by:
configurationChanged in interface NetworkConfigurationChangeListener
Parameters:
event - the change event.

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under LGPL license.