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 684c036d1..197e2eddb 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolProviderServiceJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolProviderServiceJabberImpl.java @@ -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()); + } } } diff --git a/src/net/java/sip/communicator/impl/sysactivity/SystemActivityNotificationsServiceImpl.java b/src/net/java/sip/communicator/impl/sysactivity/SystemActivityNotificationsServiceImpl.java index 4d7c12dbd..112fe9352 100644 --- a/src/net/java/sip/communicator/impl/sysactivity/SystemActivityNotificationsServiceImpl.java +++ b/src/net/java/sip/communicator/impl/sysactivity/SystemActivityNotificationsServiceImpl.java @@ -48,10 +48,21 @@ public class SystemActivityNotificationsServiceImpl private final List listenersInIdleState = new ArrayList(); + /** + * 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 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 listeners = null; + Collection listeners; synchronized (this.activityChangeListeners) { listeners = new ArrayList( @@ -393,38 +428,6 @@ protected void fireSystemActivityEvent(SystemActivityEvent evt) } } - /** - * Delivers the specified event to all registered listeners. - * - * @param evt the SystemActivityEvent that we'd like delivered to - * all registered message listeners. - */ - protected void fireSystemIdleEvent(SystemActivityEvent evt) - { - Collection listeners = null; - synchronized (this.idleChangeListeners) - { - listeners = new ArrayList( - 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. *