From a28fcf0dc592b23b35a91ca14ea88f88d04618e8 Mon Sep 17 00:00:00 2001 From: Brian Clements Date: Tue, 18 Feb 2014 08:48:17 -0600 Subject: [PATCH] Issue #2793 improved collaboration disconnect handling collaboration was being shutdown even though smack was trying to reconnect changed to notify of disconnect, but not shutdown until reconnect fails Former-commit-id: 231c3cd84e3c86caba81708581be911e771aa774 --- .../session/CollaborationConnection.java | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/cave/com.raytheon.uf.viz.collaboration.comm/src/com/raytheon/uf/viz/collaboration/comm/provider/session/CollaborationConnection.java b/cave/com.raytheon.uf.viz.collaboration.comm/src/com/raytheon/uf/viz/collaboration/comm/provider/session/CollaborationConnection.java index 446e10be52..4a1417236b 100644 --- a/cave/com.raytheon.uf.viz.collaboration.comm/src/com/raytheon/uf/viz/collaboration/comm/provider/session/CollaborationConnection.java +++ b/cave/com.raytheon.uf.viz.collaboration.comm/src/com/raytheon/uf/viz/collaboration/comm/provider/session/CollaborationConnection.java @@ -22,6 +22,7 @@ package com.raytheon.uf.viz.collaboration.comm.provider.session; import java.util.Collection; import java.util.HashMap; import java.util.Map; +import java.util.Map.Entry; import org.apache.commons.lang.StringUtils; import org.jivesoftware.smack.Connection; @@ -65,6 +66,7 @@ import com.raytheon.uf.viz.collaboration.comm.provider.Tools; import com.raytheon.uf.viz.collaboration.comm.provider.event.RosterChangeEvent; import com.raytheon.uf.viz.collaboration.comm.provider.event.ServerDisconnectEvent; import com.raytheon.uf.viz.collaboration.comm.provider.event.VenueInvitationEvent; +import com.raytheon.uf.viz.collaboration.comm.provider.event.VenueUserEvent; import com.raytheon.uf.viz.collaboration.comm.provider.user.ContactsManager; import com.raytheon.uf.viz.collaboration.comm.provider.user.IDConverter; import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId; @@ -110,6 +112,7 @@ import com.raytheon.uf.viz.collaboration.comm.provider.user.VenueParticipant; * Jan 30, 2014 2698 bclement changed arguments to create sessions, moved room connection from SessionView * Feb 3, 2014 2699 bclement removed unneeded catch in joinTextOnlyVenue * Feb 13, 2014 2751 bclement better types for venueid and invitor + * Feb 18, 2014 2793 bclement improved disconnection notification and handling * * * @@ -322,7 +325,9 @@ public class CollaborationConnection implements IEventPublisher { chatInstance = null; // Get rid of the account and roster managers - connection.disconnect(); + if (connection.isConnected()) { + connection.disconnect(); + } connection = null; } PeerToPeerCommHelper.reset(); @@ -548,6 +553,7 @@ public class CollaborationConnection implements IEventPublisher { @Override public void reconnectionSuccessful() { statusHandler.debug("Client successfully reconnected to server"); + postSystemMessageToVenues("Connection to collaboration server reestablished."); } @Override @@ -567,7 +573,8 @@ public class CollaborationConnection implements IEventPublisher { public void connectionClosedOnError(Exception e) { String reason = getErrorReason(e); statusHandler.error("Server closed on error: " + reason, e); - sendDisconnectNotice(reason); + // don't shutdown yet, we might be able to reconnect + postSystemMessageToVenues("Not currently connected to collaboration server."); } private String getErrorReason(Exception e) { @@ -733,12 +740,32 @@ public class CollaborationConnection implements IEventPublisher { } } + /** + * @return Smack connection object + */ protected XMPPConnection getXmppConnection() { return connection; } + /** + * Construct a new UserSearch object + * + * @return + */ public UserSearch createSearch() { return new UserSearch(connection); } + /** + * Post a system message to all venue windows this client has. This is for + * local system messages, it does not go out to the server. + * + * @param message + */ + public void postSystemMessageToVenues(String message) { + for (Entry entry : sessions.entrySet()) { + entry.getValue().postEvent(new VenueUserEvent(message)); + } + } + }