From b817367a5cf2359e7ecab9f1a31c49b3890cf35a Mon Sep 17 00:00:00 2001 From: Danny van Heumen Date: Tue, 21 Jan 2014 22:25:17 +0100 Subject: [PATCH] Tweaking the join process: throw OFE when there's trouble. --- .../impl/protocol/irc/IrcStack.java | 21 +++++++++++++++++-- .../irc/OperationSetMultiUserChatIrcImpl.java | 13 ++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java b/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java index a943ccee5..46518eff1 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java @@ -350,8 +350,9 @@ public List getServerChatRoomList() * Join a particular chat room. * * @param chatroom Chat room to join. + * @throws OperationFailedException failed to join the chat room */ - public void join(ChatRoomIrcImpl chatroom) + public void join(ChatRoomIrcImpl chatroom) throws OperationFailedException { join(chatroom, ""); } @@ -365,8 +366,10 @@ public void join(ChatRoomIrcImpl chatroom) * @param chatroom The chatroom to join. * @param password Optionally, a password that may be required for some * channels. + * @throws OperationFailedException failed to join the chat room */ public void join(final ChatRoomIrcImpl chatroom, final String password) + throws OperationFailedException { if (isConnected() == false) throw new IllegalStateException( @@ -384,7 +387,7 @@ public void join(final ChatRoomIrcImpl chatroom, final String password) } LOGGER.trace("Start joining channel " + chatroom.getIdentifier()); - final Object joinSignal = new Object(); + final Exception[] joinSignal = new Exception[1]; synchronized (joinSignal) { try @@ -420,6 +423,9 @@ public void onSuccess(IRCChannel channel) "Forwarding to channel " + channel.getName(), "text/plain", "UTF-8", null); + IrcStack.this.provider.getMUC() + .registerChatRoomInstance( + actualChatRoom); chatroom .fireMessageReceivedEvent( message, @@ -504,6 +510,7 @@ public void onFailure(Exception e) { try { + joinSignal[0] = e; MessageIrcImpl message = new MessageIrcImpl( "Failed to join channel " @@ -537,8 +544,18 @@ public void onFailure(Exception e) } catch (InterruptedException e) { + // TODO what should we do with this? Maybe store in joinSignal + // if there's nothing else? e.printStackTrace(); } + + if (joinSignal[0] != null) + { + // in case an exception occurred during join process + throw new OperationFailedException(joinSignal[0].getMessage(), + OperationFailedException.CHAT_ROOM_NOT_JOINED, + joinSignal[0]); + } } } diff --git a/src/net/java/sip/communicator/impl/protocol/irc/OperationSetMultiUserChatIrcImpl.java b/src/net/java/sip/communicator/impl/protocol/irc/OperationSetMultiUserChatIrcImpl.java index 3e9d0da68..a4a8b7e07 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/OperationSetMultiUserChatIrcImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/OperationSetMultiUserChatIrcImpl.java @@ -213,6 +213,19 @@ private ChatRoom createLocalChatRoomInstance(String chatRoomName) return chatRoom; } } + + /** + * Register chat room instance in case it is not yet registered. + * + * @param chatroom the chatroom + */ + public void registerChatRoomInstance(ChatRoomIrcImpl chatroom) + { + synchronized (this.chatRoomCache) + { + this.chatRoomCache.put(chatroom.getIdentifier(), chatroom); + } + } /** * Delivers a ChatRoomInvitationReceivedEvent to all