Author: rajith
Date: Mon Jan 11 18:15:03 2010
New Revision: 897985

URL: http://svn.apache.org/viewvc?rev=897985&view=rev
Log:
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.

Modified:
    
qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/ClientDelegate.java

Modified: 
qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/ClientDelegate.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/ClientDelegate.java?rev=897985&r1=897984&r2=897985&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/ClientDelegate.java
 (original)
+++ 
qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/ClientDelegate.java
 Mon Jan 11 18:15:03 2010
@@ -22,6 +22,8 @@
 
 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 @@
 
     @Override public void connectionStart(Connection conn, ConnectionStart 
start)
     {
-        Map clientProperties = new HashMap();
+        Map<String,Object> clientProperties = new HashMap<String,Object>();
         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<Object> mechanisms = start.getMechanisms();
         if (mechanisms == null || mechanisms.isEmpty())
         {
@@ -173,4 +179,28 @@
             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;
+        }
+
+    }
 }



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:[email protected]

Reply via email to