activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From martyntay...@apache.org
Subject [3/3] activemq-artemis git commit: NO-JIRA Clean up around MQTTConnectionManager
Date Tue, 14 Feb 2017 19:42:14 GMT
NO-JIRA Clean up around MQTTConnectionManager

(cherry picked from commit bd1f244dfcd20f7a2c7f22f5a77d40b4e4079230)


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/b3988647
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/b3988647
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/b3988647

Branch: refs/heads/1.x
Commit: b3988647f4c4315d0042696442075baf3d2989a1
Parents: f25396d
Author: Martyn Taylor <mtaylor@redhat.com>
Authored: Tue Feb 14 10:10:25 2017 +0000
Committer: Martyn Taylor <mtaylor@redhat.com>
Committed: Tue Feb 14 19:41:50 2017 +0000

----------------------------------------------------------------------
 .../protocol/mqtt/MQTTConnectionManager.java    | 58 +++++++++-----------
 1 file changed, 26 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b3988647/artemis-protocols/artemis-mqtt-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/mqtt/MQTTConnectionManager.java
----------------------------------------------------------------------
diff --git a/artemis-protocols/artemis-mqtt-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/mqtt/MQTTConnectionManager.java
b/artemis-protocols/artemis-mqtt-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/mqtt/MQTTConnectionManager.java
index f5f9111..182ebad 100644
--- a/artemis-protocols/artemis-mqtt-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/mqtt/MQTTConnectionManager.java
+++ b/artemis-protocols/artemis-mqtt-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/mqtt/MQTTConnectionManager.java
@@ -107,28 +107,28 @@ public class MQTTConnectionManager {
       return (ServerSessionImpl) serverSession;
    }
 
-   void disconnect() {
+   synchronized void disconnect() {
       if (session == null) {
          return;
       }
+
       try {
+         session.stop();
+         session.getConnection().destroy();
+
+         if (session.getState().isWill()) {
+            session.getConnectionManager().sendWill();
+         }
+      } catch (Exception e) {
+         log.error("Error disconnecting client: " + e.getMessage());
+      } finally {
          if (session.getSessionState() != null) {
+            session.getSessionState().setAttached(false);
             String clientId = session.getSessionState().getClientId();
-            if (clientId != null)
+            if (clientId != null) {
                CONNECTED_CLIENTS.remove(clientId);
-
-            if (session.getState().isWill()) {
-               session.getConnectionManager().sendWill();
             }
          }
-         session.stop();
-         session.getConnection().disconnect(false);
-         session.getConnection().destroy();
-      } catch (Exception e) {
-         /* FIXME Failure during disconnect would leave the session state in an unrecoverable
state.  We should handle
-         errors more gracefully.
-          */
-         log.error("Error disconnecting client: " + e.getMessage());
       }
    }
 
@@ -138,25 +138,19 @@ public class MQTTConnectionManager {
    }
 
    private MQTTSessionState getSessionState(String clientId) throws InterruptedException
{
-      synchronized (MQTTSession.SESSIONS) {
-         /* [MQTT-3.1.2-6] If CleanSession is set to 1, the Client and Server MUST discard
any previous Session and
-          * start a new one  This Session lasts as long as the Network Connection. State
data associated with this Session
-          * MUST NOT be reused in any subsequent Session */
-
-         /* [MQTT-3.1.2-4] Attach an existing session if one exists (if cleanSession flag
is false) otherwise create
-         a new one. */
-         MQTTSessionState state = MQTTSession.SESSIONS.get(clientId);
-         if (state != null) {
-            // TODO Add a count down latch for handling wait during attached session state.
-            while (state.getAttached()) {
-               Thread.sleep(1000);
-            }
-            return state;
-         } else {
-            state = new MQTTSessionState(clientId);
-            MQTTSession.SESSIONS.put(clientId, state);
-            return state;
-         }
+      /* [MQTT-3.1.2-6] If CleanSession is set to 1, the Client and Server MUST discard any
previous Session and
+       * start a new one  This Session lasts as long as the Network Connection. State data
associated with this Session
+       * MUST NOT be reused in any subsequent Session */
+
+      /* [MQTT-3.1.2-4] Attach an existing session if one exists (if cleanSession flag is
false) otherwise create
+      a new one. */
+      MQTTSessionState state = MQTTSession.SESSIONS.get(clientId);
+      if (state != null) {
+         return state;
+      } else {
+         state = new MQTTSessionState(clientId);
+         MQTTSession.SESSIONS.put(clientId, state);
+         return state;
       }
    }
 


Mime
View raw message