summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Wall <kwall@apache.org>2014-12-30 16:48:57 +0000
committerKeith Wall <kwall@apache.org>2014-12-30 16:48:57 +0000
commite249f157f5963cfc458eca1988fb970f086ced72 (patch)
tree362ba05bb4dbf99f5ca5210e092eac40c1b62123
parentfcaa5ff88e5ad15469c54e29d8f0d87821ccf8e1 (diff)
downloadqpid-python-e249f157f5963cfc458eca1988fb970f086ced72.tar.gz
QPID-6293: [Java Broker] Log Java Broker's pid on startup
* Log the process identifer on startup as an operational log message * Wired up the Broker attribute Broker#processPid git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1648545 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/doc/book/src/java-broker/Java-Broker-Appendix-Operational-Logging-Messages.xml9
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/logging/messages/BrokerMessages.java34
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/logging/messages/Broker_logmessages.properties5
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractSystemConfig.java5
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java3
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/properties/ConnectionStartProperties.java27
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/util/SystemUtils.java48
7 files changed, 106 insertions, 25 deletions
diff --git a/qpid/doc/book/src/java-broker/Java-Broker-Appendix-Operational-Logging-Messages.xml b/qpid/doc/book/src/java-broker/Java-Broker-Appendix-Operational-Logging-Messages.xml
index 0c0adffbe3..dbc12dc111 100644
--- a/qpid/doc/book/src/java-broker/Java-Broker-Appendix-Operational-Logging-Messages.xml
+++ b/qpid/doc/book/src/java-broker/Java-Broker-Appendix-Operational-Logging-Messages.xml
@@ -378,6 +378,15 @@
<para>Indicates that broker was shut down due to fatal error.</para>
</entry>
</row>
+ <row id="Java-Broker-Appendix-Operation-Logging-Message-BRK-1017">
+ <entry morerows="1">BRK-1017</entry>
+ <entry>Process : PID <replaceable>process identifier</replaceable></entry>
+ </row>
+ <row>
+ <entry>
+ <para>Process identifier (PID) of the Broker process.</para>
+ </entry>
+ </row>
</tbody>
</tgroup>
</table>
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/logging/messages/BrokerMessages.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/logging/messages/BrokerMessages.java
index cd21f533a4..58f7dfe807 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/logging/messages/BrokerMessages.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/logging/messages/BrokerMessages.java
@@ -54,6 +54,7 @@ public class BrokerMessages
public static final String FLOW_TO_DISK_ACTIVE_LOG_HIERARCHY = DEFAULT_LOG_HIERARCHY_PREFIX + "broker.flow_to_disk_active";
public static final String MAX_MEMORY_LOG_HIERARCHY = DEFAULT_LOG_HIERARCHY_PREFIX + "broker.max_memory";
public static final String PLATFORM_LOG_HIERARCHY = DEFAULT_LOG_HIERARCHY_PREFIX + "broker.platform";
+ public static final String PROCESS_LOG_HIERARCHY = DEFAULT_LOG_HIERARCHY_PREFIX + "broker.process";
public static final String SHUTTING_DOWN_LOG_HIERARCHY = DEFAULT_LOG_HIERARCHY_PREFIX + "broker.shutting_down";
public static final String MANAGEMENT_MODE_LOG_HIERARCHY = DEFAULT_LOG_HIERARCHY_PREFIX + "broker.management_mode";
public static final String STARTUP_LOG_HIERARCHY = DEFAULT_LOG_HIERARCHY_PREFIX + "broker.startup";
@@ -73,6 +74,7 @@ public class BrokerMessages
Logger.getLogger(FLOW_TO_DISK_ACTIVE_LOG_HIERARCHY);
Logger.getLogger(MAX_MEMORY_LOG_HIERARCHY);
Logger.getLogger(PLATFORM_LOG_HIERARCHY);
+ Logger.getLogger(PROCESS_LOG_HIERARCHY);
Logger.getLogger(SHUTTING_DOWN_LOG_HIERARCHY);
Logger.getLogger(MANAGEMENT_MODE_LOG_HIERARCHY);
Logger.getLogger(STARTUP_LOG_HIERARCHY);
@@ -399,6 +401,38 @@ public class BrokerMessages
/**
* Log a Broker message of the Format:
+ * <pre>BRK-1017 : Process : PID : {0}</pre>
+ * Optional values are contained in [square brackets] and are numbered
+ * sequentially in the method call.
+ *
+ */
+ public static LogMessage PROCESS(String param1)
+ {
+ String rawMessage = _messages.getString("PROCESS");
+
+ 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()
+ {
+ public String toString()
+ {
+ return message;
+ }
+
+ public String getLogHierarchy()
+ {
+ return PROCESS_LOG_HIERARCHY;
+ }
+ };
+ }
+
+ /**
+ * Log a Broker message of the Format:
* <pre>BRK-1003 : Shutting down : {0} port {1,number,#}</pre>
* Optional values are contained in [square brackets] and are numbered
* sequentially in the method call.
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/logging/messages/Broker_logmessages.properties b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/logging/messages/Broker_logmessages.properties
index 322335a956..92417b6764 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/logging/messages/Broker_logmessages.properties
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/logging/messages/Broker_logmessages.properties
@@ -54,4 +54,7 @@ MANAGEMENT_MODE = BRK-1012 : Management Mode : User Details : {0} / {1}
FLOW_TO_DISK_ACTIVE = BRK-1014 : Message flow to disk active : Message memory use {0,number,#}KB exceeds threshold {1,number,#.##}KB
FLOW_TO_DISK_INACTIVE = BRK-1015 : Message flow to disk inactive : Message memory use {0,number,#}KB within threshold {1,number,#.##}KB
-FATAL_ERROR = BRK-1016 : Fatal error : {0} : See log file for more information \ No newline at end of file
+FATAL_ERROR = BRK-1016 : Fatal error : {0} : See log file for more information
+
+# 0 - pid
+PROCESS = BRK-1017 : Process : PID : {0} \ No newline at end of file
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractSystemConfig.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractSystemConfig.java
index 19918abb14..b421c5aaf1 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractSystemConfig.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractSystemConfig.java
@@ -224,6 +224,11 @@ public abstract class AbstractSystemConfig<X extends SystemConfig<X>>
startupLogger.message(BrokerMessages.MAX_MEMORY(Runtime.getRuntime().maxMemory()));
+ if (SystemUtils.getProcessPid() != null)
+ {
+ startupLogger.message(BrokerMessages.PROCESS(SystemUtils.getProcessPid()));
+ }
+
BrokerStoreUpgraderAndRecoverer upgrader = new BrokerStoreUpgraderAndRecoverer(this);
upgrader.perform();
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java
index ac14308d2d..5975d64f19 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java
@@ -316,8 +316,7 @@ public class BrokerAdapter extends AbstractConfiguredObject<BrokerAdapter> imple
@Override
public String getProcessPid()
{
- // TODO
- return null;
+ return SystemUtils.getProcessPid();
}
@Override
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/properties/ConnectionStartProperties.java b/qpid/java/common/src/main/java/org/apache/qpid/properties/ConnectionStartProperties.java
index 4f88fe7071..3569b4b460 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/properties/ConnectionStartProperties.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/properties/ConnectionStartProperties.java
@@ -20,9 +20,6 @@
*/
package org.apache.qpid.properties;
-import java.lang.management.ManagementFactory;
-import java.lang.management.RuntimeMXBean;
-
import org.apache.qpid.transport.util.Logger;
import org.apache.qpid.util.SystemUtils;
@@ -62,30 +59,18 @@ public class ConnectionStartProperties
public static final String QPID_CONFIRMED_PUBLISH_SUPPORTED = "qpid.confirmed_publish_supported";
- public static int _pid;
+ public static final int _pid;
public static final String _platformInfo;
static
{
- RuntimeMXBean rtb = ManagementFactory.getRuntimeMXBean();
- String processName = rtb.getName();
- if (processName != null && processName.indexOf('@') > 0)
- {
- try
- {
- _pid = Integer.parseInt(processName.substring(0,processName.indexOf('@')));
- }
- catch(Exception e)
- {
- LOGGER.warn("Unable to get the PID due to error",e);
- _pid = -1;
- }
- }
- else
+
+ _pid = SystemUtils.getProcessPidAsInt();
+
+ if (_pid == -1)
{
- LOGGER.warn("Unable to get the PID due to unsupported format : " + processName);
- _pid = -1;
+ LOGGER.warn("Unable to get the process's PID");
}
StringBuilder fullSystemInfo = new StringBuilder(System.getProperty("java.runtime.name"));
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/util/SystemUtils.java b/qpid/java/common/src/main/java/org/apache/qpid/util/SystemUtils.java
index 55c7ae9b96..5825276760 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/util/SystemUtils.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/util/SystemUtils.java
@@ -20,6 +20,9 @@
*/
package org.apache.qpid.util;
+import java.lang.management.ManagementFactory;
+import java.lang.management.RuntimeMXBean;
+
/**
* SystemUtils provides some simple helper methods for working with the current
* Operating System.
@@ -38,9 +41,29 @@ public class SystemUtils
private static final String _osName = System.getProperty("os.name", UNKNOWN_OS);
private static final String _osVersion = System.getProperty("os.version", UNKNOWN_VERSION);
private static final String _osArch = System.getProperty("os.arch", UNKNOWN_ARCH);
-
private static final boolean _isWindows = _osName.toLowerCase().contains("windows");
+ /** Process identifier of underlying process or null if it cannot be determined */
+ private static final String _osPid;
+ private static int _osPidInt;
+
+ static
+ {
+ RuntimeMXBean rtb = ManagementFactory.getRuntimeMXBean();
+ String processName = rtb.getName();
+ int atIndex;
+ if(processName != null && (atIndex = processName.indexOf('@')) > 0)
+ {
+ _osPid = processName.substring(0, atIndex);
+ _osPidInt = parseInt(_osPid, -1);
+ }
+ else
+ {
+ _osPid = null;
+ }
+ }
+
+
private SystemUtils()
{
}
@@ -60,6 +83,16 @@ public class SystemUtils
return _osArch;
}
+ public final static String getProcessPid()
+ {
+ return _osPid;
+ }
+
+ public final static int getProcessPidAsInt()
+ {
+ return _osPidInt;
+ }
+
public final static boolean isWindows()
{
return _isWindows;
@@ -78,4 +111,17 @@ public class SystemUtils
{
return _osName + " " + _osVersion + " " + _osArch;
}
+
+ private static int parseInt(String str, int defaultVal)
+ {
+ try
+ {
+ return Integer.parseInt(str);
+ }
+ catch(NumberFormatException e)
+ {
+ return defaultVal;
+ }
+ }
+
}