-
Notifications
You must be signed in to change notification settings - Fork 8
Add auto rejoin on join errors #359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,8 @@ class JabberProtocol() extends Actor with ActorLogging { | |
| var privateHandler: ActorRef = null | ||
| var rooms = Map[String, RoomDefinition]() | ||
|
|
||
| private val rejoinInterval = 5.seconds | ||
|
|
||
| override def preStart() { | ||
| privateHandler = context.actorOf( | ||
| Props(new PrivateMessageHandler(Configuration.defaultLocalization, self)), "privateHandler") | ||
|
|
@@ -52,26 +54,34 @@ class JabberProtocol() extends Actor with ActorLogging { | |
| case Reconnect(otherConnection) => | ||
| log.info(s"Ignored reconnect request from connection $otherConnection") | ||
|
|
||
| case JoinRoom(jid, locale, nickname, greeting) => | ||
| case message@JoinRoom(jid, locale, nickname, greeting) => | ||
| log.info(s"Joining room $jid") | ||
| val actor = context.actorOf( | ||
| Props(new MucMessageHandler(locale, self, jid, nickname)), jid) | ||
|
|
||
| val muc = new MultiUserChat(connection, jid) | ||
| rooms = rooms.updated(jid, RoomDefinition(muc, actor)) | ||
|
|
||
| muc.addMessageListener(new MucMessageListener(jid, actor, log)) | ||
| muc.addParticipantStatusListener(new MucParticipantStatusListener(muc, actor)) | ||
|
|
||
| val filter = new AndFilter(new PacketTypeFilter(classOf[Message]), new FromContainsFilter(jid)) | ||
| connection.addPacketListener( | ||
| new MessageAutoRepeater(context.system, self, context.system.scheduler, jid, context.dispatcher), | ||
| filter) | ||
|
|
||
| muc.join(nickname) | ||
| greeting match { | ||
| case Some(message) => muc.sendMessage(message) | ||
| case None => | ||
| try { | ||
| // TODO: Move this code to the room actor and use "let it fall" strategy ~ F | ||
| val muc = new MultiUserChat(connection, jid) | ||
| rooms = rooms.updated(jid, RoomDefinition(muc, actor)) | ||
|
|
||
| muc.addMessageListener(new MucMessageListener(jid, actor, log)) | ||
| muc.addParticipantStatusListener(new MucParticipantStatusListener(muc, actor)) | ||
|
|
||
| val filter = new AndFilter(new PacketTypeFilter(classOf[Message]), new FromContainsFilter(jid)) | ||
| connection.addPacketListener( | ||
| new MessageAutoRepeater(context.system, self, context.system.scheduler, jid, context.dispatcher), | ||
| filter) | ||
|
|
||
| muc.join(nickname) | ||
| greeting match { | ||
| case Some(text) => muc.sendMessage(text) | ||
| case None => | ||
| } | ||
| } catch { | ||
| case t: Throwable => | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Generally, I do not like this approach. But I cannot suggest anything better for now. I'm ok with this if we at least will log the exception somewhere. At least its message. Like "Cannot join because of
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a nice suggestion about logging. Thank you, I'll implement that. |
||
| log.warning(s"Cannot join room $jid, retrying in $rejoinInterval. Error was $t") | ||
| context.stop(actor) | ||
| context.system.scheduler.scheduleOnce(rejoinInterval, self, message) | ||
| } | ||
|
|
||
| case ChatOpened(chat) => { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For such todos I always recommend to create an issue with the
refactortag or something. :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have already created it: #358.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Thanks! :)