This is an automated email from the ASF dual-hosted git repository.

vavrtom pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-broker-j.git


The following commit(s) were added to refs/heads/main by this push:
     new 50f6ae6db3 QPID-8702: [Broker-J] Log all broker connection attempts 
(#301)
50f6ae6db3 is described below

commit 50f6ae6db3b2e7278745a21398c995120538120f
Author: Daniil Kirilyuk <[email protected]>
AuthorDate: Wed Jul 30 08:49:51 2025 +0200

    QPID-8702: [Broker-J] Log all broker connection attempts (#301)
    
    Co-authored-by: vavrtom <[email protected]>
---
 .../server/logging/messages/NetworkMessages.java   | 203 +++++++++++++++++++++
 .../messages/Network_logmessages.properties        |  22 +++
 .../server/transport/AbstractAMQPConnection.java   |  12 +-
 .../server/transport/NonBlockingConnection.java    |  11 ++
 .../server/transport/ServerNetworkConnection.java  |  11 ++
 ...roker-Appendix-Operational-Logging-Messages.xml |  39 ++++
 6 files changed, 287 insertions(+), 11 deletions(-)

diff --git 
a/broker-core/src/main/java/org/apache/qpid/server/logging/messages/NetworkMessages.java
 
b/broker-core/src/main/java/org/apache/qpid/server/logging/messages/NetworkMessages.java
new file mode 100644
index 0000000000..abc8e3e5bb
--- /dev/null
+++ 
b/broker-core/src/main/java/org/apache/qpid/server/logging/messages/NetworkMessages.java
@@ -0,0 +1,203 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ *
+ */
+package org.apache.qpid.server.logging.messages;
+
+import static 
org.apache.qpid.server.logging.AbstractMessageLogger.DEFAULT_LOG_HIERARCHY_PREFIX;
+
+import java.text.MessageFormat;
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+import org.slf4j.LoggerFactory;
+
+import org.apache.qpid.server.logging.LogMessage;
+
+/**
+ * DO NOT EDIT DIRECTLY, THIS FILE WAS GENERATED.
+ *
+ * Generated using GenerateLogMessages and LogMessages.vm
+ * This file is based on the content of Network_logmessages.properties
+ *
+ * To regenerate, use Maven lifecycle generates-sources with -Dgenerate=true
+ */
+public class NetworkMessages
+{
+    private static final ResourceBundle MESSAGES;
+    private static final Locale CURRENT_LOCALE;
+
+    static
+    {
+        Locale locale = Locale.US;
+        String localeSetting = System.getProperty("qpid.broker_locale");
+        if (localeSetting != null)
+        {
+            String[] localeParts = localeSetting.split("_");
+            String language = (localeParts.length > 0 ? localeParts[0] : "");
+            String country = (localeParts.length > 1 ? localeParts[1] : "");
+            String variant = "";
+            if (localeParts.length > 2)
+            {
+                variant = localeSetting.substring(language.length() + 1 + 
country.length() + 1);
+            }
+            locale = new Locale(language, country, variant);
+        }
+        CURRENT_LOCALE = locale;
+    }
+
+    public static final String NETWORK_LOG_HIERARCHY = 
DEFAULT_LOG_HIERARCHY_PREFIX + "network";
+    public static final String CLOSED_LOG_HIERARCHY = 
DEFAULT_LOG_HIERARCHY_PREFIX + "network.closed";
+    public static final String OPEN_LOG_HIERARCHY = 
DEFAULT_LOG_HIERARCHY_PREFIX + "network.open";
+
+    static
+    {
+        LoggerFactory.getLogger(NETWORK_LOG_HIERARCHY);
+        LoggerFactory.getLogger(CLOSED_LOG_HIERARCHY);
+        LoggerFactory.getLogger(OPEN_LOG_HIERARCHY);
+
+        MESSAGES = 
ResourceBundle.getBundle("org.apache.qpid.server.logging.messages.Network_logmessages",
 CURRENT_LOCALE);
+    }
+
+    /**
+     * Log a Network message of the Format:
+     * <pre>NET-1002 : Close : Destination : {0}({1}) : Source {2}</pre>
+     * Optional values are contained in [square brackets] and are numbered
+     * sequentially in the method call.
+     *
+     */
+    public static LogMessage CLOSED(CharSequence param1, CharSequence param2, 
CharSequence param3)
+    {
+        String rawMessage = MESSAGES.getString("CLOSED");
+
+        final Object[] messageArguments = {param1, param2, param3};
+        // Create a new MessageFormat to ensure thread safety.
+        // Sharing a MessageFormat and using applyPattern is not thread safe
+        MessageFormat formatter = new MessageFormat(rawMessage, 
CURRENT_LOCALE);
+
+        final String message = formatter.format(messageArguments);
+
+        return new LogMessage()
+        {
+            @Override
+            public String toString()
+            {
+                return message;
+            }
+
+            @Override
+            public String getLogHierarchy()
+            {
+                return CLOSED_LOG_HIERARCHY;
+            }
+
+            @Override
+            public boolean equals(final Object o)
+            {
+                if (this == o)
+                {
+                    return true;
+                }
+                if (o == null || getClass() != o.getClass())
+                {
+                    return false;
+                }
+
+                final LogMessage that = (LogMessage) o;
+
+                return getLogHierarchy().equals(that.getLogHierarchy()) && 
toString().equals(that.toString());
+
+            }
+
+            @Override
+            public int hashCode()
+            {
+                int result = toString().hashCode();
+                result = 31 * result + getLogHierarchy().hashCode();
+                return result;
+            }
+        };
+    }
+
+    /**
+     * Log a Network message of the Format:
+     * <pre>NET-1001 : Open : Destination : {0}({1}) : Source {2}</pre>
+     * Optional values are contained in [square brackets] and are numbered
+     * sequentially in the method call.
+     *
+     */
+    public static LogMessage OPEN(CharSequence param1, CharSequence param2, 
CharSequence param3)
+    {
+        String rawMessage = MESSAGES.getString("OPEN");
+
+        final Object[] messageArguments = {param1, param2, param3};
+        // Create a new MessageFormat to ensure thread safety.
+        // Sharing a MessageFormat and using applyPattern is not thread safe
+        MessageFormat formatter = new MessageFormat(rawMessage, 
CURRENT_LOCALE);
+
+        final String message = formatter.format(messageArguments);
+
+        return new LogMessage()
+        {
+            @Override
+            public String toString()
+            {
+                return message;
+            }
+
+            @Override
+            public String getLogHierarchy()
+            {
+                return OPEN_LOG_HIERARCHY;
+            }
+
+            @Override
+            public boolean equals(final Object o)
+            {
+                if (this == o)
+                {
+                    return true;
+                }
+                if (o == null || getClass() != o.getClass())
+                {
+                    return false;
+                }
+
+                final LogMessage that = (LogMessage) o;
+
+                return getLogHierarchy().equals(that.getLogHierarchy()) && 
toString().equals(that.toString());
+
+            }
+
+            @Override
+            public int hashCode()
+            {
+                int result = toString().hashCode();
+                result = 31 * result + getLogHierarchy().hashCode();
+                return result;
+            }
+        };
+    }
+
+
+    private NetworkMessages()
+    {
+    }
+
+}
diff --git 
a/broker-core/src/main/java/org/apache/qpid/server/logging/messages/Network_logmessages.properties
 
b/broker-core/src/main/java/org/apache/qpid/server/logging/messages/Network_logmessages.properties
new file mode 100644
index 0000000000..f59ccbb8a3
--- /dev/null
+++ 
b/broker-core/src/main/java/org/apache/qpid/server/logging/messages/Network_logmessages.properties
@@ -0,0 +1,22 @@
+#
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing,
+#  software distributed under the License is distributed on an
+#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+#  specific language governing permissions and limitations
+#  under the License.
+#
+# Default File used for all non-defined locales.
+
+OPEN = NET-1001 : Open : Destination : {0}({1}) : Source {2}
+CLOSED = NET-1002 : Close : Destination : {0}({1}) : Source {2}
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 481420e941..2e05a38108 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
@@ -765,17 +765,7 @@ public abstract class AbstractAMQPConnection<C extends 
AbstractAMQPConnection<C,
     {
         runAsSubject(() ->
         {
-            SocketAddress localAddress = _network.getLocalAddress();
-            final String localAddressStr;
-            if (localAddress instanceof InetSocketAddress)
-            {
-                InetSocketAddress inetAddress = (InetSocketAddress) 
localAddress;
-                localAddressStr = inetAddress.getAddress().getHostAddress() + 
":" + inetAddress.getPort();
-            }
-            else
-            {
-                localAddressStr = localAddress.toString();
-            }
+            final String localAddressStr = _network.formattedLocalAddress();
             
getEventLogger().message(ConnectionMessages.OPEN(getPort().getName(),
                                                              localAddressStr,
                                                              
getProtocol().getProtocolVersion(),
diff --git 
a/broker-core/src/main/java/org/apache/qpid/server/transport/NonBlockingConnection.java
 
b/broker-core/src/main/java/org/apache/qpid/server/transport/NonBlockingConnection.java
index aab4806a2c..d8a8857d82 100644
--- 
a/broker-core/src/main/java/org/apache/qpid/server/transport/NonBlockingConnection.java
+++ 
b/broker-core/src/main/java/org/apache/qpid/server/transport/NonBlockingConnection.java
@@ -40,6 +40,9 @@ 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.NetworkMessages;
+import org.apache.qpid.server.model.Broker;
 import org.apache.qpid.server.model.port.AmqpPort;
 import org.apache.qpid.server.transport.network.TransportEncryption;
 import org.apache.qpid.server.util.ConnectionScopedRuntimeException;
@@ -66,6 +69,7 @@ public class NonBlockingConnection implements 
ServerNetworkConnection, ByteBuffe
     private volatile boolean _partialRead = false;
 
     private final AmqpPort _port;
+    private final EventLogger _eventLogger;
     private final AtomicBoolean _scheduled = new AtomicBoolean();
     private volatile long _scheduledTime;
     private volatile boolean _unexpectedByteBufferSizeReported;
@@ -114,6 +118,9 @@ public class NonBlockingConnection implements 
ServerNetworkConnection, ByteBuffe
         }
         _finalWriteThreshold = port.getContextValue(Integer.class, 
AmqpPort.FINAL_WRITE_THRESHOLD);
         _finalWriteTimeout = port.getContextValue(Long.class, 
AmqpPort.FINAL_WRITE_TIMEOUT);
+
+        final Broker broker = (Broker<?>) port.getParent();
+        _eventLogger = broker.getEventLogger();
     }
 
     String getThreadName()
@@ -139,6 +146,8 @@ public class NonBlockingConnection implements 
ServerNetworkConnection, ByteBuffe
     @Override
     public void start()
     {
+        final String localAddressStr = formattedLocalAddress();
+        _eventLogger.message(NetworkMessages.OPEN(_port.getName(), 
localAddressStr, _remoteSocketAddress));
     }
 
     @Override
@@ -398,6 +407,8 @@ public class NonBlockingConnection implements 
ServerNetworkConnection, ByteBuffe
                 finally
                 {
                     _socketChannel.close();
+                    final String localAddressStr = formattedLocalAddress();
+                    
_eventLogger.message(NetworkMessages.CLOSED(_port.getName(), localAddressStr, 
_remoteSocketAddress));
                 }
             }
             catch (IOException e)
diff --git 
a/broker-core/src/main/java/org/apache/qpid/server/transport/ServerNetworkConnection.java
 
b/broker-core/src/main/java/org/apache/qpid/server/transport/ServerNetworkConnection.java
index 943a480bc0..eab77cb883 100644
--- 
a/broker-core/src/main/java/org/apache/qpid/server/transport/ServerNetworkConnection.java
+++ 
b/broker-core/src/main/java/org/apache/qpid/server/transport/ServerNetworkConnection.java
@@ -19,6 +19,9 @@
 
 package org.apache.qpid.server.transport;
 
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+
 import org.apache.qpid.server.transport.network.NetworkConnection;
 
 public interface ServerNetworkConnection extends NetworkConnection
@@ -32,4 +35,12 @@ public interface ServerNetworkConnection extends 
NetworkConnection
     void 
removeSchedulingDelayNotificationListeners(SchedulingDelayNotificationListener 
listener);
 
     String getSelectedHost();
+
+    default String formattedLocalAddress()
+    {
+        final SocketAddress localAddress = getLocalAddress();
+        return localAddress instanceof final InetSocketAddress inetAddress
+                ? "%s:%s".formatted(inetAddress.getAddress().getHostAddress(), 
inetAddress.getPort())
+                : localAddress.toString();
+    }
 }
diff --git 
a/doc/java-broker/src/docbkx/Java-Broker-Appendix-Operational-Logging-Messages.xml
 
b/doc/java-broker/src/docbkx/Java-Broker-Appendix-Operational-Logging-Messages.xml
index 9b3eabbaf1..5b0152b17e 100644
--- 
a/doc/java-broker/src/docbkx/Java-Broker-Appendix-Operational-Logging-Messages.xml
+++ 
b/doc/java-broker/src/docbkx/Java-Broker-Appendix-Operational-Logging-Messages.xml
@@ -735,6 +735,45 @@
     </tgroup>
   </table>
 
+  <table pgwide="1" 
xml:id="Java-Broker-Appendix-Operation-Logging-Message-List-Network">
+    <title>Network Log Messages</title>
+    <tgroup cols="2">
+      <colspec colnum="1" colname="messageId" colwidth="1*"/>
+      <colspec colnum="2" colname="messageText" colwidth="1*"/>
+      <thead>
+        <row>
+          <entry>Message Id</entry>
+          <entry>Message Text / Purpose</entry>
+        </row>
+      </thead>
+      <tbody>
+        <row xml:id="Java-Broker-Appendix-Operation-Logging-Message-NET-1001">
+          <entry morerows="1">NET-1001</entry>
+          <entry>Open : Destination : <replaceable>target host and 
port</replaceable> : Source
+            <replaceable>source host and port</replaceable></entry>
+        </row>
+        <row>
+          <entry>
+            <para>Indicates that an attempt to establish a connection has been 
performed. The Broker logs one of these message
+              each time a client tries to open a connection. This message 
indicates a socket channel being opened
+              unrelated to protocol version or correctness. It may be used 
e.g. to check network connectivity.</para>
+          </entry>
+        </row>
+        <row xml:id="Java-Broker-Appendix-Operation-Logging-Message-NET-1002">
+          <entry morerows="1">NET-1002</entry>
+          <entry>Close</entry>
+        </row>
+        <row>
+          <entry>
+            <para>Indicates that a socket channel has been closed. This 
message is logged regardless of
+              if the connection is closed normally, or if the connection is 
somehow lost e.g network
+              error.</para>
+          </entry>
+        </row>
+      </tbody>
+    </tgroup>
+  </table>
+
   <table pgwide="1" 
xml:id="Java-Broker-Appendix-Operation-Logging-Message-List-Connection">
     <title>Connection Log Messages</title>
     <tgroup cols="2">


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to