QPID-8091: [Broker-J] Report connection close reason as part of operational log 
message

(cherry picked from commit 53cf0201a3d363f3e5f18ef758fd8a6fc3d22b4c)


Project: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/commit/f84a341c
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/f84a341c
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/f84a341c

Branch: refs/heads/7.0.x
Commit: f84a341c9f05ad53c1a86a19dd55509e45423a51
Parents: 16bd395
Author: Alex Rudyy <oru...@apache.org>
Authored: Thu Feb 8 14:40:02 2018 +0000
Committer: Alex Rudyy <oru...@apache.org>
Committed: Mon Feb 19 18:14:04 2018 +0000

----------------------------------------------------------------------
 .../logging/messages/ConnectionMessages.java    | 34 ++++++++++++++++++--
 .../messages/Connection_logmessages.properties  |  2 +-
 .../transport/AbstractAMQPConnection.java       |  5 ++-
 .../messages/ConnectionMessagesTest.java        | 11 ++++++-
 .../protocol/v0_10/AMQPConnection_0_10Impl.java |  8 +++++
 .../protocol/v0_8/AMQPConnection_0_8Impl.java   | 17 +++++++++-
 .../protocol/v1_0/AMQPConnection_1_0Impl.java   | 15 +++++----
 7 files changed, 78 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/f84a341c/broker-core/src/main/java/org/apache/qpid/server/logging/messages/ConnectionMessages.java
----------------------------------------------------------------------
diff --git 
a/broker-core/src/main/java/org/apache/qpid/server/logging/messages/ConnectionMessages.java
 
b/broker-core/src/main/java/org/apache/qpid/server/logging/messages/ConnectionMessages.java
index 7708ce7..6b2ef11 100644
--- 
a/broker-core/src/main/java/org/apache/qpid/server/logging/messages/ConnectionMessages.java
+++ 
b/broker-core/src/main/java/org/apache/qpid/server/logging/messages/ConnectionMessages.java
@@ -211,16 +211,44 @@ public class ConnectionMessages
 
     /**
      * Log a Connection message of the Format:
-     * <pre>CON-1002 : Close</pre>
+     * <pre>CON-1002 : Close[ : {0}]</pre>
      * Optional values are contained in [square brackets] and are numbered
      * sequentially in the method call.
      *
      */
-    public static LogMessage CLOSE()
+    public static LogMessage CLOSE(String param1, boolean opt1)
     {
         String rawMessage = _messages.getString("CLOSE");
+        StringBuffer msg = new StringBuffer();
 
-        final String message = rawMessage;
+        // Split the formatted message up on the option values so we can
+        // rebuild the message based on the configured options.
+        String[] parts = rawMessage.split("\\[");
+        msg.append(parts[0]);
+
+        int end;
+        if (parts.length > 1)
+        {
+
+            // Add Option : : {0}.
+            end = parts[1].indexOf(']');
+            if (opt1)
+            {
+                msg.append(parts[1].substring(0, end));
+            }
+
+            // Use 'end + 1' to remove the ']' from the output
+            msg.append(parts[1].substring(end + 1));
+        }
+
+        rawMessage = msg.toString();
+
+        final Object[] messageArguments = {param1};
+        // Create a new MessageFormat to ensure thread safety.
+        // Sharing a MessageFormat and using applyPattern is not thread safe
+        MessageFormat formatter = new MessageFormat(rawMessage, 
_currentLocale);
+
+        final String message = formatter.format(messageArguments);
 
         return new LogMessage()
         {

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/f84a341c/broker-core/src/main/java/org/apache/qpid/server/logging/messages/Connection_logmessages.properties
----------------------------------------------------------------------
diff --git 
a/broker-core/src/main/java/org/apache/qpid/server/logging/messages/Connection_logmessages.properties
 
b/broker-core/src/main/java/org/apache/qpid/server/logging/messages/Connection_logmessages.properties
index 5238559..f66a04c 100644
--- 
a/broker-core/src/main/java/org/apache/qpid/server/logging/messages/Connection_logmessages.properties
+++ 
b/broker-core/src/main/java/org/apache/qpid/server/logging/messages/Connection_logmessages.properties
@@ -19,7 +19,7 @@
 # Default File used for all non-defined locales.
 
 OPEN = CON-1001 : Open : Destination : {0}({1}) : Protocol Version : {2}[ : 
SSL][ : Client ID : {3}][ : Client Version : {4}][ : Client Product : {5}]
-CLOSE = CON-1002 : Close
+CLOSE = CON-1002 : Close[ : {0}]
 IDLE_CLOSE = CON-1003 : Closed due to inactivity [: {0}]
 DROPPED_CONNECTION = CON-1004 : Connection dropped
 CLIENT_VERSION_LOG = CON-1005 : Client version "{0}" logged by validation

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/f84a341c/broker-core/src/main/java/org/apache/qpid/server/transport/AbstractAMQPConnection.java
----------------------------------------------------------------------
diff --git 
a/broker-core/src/main/java/org/apache/qpid/server/transport/AbstractAMQPConnection.java
 
b/broker-core/src/main/java/org/apache/qpid/server/transport/AbstractAMQPConnection.java
index 944d3bc..ab4fcd9 100644
--- 
a/broker-core/src/main/java/org/apache/qpid/server/transport/AbstractAMQPConnection.java
+++ 
b/broker-core/src/main/java/org/apache/qpid/server/transport/AbstractAMQPConnection.java
@@ -745,8 +745,9 @@ public abstract class AbstractAMQPConnection<C extends 
AbstractAMQPConnection<C,
             @Override
             public Void run()
             {
+                String closeCause = getCloseCause();
                 getEventLogger().message(isOrderlyClose()
-                                                 ? ConnectionMessages.CLOSE()
+                                                 ? 
ConnectionMessages.CLOSE(closeCause, closeCause != null)
                                                  : 
ConnectionMessages.DROPPED_CONNECTION());
                 return null;
             }
@@ -770,6 +771,8 @@ public abstract class AbstractAMQPConnection<C extends 
AbstractAMQPConnection<C,
 
     protected abstract boolean isOrderlyClose();
 
+    protected abstract String getCloseCause();
+
     @Override
     public int getSessionCount()
     {

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/f84a341c/broker-core/src/test/java/org/apache/qpid/server/logging/messages/ConnectionMessagesTest.java
----------------------------------------------------------------------
diff --git 
a/broker-core/src/test/java/org/apache/qpid/server/logging/messages/ConnectionMessagesTest.java
 
b/broker-core/src/test/java/org/apache/qpid/server/logging/messages/ConnectionMessagesTest.java
index c820107..058f8b1 100644
--- 
a/broker-core/src/test/java/org/apache/qpid/server/logging/messages/ConnectionMessagesTest.java
+++ 
b/broker-core/src/test/java/org/apache/qpid/server/logging/messages/ConnectionMessagesTest.java
@@ -85,7 +85,7 @@ public class ConnectionMessagesTest extends 
AbstractTestMessages
 
     public void testConnectionClose()
     {
-        _logMessage = ConnectionMessages.CLOSE();
+        _logMessage = ConnectionMessages.CLOSE(null, false);
         List<Object> log = performLog();
 
         String[] expected = {"Close"};
@@ -93,4 +93,13 @@ public class ConnectionMessagesTest extends 
AbstractTestMessages
         validateLogMessage(log, "CON-1002", expected);
     }
 
+    public void testConnectionCloseWithCause()
+    {
+        _logMessage = ConnectionMessages.CLOSE("Test", true);
+        List<Object> log = performLog();
+
+        String[] expected = {"Close : Test"};
+
+        validateLogMessage(log, "CON-1002", expected);
+    }
 }

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/f84a341c/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/AMQPConnection_0_10Impl.java
----------------------------------------------------------------------
diff --git 
a/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/AMQPConnection_0_10Impl.java
 
b/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/AMQPConnection_0_10Impl.java
index e09b48a..3c9fbd1 100755
--- 
a/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/AMQPConnection_0_10Impl.java
+++ 
b/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/AMQPConnection_0_10Impl.java
@@ -72,6 +72,7 @@ public class AMQPConnection_0_10Impl extends 
AbstractAMQPConnection<AMQPConnecti
 
     private final Set<AMQPSession<?,?>> _sessionsWithWork =
             Collections.newSetFromMap(new ConcurrentHashMap<AMQPSession<?,?>, 
Boolean>());
+    private volatile String _closeCause;
 
 
     public AMQPConnection_0_10Impl(final Broker<?> broker,
@@ -301,6 +302,7 @@ public class AMQPConnection_0_10Impl extends 
AbstractAMQPConnection<AMQPConnecti
     @Override
     public void sendConnectionCloseAsync(final CloseReason reason, final 
String description)
     {
+        _closeCause = description;
         stopConnection();
         // Best mapping for all reasons is "forced"
         
_connection.sendConnectionCloseAsync(ConnectionCloseCode.CONNECTION_FORCED, 
description);
@@ -361,6 +363,12 @@ public class AMQPConnection_0_10Impl extends 
AbstractAMQPConnection<AMQPConnecti
     }
 
     @Override
+    protected String getCloseCause()
+    {
+        return _closeCause;
+    }
+
+    @Override
     public void initialiseHeartbeating(final long writerDelay, final long 
readerDelay)
     {
         super.initialiseHeartbeating(writerDelay, readerDelay);

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/f84a341c/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/AMQPConnection_0_8Impl.java
----------------------------------------------------------------------
diff --git 
a/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/AMQPConnection_0_8Impl.java
 
b/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/AMQPConnection_0_8Impl.java
index 0a2e323..eca6d8a 100644
--- 
a/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/AMQPConnection_0_8Impl.java
+++ 
b/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/AMQPConnection_0_8Impl.java
@@ -163,6 +163,9 @@ public class AMQPConnection_0_8Impl
             Collections.newSetFromMap(new ConcurrentHashMap<AMQPSession<?,?>, 
Boolean>());
 
     private volatile int _heartBeatDelay;
+    private volatile String _closeCause;
+    private volatile int _closeCauseCode;
+
 
     public AMQPConnection_0_8Impl(Broker<?> broker,
                                   ServerNetworkConnection network,
@@ -486,7 +489,7 @@ public class AMQPConnection_0_8Impl
             {
                 try
                 {
-                    channel.close();
+                    channel.close(_closeCauseCode, _closeCause);
                 }
                 catch (RuntimeException re)
                 {
@@ -699,6 +702,16 @@ public class AMQPConnection_0_8Impl
     }
 
     @Override
+    protected String getCloseCause()
+    {
+        if (_closeCause == null)
+        {
+            return null;
+        }
+        return _closeCauseCode + " - " + _closeCause;
+    }
+
+    @Override
     public void encryptedTransport()
     {
     }
@@ -794,6 +807,8 @@ public class AMQPConnection_0_8Impl
             default:
                 cause = ErrorCodes.INTERNAL_ERROR;
         }
+        _closeCauseCode = cause;
+        _closeCause = description;
         Action<AMQPConnection_0_8Impl> action = new 
Action<AMQPConnection_0_8Impl>()
         {
             @Override

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/f84a341c/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/AMQPConnection_1_0Impl.java
----------------------------------------------------------------------
diff --git 
a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/AMQPConnection_1_0Impl.java
 
b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/AMQPConnection_1_0Impl.java
index e440187..03954b4 100644
--- 
a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/AMQPConnection_1_0Impl.java
+++ 
b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/AMQPConnection_1_0Impl.java
@@ -50,7 +50,6 @@ import java.util.concurrent.atomic.AtomicReference;
 import java.util.stream.Collectors;
 import java.util.stream.StreamSupport;
 
-import com.google.common.base.Supplier;
 import com.google.common.collect.Iterators;
 import com.google.common.collect.PeekingIterator;
 import com.google.common.collect.Sets;
@@ -59,15 +58,12 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
-import org.apache.qpid.server.logging.EventLogger;
-import org.apache.qpid.server.logging.messages.ChannelMessages;
 import org.apache.qpid.server.logging.messages.ConnectionMessages;
 import org.apache.qpid.server.model.AuthenticationProvider;
 import org.apache.qpid.server.model.Broker;
 import org.apache.qpid.server.model.Connection;
 import org.apache.qpid.server.model.NamedAddressSpace;
 import org.apache.qpid.server.model.Protocol;
-import org.apache.qpid.server.model.Session;
 import org.apache.qpid.server.model.Transport;
 import org.apache.qpid.server.model.port.AmqpPort;
 import org.apache.qpid.server.plugin.ConnectionPropertyEnricher;
@@ -128,15 +124,12 @@ import org.apache.qpid.server.transport.AggregateTicker;
 import org.apache.qpid.server.transport.ByteBufferSender;
 import org.apache.qpid.server.transport.ProtocolEngine;
 import org.apache.qpid.server.transport.ServerNetworkConnection;
-import org.apache.qpid.server.transport.TransactionTimeoutTicker;
-import org.apache.qpid.server.transport.network.Ticker;
 import org.apache.qpid.server.transport.util.Functions;
 import org.apache.qpid.server.txn.LocalTransaction;
 import org.apache.qpid.server.txn.ServerTransaction;
 import org.apache.qpid.server.util.Action;
 import org.apache.qpid.server.util.ConnectionScopedRuntimeException;
 import org.apache.qpid.server.util.ServerScopedRuntimeException;
-import org.apache.qpid.server.virtualhost.QueueManagingVirtualHost;
 import org.apache.qpid.server.virtualhost.VirtualHostUnavailableException;
 
 public class AMQPConnection_1_0Impl extends 
AbstractAMQPConnection<AMQPConnection_1_0Impl, ConnectionHandler>
@@ -243,6 +236,7 @@ public class AMQPConnection_1_0Impl extends 
AbstractAMQPConnection<AMQPConnectio
     // Multi session transactions
     private volatile ServerTransaction[] _openTransactions = new 
ServerTransaction[16];
     private volatile boolean _sendSaslFinalChallengeAsChallenge;
+    private volatile String _closeCause;
 
     AMQPConnection_1_0Impl(final Broker<?> broker,
                            final ServerNetworkConnection network,
@@ -1172,6 +1166,7 @@ public class AMQPConnection_1_0Impl extends 
AbstractAMQPConnection<AMQPConnectio
 
     private void closeConnection(final Error error)
     {
+        _closeCause = error.getDescription();
         Close close = new Close();
         close.setError(error);
         switch (_connectionState)
@@ -1710,6 +1705,12 @@ public class AMQPConnection_1_0Impl extends 
AbstractAMQPConnection<AMQPConnectio
     }
 
     @Override
+    protected String getCloseCause()
+    {
+        return _closeCause;
+    }
+
+    @Override
     public boolean getSendSaslFinalChallengeAsChallenge()
     {
         return _sendSaslFinalChallengeAsChallenge;


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org
For additional commands, e-mail: commits-h...@qpid.apache.org

Reply via email to