summaryrefslogtreecommitdiff
path: root/qpid/java/common
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 /qpid/java/common
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
Diffstat (limited to 'qpid/java/common')
-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
2 files changed, 53 insertions, 22 deletions
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;
+ }
+ }
+
}