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.

cefexperiments 5299
Damian Minkov 11 years ago
parent f4eeaf5cec
commit d2b0603a5a

@ -450,7 +450,7 @@ else if (itemName.equals(GlobalStatusEnum.OFFLINE_STATUS))
try try
{ {
protocolProvider.unregister(); protocolProvider.unregister(true);
} }
catch (OperationFailedException e1) catch (OperationFailedException e1)
{ {

@ -561,7 +561,7 @@ void reregister(int authReasonCode)
// sets this if any is trying to use us through registration // sets this if any is trying to use us through registration
// to know we are not registered // to know we are not registered
this.unregister(false); this.unregisterInternal(false);
// reset states // reset states
this.abortConnecting = false; this.abortConnecting = false;
@ -1505,14 +1505,32 @@ public void disconnectAndCleanConnection()
*/ */
public void unregister() 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 * Unregister and fire the event if requested
* @param fireEvent boolean * @param fireEvent boolean
*/ */
public void unregister(boolean fireEvent) public void unregisterInternal(boolean fireEvent, boolean userRequest)
{ {
synchronized(initializationLock) synchronized(initializationLock)
{ {
@ -1523,7 +1541,8 @@ public void unregister(boolean fireEvent)
getRegistrationState() getRegistrationState()
, RegistrationState.UNREGISTERING , RegistrationState.UNREGISTERING
, RegistrationStateChangeEvent.REASON_NOT_SPECIFIED , RegistrationStateChangeEvent.REASON_NOT_SPECIFIED
, null); , null
, userRequest);
} }
disconnectAndCleanConnection(); disconnectAndCleanConnection();
@ -1536,7 +1555,8 @@ public void unregister(boolean fireEvent)
fireRegistrationStateChanged( fireRegistrationStateChanged(
currRegState, currRegState,
RegistrationState.UNREGISTERED, RegistrationState.UNREGISTERED,
RegistrationStateChangeEvent.REASON_USER_REQUEST, null); RegistrationStateChangeEvent.REASON_USER_REQUEST, null,
userRequest);
} }
} }
} }

@ -225,7 +225,7 @@ public void run()
+"won't send keep alive for " +"won't send keep alive for "
+ parentProvider.getAccountID().getDisplayName()); + parentProvider.getAccountID().getDisplayName());
parentProvider.unregister(false); parentProvider.unregisterInternal(false);
parentProvider.fireRegistrationStateChanged( parentProvider.fireRegistrationStateChanged(
parentProvider.getRegistrationState(), parentProvider.getRegistrationState(),
@ -244,7 +244,7 @@ public void run()
logger.error("un-registering not received ping packet " + logger.error("un-registering not received ping packet " +
"for: " + parentProvider.getAccountID().getDisplayName()); "for: " + parentProvider.getAccountID().getDisplayName());
parentProvider.unregister(false); parentProvider.unregisterInternal(false);
parentProvider.fireRegistrationStateChanged( parentProvider.fireRegistrationStateChanged(
parentProvider.getRegistrationState(), parentProvider.getRegistrationState(),

@ -241,6 +241,15 @@ public void unregister()
{ {
} }
/**
* Mock implementation of the corresponding ProtocolProviderService method.
*/
public void unregister(boolean userRequest)
throws OperationFailedException
{
this.unregister();
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *

@ -191,7 +191,7 @@ public void run()
{ {
if(!connected && msnProvider.isRegistered()) if(!connected && msnProvider.isRegistered())
{ {
msnProvider.unregister(false); msnProvider.unregisterInternal(false);
msnProvider.fireRegistrationStateChanged( msnProvider.fireRegistrationStateChanged(
msnProvider.getRegistrationState(), msnProvider.getRegistrationState(),
RegistrationState.CONNECTION_FAILED, RegistrationState.CONNECTION_FAILED,

@ -246,7 +246,7 @@ private void connectAndLogin(SecurityAuthority authority, int reasonCode)
*/ */
public void unregister() public void unregister()
{ {
unregister(true); unregisterInternal(true);
} }
/* /*
@ -275,7 +275,7 @@ public TransportProtocol getTransportProtocol()
* Unregister and fire the event if requested * Unregister and fire the event if requested
* @param fireEvent boolean * @param fireEvent boolean
*/ */
void unregister(boolean fireEvent) void unregisterInternal(boolean fireEvent)
{ {
RegistrationState currRegState = getRegistrationState(); RegistrationState currRegState = getRegistrationState();
@ -393,7 +393,7 @@ public void shutdown()
{ {
synchronized(initializationLock) synchronized(initializationLock)
{ {
unregister(false); unregisterInternal(false);
messenger = null; messenger = null;
} }
} }
@ -479,7 +479,7 @@ public void logout(MsnMessenger msnMessenger)
synchronized (initializationLock) synchronized (initializationLock)
{ {
logoutReceived = true; logoutReceived = true;
unregister(true); unregisterInternal(true);
} }
} }
@ -493,7 +493,7 @@ public void exceptionCaught(MsnMessenger msnMessenger,
{ {
if(throwable instanceof IncorrectPasswordException) if(throwable instanceof IncorrectPasswordException)
{ {
unregister(false); unregisterInternal(false);
MsnActivator.getProtocolProviderFactory(). MsnActivator.getProtocolProviderFactory().
storePassword(getAccountID(), null); storePassword(getAccountID(), null);
@ -538,7 +538,7 @@ else if(throwable instanceof MsnProtocolException)
case 601: case 601:
if(isRegistered()) if(isRegistered())
{ {
unregister(false); unregisterInternal(false);
fireRegistrationStateChanged( fireRegistrationStateChanged(
getRegistrationState(), getRegistrationState(),
RegistrationState.UNREGISTERED, RegistrationState.UNREGISTERED,
@ -549,7 +549,7 @@ else if(throwable instanceof MsnProtocolException)
case 911: case 911:
if(isRegistered()) if(isRegistered())
{ {
unregister(false); unregisterInternal(false);
MsnActivator.getProtocolProviderFactory(). MsnActivator.getProtocolProviderFactory().
storePassword(getAccountID(), null); storePassword(getAccountID(), null);
fireRegistrationStateChanged( fireRegistrationStateChanged(

@ -1303,7 +1303,7 @@ public void groupRenamed(MsnGroup group)
@Override @Override
public void loggingFromOtherLocation() public void loggingFromOtherLocation()
{ {
msnProvider.unregister(false); msnProvider.unregisterInternal(false);
msnProvider.fireRegistrationStateChanged( msnProvider.fireRegistrationStateChanged(
msnProvider.getRegistrationState(), msnProvider.getRegistrationState(),
RegistrationState.UNREGISTERED, RegistrationState.UNREGISTERED,

@ -365,6 +365,20 @@ public void register(SecurityAuthority authority)
*/ */
public void unregister() public void unregister()
throws OperationFailedException 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) if(getRegistrationState().equals(RegistrationState.UNREGISTERED)
|| getRegistrationState().equals(RegistrationState.UNREGISTERING) || getRegistrationState().equals(RegistrationState.UNREGISTERING)
@ -373,7 +387,7 @@ public void unregister()
return; return;
} }
sipRegistrarConnection.unregister(); sipRegistrarConnection.unregister(userRequest);
sipSecurityManager.setSecurityAuthority(null); sipSecurityManager.setSecurityAuthority(null);
} }

@ -36,6 +36,11 @@ public class SipApplicationData
*/ */
public static final String KEY_SUBSCRIPTIONS = "subscriptions"; public static final String KEY_SUBSCRIPTIONS = "subscriptions";
/**
* Key user request.
*/
public static final String KEY_USER_REQUEST = "userRequest";
/** /**
* Logger for this class. * Logger for this class.
*/ */

@ -425,9 +425,18 @@ public void processOK(ClientTransaction clientTransatcion,
logger.debug("Account " logger.debug("Account "
+ sipProvider.getAccountID().getDisplayName() + sipProvider.getAccountID().getDisplayName()
+ " unregistered!"); + " unregistered!");
Boolean userRequest = (Boolean)SipApplicationData.getApplicationData(
register, SipApplicationData.KEY_USER_REQUEST);
boolean userRequestBool = false;
if(userRequest != null && userRequest)
userRequestBool = true;
setRegistrationState(RegistrationState.UNREGISTERED setRegistrationState(RegistrationState.UNREGISTERED
, RegistrationStateChangeEvent.REASON_USER_REQUEST , RegistrationStateChangeEvent.REASON_USER_REQUEST
, "Registration terminated."); , "Registration terminated.",
userRequestBool);
} }
else else
{ {
@ -518,7 +527,19 @@ public boolean isRequestFromSameConnection(Request request)
*/ */
public void unregister() throws OperationFailedException 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 void unregister() throws OperationFailedException
* @throws OperationFailedException with the corresponding code if sending * @throws OperationFailedException with the corresponding code if sending
* or constructing the request fails. * or constructing the request fails.
*/ */
private void unregister(boolean sendUnregister) private void unregisterInternal(boolean sendUnregister, boolean userRequest)
throws OperationFailedException throws OperationFailedException
{ {
if (getRegistrationState() == RegistrationState.UNREGISTERED) if (getRegistrationState() == RegistrationState.UNREGISTERED)
@ -581,6 +602,12 @@ private void unregister(boolean sendUnregister)
, ex); , ex);
} }
if(userRequest)
{
SipApplicationData.setApplicationData(unregisterRequest,
SipApplicationData.KEY_USER_REQUEST, userRequest);
}
ClientTransaction unregisterTransaction = null; ClientTransaction unregisterTransaction = null;
try try
{ {
@ -669,6 +696,24 @@ public RegistrationState getRegistrationState()
public void setRegistrationState(RegistrationState newState, public void setRegistrationState(RegistrationState newState,
int reasonCode, int reasonCode,
String reason) 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) ) if( currentRegistrationState.equals(newState) )
return; return;
@ -677,7 +722,7 @@ public void setRegistrationState(RegistrationState newState,
this.currentRegistrationState = newState; this.currentRegistrationState = newState;
sipProvider.fireRegistrationStateChanged( sipProvider.fireRegistrationStateChanged(
oldState, newState, reasonCode, reason); oldState, newState, reasonCode, reason, userRequest);
} }
/** /**

@ -289,14 +289,14 @@ void reregister(int reasonCode)
*/ */
public void unregister() public void unregister()
{ {
unregister(true); unregisterInternal(true);
} }
/** /**
* Unregister and fire the event if requested * Unregister and fire the event if requested
* @param fireEvent boolean * @param fireEvent boolean
*/ */
void unregister(boolean fireEvent) void unregisterInternal(boolean fireEvent)
{ {
RegistrationState currRegState = getRegistrationState(); RegistrationState currRegState = getRegistrationState();
@ -437,7 +437,7 @@ protected void initialize(String screenname,
public void shutdown() public void shutdown()
{ {
synchronized(initializationLock){ synchronized(initializationLock){
unregister(false); unregisterInternal(false);
yahooSession = null; yahooSession = null;
isInitialized = false; isInitialized = false;
} }
@ -496,7 +496,7 @@ public void fireRegistrationStateChanged( RegistrationState oldState,
{ {
if(newState.equals(RegistrationState.UNREGISTERED)) if(newState.equals(RegistrationState.UNREGISTERED))
{ {
unregister(false); unregisterInternal(false);
yahooSession = null; yahooSession = null;
} }
@ -543,7 +543,7 @@ public void inputExceptionThrown(SessionExceptionEvent ev)
logger.error( logger.error(
"Yahoo protocol exception occured", ev.getException()); "Yahoo protocol exception occured", ev.getException());
unregister(false); unregisterInternal(false);
if(isRegistered()) if(isRegistered())
fireRegistrationStateChanged( fireRegistrationStateChanged(
getRegistrationState(), getRegistrationState(),

@ -775,7 +775,10 @@ else if(evt.getNewState().equals(RegistrationState.REGISTERED))
} }
else if(evt.getNewState().equals(RegistrationState.UNREGISTERED)) 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) if(!unregisteringProviders.contains(pp)
&& currentlyReconnecting.containsKey(pp)) && currentlyReconnecting.containsKey(pp))

@ -126,10 +126,35 @@ public void fireRegistrationStateChanged( RegistrationState oldState,
RegistrationState newState, RegistrationState newState,
int reasonCode, int reasonCode,
String reason) 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 = RegistrationStateChangeEvent event =
new RegistrationStateChangeEvent( new RegistrationStateChangeEvent(
this, oldState, newState, reasonCode, reason); this, oldState, newState, reasonCode, reason);
event.setUserRequest(userRequest);
RegistrationStateChangeListener[] listeners; RegistrationStateChangeListener[] listeners;
synchronized (registrationListeners) synchronized (registrationListeners)
@ -316,4 +341,20 @@ public String toString()
return getClass().getSimpleName() + "(" return getClass().getSimpleName() + "("
+ getAccountID().getDisplayName() + ")"; + 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();
}
} }

@ -74,6 +74,17 @@ public void register(SecurityAuthority authority)
public void unregister() public void unregister()
throws OperationFailedException; 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 * Indicates whether or not this provider is registered
* @return true if the provider is currently registered and false otherwise. * @return true if the provider is currently registered and false otherwise.

@ -110,6 +110,11 @@ public class RegistrationStateChangeEvent extends PropertyChangeEvent
*/ */
private final String reason; 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 * Creates an event instance indicating a change of the provider state
* from <tt>oldValue</tt> to <tt>newValue</tt>. * from <tt>oldValue</tt> to <tt>newValue</tt>.
@ -211,4 +216,22 @@ public String getReason()
{ {
return reason; 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;
}
} }

@ -547,7 +547,7 @@ public void run()
{ {
try try
{ {
protocolProvider.unregister(); protocolProvider.unregister(true);
} }
catch (OperationFailedException ex) catch (OperationFailedException ex)
{ {

Loading…
Cancel
Save