From a9f396f3274e72a8f0801425bb57425e560e9fa6 Mon Sep 17 00:00:00 2001 From: Danny van Heumen Date: Wed, 11 Feb 2015 00:08:11 +0100 Subject: Use MONITOR maximum list size. Some clean-up. --- .../impl/protocol/irc/MonitorPresenceWatcher.java | 27 +++++++++++++++++----- .../impl/protocol/irc/PresenceManager.java | 12 +++++----- 2 files changed, 27 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/net/java/sip/communicator/impl/protocol/irc/MonitorPresenceWatcher.java b/src/net/java/sip/communicator/impl/protocol/irc/MonitorPresenceWatcher.java index 7001c61..37eb940 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/MonitorPresenceWatcher.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/MonitorPresenceWatcher.java @@ -58,7 +58,8 @@ class MonitorPresenceWatcher */ MonitorPresenceWatcher(final IRCApi irc, final IIRCState connectionState, final SortedSet nickWatchList, - final OperationSetPersistentPresenceIrcImpl operationSet) + final OperationSetPersistentPresenceIrcImpl operationSet, + final int maxListSize) { if (irc == null) { @@ -77,9 +78,8 @@ class MonitorPresenceWatcher } this.nickWatchList = nickWatchList; this.irc.addListener(new MonitorReplyListener(operationSet)); - setUpMonitor(this.irc, this.nickWatchList); + setUpMonitor(this.irc, this.nickWatchList, maxListSize); // FIXME add basic poller watcher as a fallback method - // FIXME adhere to limits according to ISUPPORT MONITOR=# entry LOGGER.debug("MONITOR presence watcher initialized."); } @@ -90,13 +90,18 @@ class MonitorPresenceWatcher * still being initialized. */ private static void setUpMonitor(final IRCApi irc, - final SortedSet nickWatchList) + final SortedSet nickWatchList, final int maxListSize) { - final List current; + List current; synchronized (nickWatchList) { current = new LinkedList(nickWatchList); } + if (current.size() > maxListSize) + { + // cut off list to maximum number of entries allowed by server + current = current.subList(0, maxListSize); + } final int maxLength = 510 - MONITOR_ADD_CMD_STATIC_OVERHEAD; final StringBuilder query = new StringBuilder(); for (String nick : current) @@ -158,7 +163,6 @@ class MonitorPresenceWatcher */ private static final int IRC_RPL_MONOFFLINE = 731; - // Unused constants. Listed for completeness. // /** // * Numeric message id for MONLIST entry. // */ @@ -170,6 +174,12 @@ class MonitorPresenceWatcher // private static final int IRC_RPL_ENDOFMONLIST = 733; /** + * Error message signaling full list. Nick list provided are all nicks + * that failed to be added to the monitor list. + */ + private static final int IRC_ERR_MONLISTFULL = 734; + + /** * Operation set persistent presence instance. */ private final OperationSetPersistentPresenceIrcImpl operationSet; @@ -228,6 +238,11 @@ class MonitorPresenceWatcher } monitoredNickList.addAll(acknowledged); break; + case IRC_ERR_MONLISTFULL: + LOGGER.debug("MONITOR list full. Nick was not added. " + + "Fall back Basic Poller will be used if it is enabled. (" + + msg.getText() + ")"); + break; } } diff --git a/src/net/java/sip/communicator/impl/protocol/irc/PresenceManager.java b/src/net/java/sip/communicator/impl/protocol/irc/PresenceManager.java index 7e1ca52..da30cd0 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/PresenceManager.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/PresenceManager.java @@ -19,16 +19,16 @@ import com.ircclouds.irc.api.state.*; /** * Manager for presence status of IRC connection. * - * There is (somewhat primitive) support for online presence by periodically - * querying IRC server with ISON requests for each of the members in the contact - * list. + * There is support for online presence by polling (periodically querying IRC + * server with ISON requests) for each of the members in the contact list or, if + * supported by the IRC server, for the MONITOR command to subscribe to presence + * notifications for the specified nick. * * TODO Support for 'a' (Away) user mode. (Check this again, since I also see * 'a' used for other purposes. This may be one of those ambiguous letters that * every server interprets differently.) * - * TODO Improve presence watcher by using WATCH or MONITOR. (Monitor does not - * seem to support away status, though) + * TODO Additionally add support for pub/sub presence notifications using WATCH. * * @author Danny van Heumen */ @@ -161,7 +161,7 @@ public class PresenceManager { this.watcher = new MonitorPresenceWatcher(this.irc, this.connectionState, - nickWatchList, this.operationSet); + nickWatchList, this.operationSet, this.isupportMonitor); } } else -- cgit v1.1