Respects IS_SERVER_OVERRIDDEN account property when connecting with Jabber account. Better detection for idle and exit of idle state.

cusax-fix
Damian Minkov 15 years ago
parent a5f2f134dc
commit dcefe7152a

@ -546,17 +546,25 @@ private void connectAndLogin(SecurityAuthority authority,
}
}
// check to see is there SRV records for this server domain
boolean isServerOverriden =
getAccountID().getAccountPropertyBoolean(
ProtocolProviderFactory.IS_SERVER_OVERRIDDEN, false);
try
{
SRVRecord srvRecords[] = NetworkUtils
.getSRVRecords("xmpp-client", "tcp", serviceName);
if(srvRecords != null)
if(!isServerOverriden)
{
for(int i = 0 ; i < srvRecords.length ; i++)
// check to see is there SRV records for
// this server domain
SRVRecord srvRecords[] = NetworkUtils
.getSRVRecords("xmpp-client", "tcp", serviceName);
if(srvRecords != null)
{
serverAddresses.add(srvRecords[i].getTarget());
for(int i = 0 ; i < srvRecords.length ; i++)
{
serverAddresses.add(srvRecords[i].getTarget());
}
}
}

@ -48,10 +48,21 @@ public class SystemActivityNotificationsServiceImpl
private final List<SystemActivityChangeListener> listenersInIdleState
= new ArrayList<SystemActivityChangeListener>();
/**
* The interval between checks when not idle.
*/
private static final int CHECK_FOR_IDLE_DEFAULT = 30*1000;
/**
* The interval between checks when idle. The interval is shorter
* so we can react almost immediately when we are active again.
*/
private static final int CHECK_FOR_IDLE_WHEN_IDLE = 1000;
/**
* The time in milliseconds between two checks for system idle.
*/
private static final int idleStateCheckDelay = 10*1000;
private static int idleStateCheckDelay = CHECK_FOR_IDLE_DEFAULT;
/**
* Whether current service is started or stopped.
@ -202,7 +213,7 @@ public void removeIdleSystemChangeListener(
/**
* Callback method when receiving notifications.
*
* @param type
* @param type type of the notification.
*/
@Override
public void notify(int type)
@ -316,10 +327,11 @@ public void run()
{
try
{
long idleTime = 0;
if(idleChangeListeners.size() > 0)
{
// check
long idleTime = SystemActivityNotifications.getLastInput();
idleTime = SystemActivityNotifications.getLastInput();
if(idleTime < idleStateCheckDelay
&& listenersInIdleState.size() > 0)
@ -334,7 +346,7 @@ public void run()
for(Map.Entry<SystemActivityChangeListener, Long> entry :
idleChangeListeners.entrySet())
{
if(entry.getValue().longValue() <= idleTime)
if(entry.getValue() <= idleTime)
{
fireSystemIdleEvent(entry.getKey());
@ -343,6 +355,29 @@ public void run()
}
}
// if the minimum check for idle is X minutes
// we will wait before checking (X - Y + 1sec)
// where Y is the last idle time returned by OS
if(listenersInIdleState.size() > 0)
{
idleStateCheckDelay = CHECK_FOR_IDLE_WHEN_IDLE;
}
else if(idleTime != 0)
{
long minIdleSetting =
Collections.min(idleChangeListeners.values());
int newSetting = (int)(minIdleSetting - idleTime) + 1000;
if(newSetting > 0)
idleStateCheckDelay = newSetting;
else
idleStateCheckDelay = CHECK_FOR_IDLE_DEFAULT;
}
else
{
idleStateCheckDelay = CHECK_FOR_IDLE_DEFAULT;
}
// wait for the specified time
synchronized(this)
{
@ -369,7 +404,7 @@ public void run()
*/
protected void fireSystemActivityEvent(SystemActivityEvent evt)
{
Collection<SystemActivityChangeListener> listeners = null;
Collection<SystemActivityChangeListener> listeners;
synchronized (this.activityChangeListeners)
{
listeners = new ArrayList<SystemActivityChangeListener>(
@ -393,38 +428,6 @@ protected void fireSystemActivityEvent(SystemActivityEvent evt)
}
}
/**
* Delivers the specified event to all registered listeners.
*
* @param evt the <tt>SystemActivityEvent</tt> that we'd like delivered to
* all registered message listeners.
*/
protected void fireSystemIdleEvent(SystemActivityEvent evt)
{
Collection<SystemActivityChangeListener> listeners = null;
synchronized (this.idleChangeListeners)
{
listeners = new ArrayList<SystemActivityChangeListener>(
this.idleChangeListeners.keySet());
}
if (logger.isDebugEnabled())
logger.debug("Dispatching SystemActivityEvent Listeners="
+ listeners.size() + " evt=" + evt);
for (SystemActivityChangeListener listener : listeners)
{
try
{
listener.activityChanged(evt);
}
catch (Throwable e)
{
logger.error("Error delivering event", e);
}
}
}
/**
* Delivers the specified event to all registered listeners.
*

Loading…
Cancel
Save