From dd9365811468be2dbb6bb34f5942bbe87ec4c830 Mon Sep 17 00:00:00 2001 From: Rajith Muditha Attapattu Date: Mon, 11 Jan 2010 18:15:03 +0000 Subject: This is a fix for QPID-2173 The qpid.client_process could also be set to something more descriptive as follows using a jvm argument. -Dqpid.client_process="My Billing App" Currently added the prop names as plain strings. They will be moved to a single location as part of wider effort in organizing our configuration. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@897985 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/qpid/transport/ClientDelegate.java | 34 ++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'java/common/src') diff --git a/java/common/src/main/java/org/apache/qpid/transport/ClientDelegate.java b/java/common/src/main/java/org/apache/qpid/transport/ClientDelegate.java index 09d91ae6c6..934d8f2949 100644 --- a/java/common/src/main/java/org/apache/qpid/transport/ClientDelegate.java +++ b/java/common/src/main/java/org/apache/qpid/transport/ClientDelegate.java @@ -22,6 +22,8 @@ package org.apache.qpid.transport; import static org.apache.qpid.transport.Connection.State.OPEN; +import java.lang.management.ManagementFactory; +import java.lang.management.RuntimeMXBean; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -73,9 +75,13 @@ public class ClientDelegate extends ConnectionDelegate @Override public void connectionStart(Connection conn, ConnectionStart start) { - Map clientProperties = new HashMap(); + Map clientProperties = new HashMap(); clientProperties.put("qpid.session_flow", 1); - + clientProperties.put("qpid.client_pid",getPID()); + clientProperties.put("qpid.client_pid",clientProperties.get("qpid.client_pid")); + clientProperties.put("qpid.client_process", + System.getProperty("qpid.client_process","Qpid Java Client")); + List mechanisms = start.getMechanisms(); if (mechanisms == null || mechanisms.isEmpty()) { @@ -173,4 +179,28 @@ public class ClientDelegate extends ConnectionDelegate return max; } } + + private int getPID() + { + RuntimeMXBean rtb = ManagementFactory.getRuntimeMXBean(); + String processName = rtb.getName(); + if (processName != null && processName.indexOf('@')>0) + { + try + { + return Integer.parseInt(processName.substring(0,processName.indexOf('@'))); + } + catch(Exception e) + { + log.warn("Unable to get the client PID due to error",e); + return -1; + } + } + else + { + log.warn("Unable to get the client PID due to unsupported format : " + processName); + return -1; + } + + } } -- cgit v1.2.1