diff options
author | Damian Minkov <damencho@jitsi.org> | 2010-05-18 13:17:36 +0000 |
---|---|---|
committer | Damian Minkov <damencho@jitsi.org> | 2010-05-18 13:17:36 +0000 |
commit | ca73a4bca2ee9c65c9e4c94a4617a07451ec4240 (patch) | |
tree | 5ebba4a7e517bcf8990f925b298bcbde115676ab | |
parent | c5805675da62950dbecb2ad172d1e29e43aa9b14 (diff) | |
download | jitsi-ca73a4bca2ee9c65c9e4c94a4617a07451ec4240.zip jitsi-ca73a4bca2ee9c65c9e4c94a4617a07451ec4240.tar.gz jitsi-ca73a4bca2ee9c65c9e4c94a4617a07451ec4240.tar.bz2 |
Some reconnect improvements as detecting newly created accounts and modified one. Fix icq to properly detect disconnects on purpose.
3 files changed, 201 insertions, 12 deletions
diff --git a/resources/languages/resources.properties b/resources/languages/resources.properties index 2d1749f..7aed757 100644 --- a/resources/languages/resources.properties +++ b/resources/languages/resources.properties @@ -932,4 +932,7 @@ plugin.globalproxy.PROTOCOL_SUPPORT=<html><table> \ <tr><td>MSN</td><td>+</td><td>+</td><td>-</td><td>-</td></tr>\
<tr><td>JABBER</td><td>+</td><td>+</td><td>+</td><td>+</td></tr>\
<tr><td>ICQ/AIM</td><td>+</td><td>+</td><td>+</td><td>+</td></tr>\
-</table></html>
\ No newline at end of file +</table></html
+
+# plugin reconnect
+plugin.reconnectplugin.CONNECTION_FAILED_MSG=Connection failed for the following account:\nUser name: {0}, Server name: {1}.\nPlease check your settings or contact your network administrator for more information.
\ No newline at end of file diff --git a/src/net/java/sip/communicator/impl/protocol/icq/ProtocolProviderServiceIcqImpl.java b/src/net/java/sip/communicator/impl/protocol/icq/ProtocolProviderServiceIcqImpl.java index 3ebcaee..100f5a5 100644 --- a/src/net/java/sip/communicator/impl/protocol/icq/ProtocolProviderServiceIcqImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/icq/ProtocolProviderServiceIcqImpl.java @@ -31,15 +31,30 @@ import net.kano.joustsim.oscar.proxy.*; public class ProtocolProviderServiceIcqImpl extends AbstractProtocolProviderService { + /** + * This class logger. + */ private static final Logger logger = Logger.getLogger(ProtocolProviderServiceIcqImpl.class); + /** + * Application session. + */ private DefaultAppSession session = null; + /** + * Protocol stack session. + */ private AimSession aimSession = null; + /** + * Protocol stack connection. + */ private AimConnection aimConnection = null; + /** + * Messenger service. + */ private IcbmService icbmService = null; /** @@ -233,6 +248,7 @@ public class ProtocolProviderServiceIcqImpl /** * Connects and logins to the server * @param authority SecurityAuthority + * @param reasonCode reason code in case of reconnect. * @throws OperationFailedException if login parameters * as server port are not correct */ @@ -630,6 +646,10 @@ public class ProtocolProviderServiceIcqImpl */ private class AimConnStateListener implements StateListener { + /** + * Connection state changes being reported here. + * @param event + */ public void handleStateChange(StateEvent event) { State newState = event.getNewState(); @@ -672,6 +692,17 @@ public class ProtocolProviderServiceIcqImpl "The aim Connection was disconnected! with reason : " + reasonStr); } + + if(reasonCode == RegistrationStateChangeEvent.REASON_NOT_SPECIFIED + && event.getNewStateInfo() instanceof DisconnectedStateInfo) + { + // if its on purpose it is user request + if(((DisconnectedStateInfo)event.getNewStateInfo()).isOnPurpose()) + { + reasonCode = + RegistrationStateChangeEvent.REASON_USER_REQUEST; + } + } else logger.debug("The aim Connection was disconnected!"); } @@ -742,6 +773,11 @@ public class ProtocolProviderServiceIcqImpl } } + /** + * Throw registered with 2 seconds delay. + * We must wait a little bit before firing registered + * event , waiting for ClientReadyCommand to be sent successfully + */ private class RegisteredEventThread extends Thread { public void run() @@ -782,21 +818,41 @@ public class ProtocolProviderServiceIcqImpl return aimConnection; } + /** + * Message listener. + */ public static class AimIcbmListener implements IcbmListener { + /** + * New conversations. + * @param service the messenger service. + * @param conv the new conversation. + */ public void newConversation(IcbmService service, Conversation conv) { logger.debug("Received a new conversation event"); conv.addConversationListener(new AimConversationListener()); } + /** + * Does nothing. + * @param service + * @param buddy + * @param info + */ public void buddyInfoUpdated(IcbmService service, Screenname buddy, IcbmBuddyInfo info) { logger.debug("Got a BuddINFO event"); } + /** + * Does nothing. + * @param service + * @param message + * @param triedConversations + */ public void sendAutomaticallyFailed( IcbmService service, net.kano.joustsim.oscar.oscar.service.icbm.Message message, diff --git a/src/net/java/sip/communicator/plugin/reconnectplugin/ReconnectPluginActivator.java b/src/net/java/sip/communicator/plugin/reconnectplugin/ReconnectPluginActivator.java index 0fc03dc..364fbae 100644 --- a/src/net/java/sip/communicator/plugin/reconnectplugin/ReconnectPluginActivator.java +++ b/src/net/java/sip/communicator/plugin/reconnectplugin/ReconnectPluginActivator.java @@ -10,12 +10,14 @@ import java.net.*; import java.util.*; import java.util.ArrayList; +import net.java.sip.communicator.service.configuration.*; import net.java.sip.communicator.service.gui.*; import net.java.sip.communicator.service.netaddr.*; import net.java.sip.communicator.service.netaddr.event.*; import net.java.sip.communicator.service.notification.*; import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.service.protocol.event.*; +import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.util.*; import org.osgi.framework.*; @@ -48,6 +50,17 @@ public class ReconnectPluginActivator private static UIService uiService; /** + * The resources service. + */ + private static ResourceManagementService resourcesService; + + /** + * A reference to the ConfigurationService implementation instance that + * is currently registered with the bundle context. + */ + private static ConfigurationService configurationService = null; + + /** * Notification service. */ private static NotificationService notificationService; @@ -120,6 +133,13 @@ public class ReconnectPluginActivator public static final String NETWORK_NOTIFICATIONS = "NetowrkNotifications"; /** + * + */ + public static final String ATLEAST_ONE_CONNECTION_PROP = + "net.java.sip.communicator.plugin.reconnectplugin." + + "ATLEAST_ONE_SUCCESSFUL_CONNECTION"; + + /** * Starts this bundle * * @param bundleContext BundleContext @@ -220,6 +240,48 @@ public class ReconnectPluginActivator } /** + * Returns resource service. + * @return the resource service. + */ + public static ResourceManagementService getResources() + { + if (resourcesService == null) + { + ServiceReference serviceReference = bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = (ResourceManagementService) bundleContext + .getService(serviceReference); + } + + return resourcesService; + } + + /** + * Returns a reference to a ConfigurationService implementation currently + * registered in the bundle context or null if no such implementation was + * found. + * + * @return a currently valid implementation of the ConfigurationService. + */ + public static ConfigurationService getConfigurationService() + { + if (configurationService == null) + { + ServiceReference confReference + = bundleContext.getServiceReference( + ConfigurationService.class.getName()); + configurationService + = (ConfigurationService) bundleContext + .getService(confReference); + } + return configurationService; + } + + /** * Returns the <tt>NotificationService</tt> obtained from the bundle context. * * @return the <tt>NotificationService</tt> obtained from the bundle context @@ -254,7 +316,7 @@ public class ReconnectPluginActivator ServiceReference serviceRef = serviceEvent.getServiceReference(); // if the event is caused by a bundle being stopped, we don't want to - // know + // know we are shutting down if (serviceRef.getBundle().getState() == Bundle.STOPPING) { return; @@ -311,24 +373,37 @@ public class ReconnectPluginActivator */ private void handleProviderAdded(ProtocolProviderService provider) { - logger.debug("Adding protocol provider " + provider.getProtocolName()); + logger.trace("New protocol provider is comming " + + provider.getProtocolName()); - if(provider instanceof ProtocolProviderService) - { - provider.addRegistrationStateChangeListener(this); - } + provider.addRegistrationStateChangeListener(this); } /** * Stop listening for events as the provider is removed. + * Providers are removed this way only when there are modified + * in the configuration. So as the provider is modified we will erase + * every instance we got. * * @param provider the ProtocolProviderService that has been unregistered. */ private void handleProviderRemoved(ProtocolProviderService provider) { - if(provider instanceof ProtocolProviderService) + logger.trace("Provider modified forget every instance of it"); + + if(hasAtLeastOneSuccessfulConnection(provider)) + { + setAtLeastOneSuccessfulConnection(provider, false); + } + + provider.removeRegistrationStateChangeListener(this); + + autoReconnEnabledProviders.remove(provider); + needsReconnection.remove(provider); + + if(currentlyReconnecting.containsKey(provider)) { - provider.removeRegistrationStateChangeListener(this); + currentlyReconnecting.remove(provider).cancel(); } } @@ -452,6 +527,25 @@ public class ReconnectPluginActivator if(evt.getNewState().equals(RegistrationState.CONNECTION_FAILED)) { + if(!hasAtLeastOneSuccessfulConnection(pp)) + { + // ignore providers which haven't registered successfully + // till now, they maybe misconfigured + // todo show dialog + String msgText = getResources().getI18NString( + "plugin.reconnectplugin.CONNECTION_FAILED_MSG", + new String[] + { pp.getAccountID().getUserID(), + pp.getAccountID().getService() }); + + getUIService().getPopupDialog().showMessagePopupDialog( + msgText, + getResources().getI18NString("service.gui.ERROR"), + PopupDialog.ERROR_MESSAGE); + + return; + } + // if this pp is already in needsReconnection, it means // we got conn failed cause the pp has tried to unregister // with sending network packet @@ -474,16 +568,20 @@ public class ReconnectPluginActivator } else if(evt.getNewState().equals(RegistrationState.REGISTERED)) { + if(!hasAtLeastOneSuccessfulConnection(pp)) + { + setAtLeastOneSuccessfulConnection(pp, true); + } + autoReconnEnabledProviders.put( - (ProtocolProviderService)evt.getSource(), + pp, new ArrayList<String>(connectedInterfaces)); currentlyReconnecting.remove(pp); } else if(evt.getNewState().equals(RegistrationState.UNREGISTERED)) { - autoReconnEnabledProviders.remove( - (ProtocolProviderService)evt.getSource()); + autoReconnEnabledProviders.remove(pp); if(!unregisteredProviders.contains(pp) && currentlyReconnecting.containsKey(pp)) @@ -578,4 +676,36 @@ public class ReconnectPluginActivator } } } + + /** + * Check does the supplied protocol has the property set for at least + * one successful connection. + * @param pp the protocol provider + * @return true if property exists. + */ + private boolean hasAtLeastOneSuccessfulConnection(ProtocolProviderService pp) + { + String value = (String)getConfigurationService().getProperty( + ATLEAST_ONE_CONNECTION_PROP + "." + + pp.getAccountID().getAccountUniqueID()); + + if(value == null || !value.equals(Boolean.TRUE.toString())) + return false; + else + return true; + } + + /** + * Changes the property about at least one successful connection. + * @param pp the protocol provider + * @param value the new value true or false. + */ + private void setAtLeastOneSuccessfulConnection( + ProtocolProviderService pp, boolean value) + { + getConfigurationService().setProperty( + ATLEAST_ONE_CONNECTION_PROP + "." + + pp.getAccountID().getAccountUniqueID(), + Boolean.valueOf(value).toString()); + } } |