Some reconnect improvements as detecting newly created accounts and modified one. Fix icq to properly detect disconnects on purpose.

cusax-fix
Damian Minkov 16 years ago
parent c5805675da
commit ca73a4bca2

@ -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>
</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.

@ -31,15 +31,30 @@
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 @@ void reconnect(int reasonCode)
/**
* 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 @@ protected InfoRetreiver getInfoRetreiver()
*/
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 @@ else if (newState == State.DISCONNECTED)
"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 @@ else if (newState == State.DISCONNECTED)
}
}
/**
* 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 @@ protected AimConnection getAimConnection()
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,

@ -10,12 +10,14 @@
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.*;
@ -47,6 +49,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.
*/
@ -119,6 +132,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
*
@ -219,6 +239,48 @@ public static UIService getUIService()
return uiService;
}
/**
* 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.
*
@ -254,7 +316,7 @@ public void serviceChanged(ServiceEvent serviceEvent)
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 void serviceChanged(ServiceEvent serviceEvent)
*/
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 synchronized void registrationStateChanged(RegistrationStateChangeEvent e
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 synchronized void registrationStateChanged(RegistrationStateChangeEvent e
}
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 void run()
}
}
}
/**
* 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());
}
}

Loading…
Cancel
Save