diff options
author | Damian Minkov <damencho@jitsi.org> | 2014-09-16 09:49:23 +0300 |
---|---|---|
committer | Damian Minkov <damencho@jitsi.org> | 2014-09-16 09:49:23 +0300 |
commit | d2b0603a5a12f0305a6899991f65fe92a6f2bfe4 (patch) | |
tree | 333c391faef6c80de562a08b1103fa49c27c5416 /src/net/java/sip/communicator | |
parent | f4eeaf5cecde782ec69e2d3bd0425c8d2d0c7eb0 (diff) | |
download | jitsi-d2b0603a5a12f0305a6899991f65fe92a6f2bfe4.zip jitsi-d2b0603a5a12f0305a6899991f65fe92a6f2bfe4.tar.gz jitsi-d2b0603a5a12f0305a6899991f65fe92a6f2bfe4.tar.bz2 |
Adds new unregister method to clearly distinguish between automatic unregister that comes from timeout(ping) timers, reconnect plugin and those coming from UI by user request.
Diffstat (limited to 'src/net/java/sip/communicator')
16 files changed, 200 insertions, 29 deletions
diff --git a/src/net/java/sip/communicator/impl/globaldisplaydetails/GlobalStatusServiceImpl.java b/src/net/java/sip/communicator/impl/globaldisplaydetails/GlobalStatusServiceImpl.java index a454dda..5b31a82 100644 --- a/src/net/java/sip/communicator/impl/globaldisplaydetails/GlobalStatusServiceImpl.java +++ b/src/net/java/sip/communicator/impl/globaldisplaydetails/GlobalStatusServiceImpl.java @@ -450,7 +450,7 @@ public class GlobalStatusServiceImpl try { - protocolProvider.unregister(); + protocolProvider.unregister(true); } catch (OperationFailedException e1) { diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolProviderServiceJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolProviderServiceJabberImpl.java index 3f185be..cee6093 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolProviderServiceJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolProviderServiceJabberImpl.java @@ -561,7 +561,7 @@ public class ProtocolProviderServiceJabberImpl // sets this if any is trying to use us through registration // to know we are not registered - this.unregister(false); + this.unregisterInternal(false); // reset states this.abortConnecting = false; @@ -1505,14 +1505,32 @@ public class ProtocolProviderServiceJabberImpl */ public void unregister() { - unregister(true); + unregisterInternal(true); + } + + /** + * Ends the registration of this protocol provider with the service. + * @param userRequest is the unregister by user request. + */ + public void unregister(boolean userRequest) + { + unregisterInternal(true, userRequest); + } + + /** + * Unregister and fire the event if requested + * @param fireEvent boolean + */ + public void unregisterInternal(boolean fireEvent) + { + unregisterInternal(fireEvent, false); } /** * Unregister and fire the event if requested * @param fireEvent boolean */ - public void unregister(boolean fireEvent) + public void unregisterInternal(boolean fireEvent, boolean userRequest) { synchronized(initializationLock) { @@ -1523,7 +1541,8 @@ public class ProtocolProviderServiceJabberImpl getRegistrationState() , RegistrationState.UNREGISTERING , RegistrationStateChangeEvent.REASON_NOT_SPECIFIED - , null); + , null + , userRequest); } disconnectAndCleanConnection(); @@ -1536,7 +1555,8 @@ public class ProtocolProviderServiceJabberImpl fireRegistrationStateChanged( currRegState, RegistrationState.UNREGISTERED, - RegistrationStateChangeEvent.REASON_USER_REQUEST, null); + RegistrationStateChangeEvent.REASON_USER_REQUEST, null, + userRequest); } } } diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/keepalive/KeepAliveManager.java b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/keepalive/KeepAliveManager.java index fdc5350..9a4bef0 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/keepalive/KeepAliveManager.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/keepalive/KeepAliveManager.java @@ -225,7 +225,7 @@ public class KeepAliveManager +"won't send keep alive for " + parentProvider.getAccountID().getDisplayName()); - parentProvider.unregister(false); + parentProvider.unregisterInternal(false); parentProvider.fireRegistrationStateChanged( parentProvider.getRegistrationState(), @@ -244,7 +244,7 @@ public class KeepAliveManager logger.error("un-registering not received ping packet " + "for: " + parentProvider.getAccountID().getDisplayName()); - parentProvider.unregister(false); + parentProvider.unregisterInternal(false); parentProvider.fireRegistrationStateChanged( parentProvider.getRegistrationState(), diff --git a/src/net/java/sip/communicator/impl/protocol/mock/MockProvider.java b/src/net/java/sip/communicator/impl/protocol/mock/MockProvider.java index dac258e..06f1d5d 100644 --- a/src/net/java/sip/communicator/impl/protocol/mock/MockProvider.java +++ b/src/net/java/sip/communicator/impl/protocol/mock/MockProvider.java @@ -241,6 +241,15 @@ public class MockProvider { } + /** + * Mock implementation of the corresponding ProtocolProviderService method. + */ + public void unregister(boolean userRequest) + throws OperationFailedException + { + this.unregister(); + } + /* * (non-Javadoc) * diff --git a/src/net/java/sip/communicator/impl/protocol/msn/EventManager.java b/src/net/java/sip/communicator/impl/protocol/msn/EventManager.java index e7ab7b5..646be8a 100644 --- a/src/net/java/sip/communicator/impl/protocol/msn/EventManager.java +++ b/src/net/java/sip/communicator/impl/protocol/msn/EventManager.java @@ -191,7 +191,7 @@ public class EventManager { if(!connected && msnProvider.isRegistered()) { - msnProvider.unregister(false); + msnProvider.unregisterInternal(false); msnProvider.fireRegistrationStateChanged( msnProvider.getRegistrationState(), RegistrationState.CONNECTION_FAILED, diff --git a/src/net/java/sip/communicator/impl/protocol/msn/ProtocolProviderServiceMsnImpl.java b/src/net/java/sip/communicator/impl/protocol/msn/ProtocolProviderServiceMsnImpl.java index 813fda9..9b8d1e9 100644 --- a/src/net/java/sip/communicator/impl/protocol/msn/ProtocolProviderServiceMsnImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/msn/ProtocolProviderServiceMsnImpl.java @@ -246,7 +246,7 @@ public class ProtocolProviderServiceMsnImpl */ public void unregister() { - unregister(true); + unregisterInternal(true); } /* @@ -275,7 +275,7 @@ public class ProtocolProviderServiceMsnImpl * Unregister and fire the event if requested * @param fireEvent boolean */ - void unregister(boolean fireEvent) + void unregisterInternal(boolean fireEvent) { RegistrationState currRegState = getRegistrationState(); @@ -393,7 +393,7 @@ public class ProtocolProviderServiceMsnImpl { synchronized(initializationLock) { - unregister(false); + unregisterInternal(false); messenger = null; } } @@ -479,7 +479,7 @@ public class ProtocolProviderServiceMsnImpl synchronized (initializationLock) { logoutReceived = true; - unregister(true); + unregisterInternal(true); } } @@ -493,7 +493,7 @@ public class ProtocolProviderServiceMsnImpl { if(throwable instanceof IncorrectPasswordException) { - unregister(false); + unregisterInternal(false); MsnActivator.getProtocolProviderFactory(). storePassword(getAccountID(), null); @@ -538,7 +538,7 @@ public class ProtocolProviderServiceMsnImpl case 601: if(isRegistered()) { - unregister(false); + unregisterInternal(false); fireRegistrationStateChanged( getRegistrationState(), RegistrationState.UNREGISTERED, @@ -549,7 +549,7 @@ public class ProtocolProviderServiceMsnImpl case 911: if(isRegistered()) { - unregister(false); + unregisterInternal(false); MsnActivator.getProtocolProviderFactory(). storePassword(getAccountID(), null); fireRegistrationStateChanged( diff --git a/src/net/java/sip/communicator/impl/protocol/msn/ServerStoredContactListMsnImpl.java b/src/net/java/sip/communicator/impl/protocol/msn/ServerStoredContactListMsnImpl.java index 59fe6f2..bbae5be 100644 --- a/src/net/java/sip/communicator/impl/protocol/msn/ServerStoredContactListMsnImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/msn/ServerStoredContactListMsnImpl.java @@ -1303,7 +1303,7 @@ public class ServerStoredContactListMsnImpl @Override public void loggingFromOtherLocation() { - msnProvider.unregister(false); + msnProvider.unregisterInternal(false); msnProvider.fireRegistrationStateChanged( msnProvider.getRegistrationState(), RegistrationState.UNREGISTERED, diff --git a/src/net/java/sip/communicator/impl/protocol/sip/ProtocolProviderServiceSipImpl.java b/src/net/java/sip/communicator/impl/protocol/sip/ProtocolProviderServiceSipImpl.java index 7877a7c..da36c7c 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/ProtocolProviderServiceSipImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/ProtocolProviderServiceSipImpl.java @@ -366,6 +366,20 @@ public class ProtocolProviderServiceSipImpl public void unregister() throws OperationFailedException { + unregister(false); + } + + /** + * Ends the registration of this protocol provider with the current + * registration service. + * + * @throws OperationFailedException with the corresponding code it the + * registration fails for some reason (e.g. a networking error or an + * implementation problem). + */ + public void unregister(boolean userRequest) + throws OperationFailedException + { if(getRegistrationState().equals(RegistrationState.UNREGISTERED) || getRegistrationState().equals(RegistrationState.UNREGISTERING) || getRegistrationState().equals(RegistrationState.CONNECTION_FAILED)) @@ -373,7 +387,7 @@ public class ProtocolProviderServiceSipImpl return; } - sipRegistrarConnection.unregister(); + sipRegistrarConnection.unregister(userRequest); sipSecurityManager.setSecurityAuthority(null); } diff --git a/src/net/java/sip/communicator/impl/protocol/sip/SipApplicationData.java b/src/net/java/sip/communicator/impl/protocol/sip/SipApplicationData.java index 27e48ad..f516ccc 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/SipApplicationData.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/SipApplicationData.java @@ -37,6 +37,11 @@ public class SipApplicationData public static final String KEY_SUBSCRIPTIONS = "subscriptions"; /** + * Key user request. + */ + public static final String KEY_USER_REQUEST = "userRequest"; + + /** * Logger for this class. */ private static final Logger logger diff --git a/src/net/java/sip/communicator/impl/protocol/sip/SipRegistrarConnection.java b/src/net/java/sip/communicator/impl/protocol/sip/SipRegistrarConnection.java index 145ef6d..7408dcd 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/SipRegistrarConnection.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/SipRegistrarConnection.java @@ -425,9 +425,18 @@ public class SipRegistrarConnection logger.debug("Account " + sipProvider.getAccountID().getDisplayName() + " unregistered!"); + + Boolean userRequest = (Boolean)SipApplicationData.getApplicationData( + register, SipApplicationData.KEY_USER_REQUEST); + + boolean userRequestBool = false; + if(userRequest != null && userRequest) + userRequestBool = true; + setRegistrationState(RegistrationState.UNREGISTERED , RegistrationStateChangeEvent.REASON_USER_REQUEST - , "Registration terminated."); + , "Registration terminated.", + userRequestBool); } else { @@ -518,7 +527,19 @@ public class SipRegistrarConnection */ public void unregister() throws OperationFailedException { - unregister(true); + unregisterInternal(true, false); + } + + /** + * Sends a unregistered request to the registrar thus ending our + * registration. + * @throws OperationFailedException with the corresponding code if sending + * or constructing the request fails. + */ + public void unregister(boolean userRequest) + throws OperationFailedException + { + unregisterInternal(true, userRequest); } /** @@ -531,7 +552,7 @@ public class SipRegistrarConnection * @throws OperationFailedException with the corresponding code if sending * or constructing the request fails. */ - private void unregister(boolean sendUnregister) + private void unregisterInternal(boolean sendUnregister, boolean userRequest) throws OperationFailedException { if (getRegistrationState() == RegistrationState.UNREGISTERED) @@ -581,6 +602,12 @@ public class SipRegistrarConnection , ex); } + if(userRequest) + { + SipApplicationData.setApplicationData(unregisterRequest, + SipApplicationData.KEY_USER_REQUEST, userRequest); + } + ClientTransaction unregisterTransaction = null; try { @@ -670,6 +697,24 @@ public class SipRegistrarConnection int reasonCode, String reason) { + this.setRegistrationState(newState, reasonCode, reason, false); + } + + /** + * Sets our registration state to <tt>newState</tt> and dispatches an event + * through the protocol provider service impl. + * <p> + * @param newState a reference to the RegistrationState that we're currently + * detaining. + * @param reasonCode one of the REASON_XXX error codes specified in + * {@link RegistrationStateChangeEvent}. + * @param reason a reason String further explaining the reasonCode. + */ + public void setRegistrationState(RegistrationState newState, + int reasonCode, + String reason, + boolean userRequest) + { if( currentRegistrationState.equals(newState) ) return; @@ -677,7 +722,7 @@ public class SipRegistrarConnection this.currentRegistrationState = newState; sipProvider.fireRegistrationStateChanged( - oldState, newState, reasonCode, reason); + oldState, newState, reasonCode, reason, userRequest); } /** diff --git a/src/net/java/sip/communicator/impl/protocol/yahoo/ProtocolProviderServiceYahooImpl.java b/src/net/java/sip/communicator/impl/protocol/yahoo/ProtocolProviderServiceYahooImpl.java index 417e5be..7bf9fc4 100644 --- a/src/net/java/sip/communicator/impl/protocol/yahoo/ProtocolProviderServiceYahooImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/yahoo/ProtocolProviderServiceYahooImpl.java @@ -289,14 +289,14 @@ public class ProtocolProviderServiceYahooImpl */ public void unregister() { - unregister(true); + unregisterInternal(true); } /** * Unregister and fire the event if requested * @param fireEvent boolean */ - void unregister(boolean fireEvent) + void unregisterInternal(boolean fireEvent) { RegistrationState currRegState = getRegistrationState(); @@ -437,7 +437,7 @@ public class ProtocolProviderServiceYahooImpl public void shutdown() { synchronized(initializationLock){ - unregister(false); + unregisterInternal(false); yahooSession = null; isInitialized = false; } @@ -496,7 +496,7 @@ public class ProtocolProviderServiceYahooImpl { if(newState.equals(RegistrationState.UNREGISTERED)) { - unregister(false); + unregisterInternal(false); yahooSession = null; } @@ -543,7 +543,7 @@ public class ProtocolProviderServiceYahooImpl logger.error( "Yahoo protocol exception occured", ev.getException()); - unregister(false); + unregisterInternal(false); if(isRegistered()) fireRegistrationStateChanged( getRegistrationState(), diff --git a/src/net/java/sip/communicator/plugin/reconnectplugin/ReconnectPluginActivator.java b/src/net/java/sip/communicator/plugin/reconnectplugin/ReconnectPluginActivator.java index 1ce59da..8e63cdb 100644 --- a/src/net/java/sip/communicator/plugin/reconnectplugin/ReconnectPluginActivator.java +++ b/src/net/java/sip/communicator/plugin/reconnectplugin/ReconnectPluginActivator.java @@ -775,7 +775,10 @@ public class ReconnectPluginActivator } else if(evt.getNewState().equals(RegistrationState.UNREGISTERED)) { - autoReconnEnabledProviders.remove(pp); + // Removes from list of autoreconnect only if the unregister + // event is by user request + if(evt.isUserRequest()) + autoReconnEnabledProviders.remove(pp); if(!unregisteringProviders.contains(pp) && currentlyReconnecting.containsKey(pp)) diff --git a/src/net/java/sip/communicator/service/protocol/AbstractProtocolProviderService.java b/src/net/java/sip/communicator/service/protocol/AbstractProtocolProviderService.java index 7053d67..9218028 100644 --- a/src/net/java/sip/communicator/service/protocol/AbstractProtocolProviderService.java +++ b/src/net/java/sip/communicator/service/protocol/AbstractProtocolProviderService.java @@ -127,9 +127,34 @@ public abstract class AbstractProtocolProviderService int reasonCode, String reason) { + this.fireRegistrationStateChanged( + oldState, newState, reasonCode, reason, false); + } + + /** + * Creates a RegistrationStateChange event corresponding to the specified + * old and new states and notifies all currently registered listeners. + * + * @param oldState the state that the provider had before the change + * occurred + * @param newState the state that the provider is currently in. + * @param reasonCode a value corresponding to one of the REASON_XXX fields + * of the RegistrationStateChangeEvent class, indicating the reason for + * this state transition. + * @param reason a String further explaining the reason code or null if + * no such explanation is necessary. + * @param userRequest is the event by user request. + */ + public void fireRegistrationStateChanged( RegistrationState oldState, + RegistrationState newState, + int reasonCode, + String reason, + boolean userRequest) + { RegistrationStateChangeEvent event = new RegistrationStateChangeEvent( this, oldState, newState, reasonCode, reason); + event.setUserRequest(userRequest); RegistrationStateChangeListener[] listeners; synchronized (registrationListeners) @@ -316,4 +341,20 @@ public abstract class AbstractProtocolProviderService return getClass().getSimpleName() + "(" + getAccountID().getDisplayName() + ")"; } + + /** + * Ends the registration of this protocol provider with the current + * registration service. The default is just to call unregister. Providers + * that need to differentiate user requests (from the UI) or automatic + * unregister can override this method. + * @param userRequest is the unregister by user request. + * @throws OperationFailedException with the corresponding code it the + * registration fails for some reason (e.g. a networking error or an + * implementation problem). + */ + public void unregister(boolean userRequest) + throws OperationFailedException + { + this.unregister(); + } } diff --git a/src/net/java/sip/communicator/service/protocol/ProtocolProviderService.java b/src/net/java/sip/communicator/service/protocol/ProtocolProviderService.java index 5bd182b..58594f6 100644 --- a/src/net/java/sip/communicator/service/protocol/ProtocolProviderService.java +++ b/src/net/java/sip/communicator/service/protocol/ProtocolProviderService.java @@ -75,6 +75,17 @@ public interface ProtocolProviderService throws OperationFailedException; /** + * Ends the registration of this protocol provider with the current + * registration service. + * @param userRequest is the unregister by user request. + * @throws OperationFailedException with the corresponding code it the + * registration fails for some reason (e.g. a networking error or an + * implementation problem). + */ + public void unregister(boolean userRequest) + throws OperationFailedException; + + /** * Indicates whether or not this provider is registered * @return true if the provider is currently registered and false otherwise. */ diff --git a/src/net/java/sip/communicator/service/protocol/event/RegistrationStateChangeEvent.java b/src/net/java/sip/communicator/service/protocol/event/RegistrationStateChangeEvent.java index dc1cb20..6df601e 100644 --- a/src/net/java/sip/communicator/service/protocol/event/RegistrationStateChangeEvent.java +++ b/src/net/java/sip/communicator/service/protocol/event/RegistrationStateChangeEvent.java @@ -111,6 +111,11 @@ public class RegistrationStateChangeEvent extends PropertyChangeEvent private final String reason; /** + * Whether this event is after user request. + */ + private boolean userRequest = false; + + /** * Creates an event instance indicating a change of the provider state * from <tt>oldValue</tt> to <tt>newValue</tt>. * @@ -211,4 +216,22 @@ public class RegistrationStateChangeEvent extends PropertyChangeEvent { return reason; } + + /** + * Whether this event is after user request. + * @return whether this event is after user request. + */ + public boolean isUserRequest() + { + return userRequest; + } + + /** + * Changes the event to indicate that is created after use request. + * @param userRequest + */ + public void setUserRequest(boolean userRequest) + { + this.userRequest = userRequest; + } } diff --git a/src/net/java/sip/communicator/util/account/LoginManager.java b/src/net/java/sip/communicator/util/account/LoginManager.java index aea9b6c..a2ad413 100644 --- a/src/net/java/sip/communicator/util/account/LoginManager.java +++ b/src/net/java/sip/communicator/util/account/LoginManager.java @@ -547,7 +547,7 @@ public class LoginManager {
try
{
- protocolProvider.unregister();
+ protocolProvider.unregister(true);
}
catch (OperationFailedException ex)
{
|