From 5e39f5a61c61237a48390a71021da0792230b8b9 Mon Sep 17 00:00:00 2001 From: Mike Duff Date: Wed, 9 Apr 2014 10:17:22 -0500 Subject: [PATCH] Issue #2785 - Throw error when CollaborationConnection needs connection and it doesn't exist Change-Id: I2f2234da42e9210b574f7489fc37da0a63bf2133 Former-commit-id: eafa177f4b8d752270dfd76c43fb6d831bd5a442 [formerly a1f94a19ba7f0bff7bbf76fa24ff6ace9019d0f1] Former-commit-id: 23474c5ead16552b762d393077ea7e5d17212c5c --- .../session/CollaborationConnection.java | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 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 31459134af..8197c7775d 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 @@ -118,6 +118,7 @@ import com.raytheon.uf.viz.collaboration.comm.provider.user.VenueParticipant; * Mar 07, 2014 2848 bclement removed join*Venue methods, now only creates venue objects * changed session map to a concurrent hash map * Apr 07, 2014 2785 mpduff Changed the order of startup, sets up listeners before actually connecting. + * Apr 09, 2014 2785 mpduff Throw error when not connected and the connection should exist. * * * @@ -207,10 +208,7 @@ public class CollaborationConnection implements IEventPublisher { this.user = new UserId(connectionData.getUserName(), connection.getServiceName()); - setupConnectionListener(); setupInternalConnectionListeners(); - setupInternalVenueInvitationListener(); - setupP2PComm(); getPeerToPeerSession(); instanceMap.put(connectionData, this); @@ -525,13 +523,18 @@ public class CollaborationConnection implements IEventPublisher { return sessions.get(sessionId); } - private void setupP2PComm() { - PeerToPeerCommHelper helper = new PeerToPeerCommHelper(this); - connection.addPacketListener(helper, - new PacketTypeFilter(Message.class)); + private void setupP2PComm() throws CollaborationException { + if (isConnected()) { + PeerToPeerCommHelper helper = new PeerToPeerCommHelper(this); + connection.addPacketListener(helper, new PacketTypeFilter( + Message.class)); + } else { + throw new CollaborationException( + "The Collaboration XMPP connection has not been established."); + } } - private void setupConnectionListener() { + private void setupConnectionListener() throws CollaborationException { if (isConnected()) { connection.addConnectionListener(new ConnectionListener() { @@ -591,6 +594,9 @@ public class CollaborationConnection implements IEventPublisher { eventBus.post(event); } }); + } else { + throw new CollaborationException( + "The Collaboration XMPP connection has not been established."); } } @@ -599,9 +605,12 @@ public class CollaborationConnection implements IEventPublisher { // *************************** /** + * Set up the invitation listener. * + * @throws CollaborationException */ - private void setupInternalVenueInvitationListener() { + private void setupInternalVenueInvitationListener() + throws CollaborationException { if (isConnected()) { MultiUserChat.addInvitationListener(connection, new InvitationListener() { @@ -633,6 +642,9 @@ public class CollaborationConnection implements IEventPublisher { message); } }); + } else { + throw new CollaborationException( + "The Collaboration XMPP connection has not been established."); } } @@ -777,5 +789,10 @@ public class CollaborationConnection implements IEventPublisher { connectionData.getPassword()); authManager = new ClientAuthManager(getXmppConnection()); + + // Finish setup + setupInternalVenueInvitationListener(); + setupP2PComm(); + setupConnectionListener(); } }