diff --git a/src/net/java/sip/communicator/impl/protocol/irc/CommandFactory.java b/src/net/java/sip/communicator/impl/protocol/irc/CommandFactory.java index 955fbdfdd..38cb7d18e 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/CommandFactory.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/CommandFactory.java @@ -35,9 +35,10 @@ public class CommandFactory * * @return returns an unmodifiable map of registered commands */ - public static Map> getCommands() + public static synchronized Map> + getCommands() { - return Collections.unmodifiableMap(COMMANDS); + return new HashMap>(COMMANDS); } /** @@ -46,7 +47,7 @@ public static Map> getCommands() * @param command the command word * @param type the type to instantiate for command execution */ - public static void registerCommand(final String command, + public static synchronized void registerCommand(final String command, final Class type) { if (command == null) @@ -57,12 +58,12 @@ public static void registerCommand(final String command, { throw new IllegalArgumentException("type cannot be null"); } + COMMANDS.put(command, type); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Registered command '" + command + "' (" + type.toString() + ")"); } - COMMANDS.put(command, type); } /** @@ -73,8 +74,9 @@ public static void registerCommand(final String command, * registered. This can be used to unregister only one of * multiple commands for the same implementation type. */ - public static void unregisterCommand(final Class type, - final String command) + public static synchronized void unregisterCommand( + final Class type, + final String command) { Iterator>> it = COMMANDS.entrySet().iterator(); @@ -85,6 +87,11 @@ public static void unregisterCommand(final Class type, && (command == null || command.equals(entry.getKey()))) { it.remove(); + if (LOGGER.isDebugEnabled()) + { + LOGGER.debug("Unregistered command '" + command + "' (" + + type.toString() + ")"); + } } } } diff --git a/src/net/java/sip/communicator/impl/protocol/irc/MessageManager.java b/src/net/java/sip/communicator/impl/protocol/irc/MessageManager.java index 8af08cbf3..f759eb8f4 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/MessageManager.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/MessageManager.java @@ -39,6 +39,10 @@ public class MessageManager */ private static final int IRC_PROTOCOL_MAXIMUM_MESSAGE_SIZE = 510; + /** + * Register some basic commands immediately so that these are guaranteed to + * be available. + */ static { CommandFactory.registerCommand("me", Me.class);