Moves RegistrationStateChangeListener to ProtocolProviderServiceSipImpl.

For readability, it makes sense to have the class
(ProtocolProviderServiceSipImpl) calling
SipStackSharing.addSipListener(listener) also call
SipStackSharing.removeSipListener(listener).
cusax-fix
Sebastien Mazy 17 years ago
parent e59382cc0b
commit 6c7e563e5c

@ -39,7 +39,8 @@
*/
public class ProtocolProviderServiceSipImpl
extends AbstractProtocolProviderService
implements SipListener
implements SipListener,
RegistrationStateChangeListener
{
private static final Logger logger =
Logger.getLogger(ProtocolProviderServiceSipImpl.class);
@ -290,6 +291,9 @@ public void register(SecurityAuthority authority)
}
sipStackSharing.addSipListener(this);
// be warned when we will unregister, so that we can
// then remove us as SipListener
this.addRegistrationStateChangeListener(this);
// Enable the user name modification. Setting this property to true we'll
// allow the user to change the user name stored in the given authority.
@ -2292,4 +2296,21 @@ private InetAddress getIntendedDestination(String host)
return destinationInetAddress;
}
/**
* Stops dispatching SIP messages to a SIP protocol provider service
* once it's been unregistered.
*
* @param event the change event in the registration state of a provider.
*/
public void registrationStateChanged(RegistrationStateChangeEvent event)
{
if(event.getNewState() == RegistrationState.UNREGISTERED)
{
ProtocolProviderServiceSipImpl listener
= (ProtocolProviderServiceSipImpl) event.getProvider();
this.sipStackSharing.removeSipListener(listener);
listener.removeRegistrationStateChangeListener(this);
}
}
}

@ -33,8 +33,7 @@
* @author Sebastien Mazy
*/
public class SipStackSharing
implements SipListener,
RegistrationStateChangeListener
implements SipListener
{
/**
* Logger for this class.
@ -127,7 +126,6 @@ public void addSipListener(ProtocolProviderServiceSipImpl listener)
if(this.listeners.size() == 0)
startListening();
this.listeners.add(listener);
listener.addRegistrationStateChangeListener(this);
logger.trace(this.listeners.size() + " listeners now");
}
}
@ -139,7 +137,7 @@ public void addSipListener(ProtocolProviderServiceSipImpl listener)
*
* @param listener possible target to remove for the dispatching process.
*/
private void removeSipListener(ProtocolProviderServiceSipImpl listener)
public void removeSipListener(ProtocolProviderServiceSipImpl listener)
{
synchronized(this.listeners)
{
@ -165,23 +163,6 @@ private Set<ProtocolProviderServiceSipImpl> getSipListeners()
}
}
/**
* Stops dispatching SIP messages to a SIP protocol provider service
* once it's been unregistered.
*
* @param event the change event in the registration state of a provider.
*/
public void registrationStateChanged(RegistrationStateChangeEvent event)
{
if(event.getNewState() == RegistrationState.UNREGISTERED)
{
ProtocolProviderServiceSipImpl listener
= (ProtocolProviderServiceSipImpl) event.getProvider();
this.removeSipListener(listener);
listener.removeRegistrationStateChangeListener(this);
}
}
/**
* Returns the JAIN-SIP <tt>ListeningPoint</tt> associated to the given
* transport string.

Loading…
Cancel
Save