Tweaking the join process: throw OFE when there's trouble.

fix-message-formatting
Danny van Heumen 12 years ago
parent 0d405b0c93
commit b817367a5c

@ -350,8 +350,9 @@ public List<String> 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]);
}
}
}

@ -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 <tt>ChatRoomInvitationReceivedEvent</tt> to all

Loading…
Cancel
Save