cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [11/14] cxf git commit: Cache the object names to help performance
Date Mon, 25 Jul 2016 15:30:45 GMT
Cache the object names to help performance

# Conflicts:
#	rt/management/src/main/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTimeInterceptor.java
#	rt/management/src/test/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTestBase.java


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/0d7ec247
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/0d7ec247
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/0d7ec247

Branch: refs/heads/3.0.x-fixes
Commit: 0d7ec2470afdb9413dfd2cb37b49ae1d9e07d6ff
Parents: 1dbc471
Author: Daniel Kulp <dkulp@apache.org>
Authored: Mon Jun 20 12:24:42 2016 -0400
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Mon Jul 25 10:27:35 2016 -0400

----------------------------------------------------------------------
 .../AbstractMessageResponseTimeInterceptor.java | 70 ++++++++++++--------
 .../AbstractMessageResponseTestBase.java        | 16 ++++-
 2 files changed, 56 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/0d7ec247/rt/management/src/main/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTimeInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/management/src/main/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTimeInterceptor.java
b/rt/management/src/main/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTimeInterceptor.java
index 92f9dc4..76bb5e9 100644
--- a/rt/management/src/main/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTimeInterceptor.java
+++ b/rt/management/src/main/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTimeInterceptor.java
@@ -113,34 +113,44 @@ public abstract class AbstractMessageResponseTimeInterceptor extends
AbstractPha
     protected ObjectName getServiceCounterName(Exchange ex) {
         Bus bus = ex.get(Bus.class);
         StringBuilder buffer = new StringBuilder();
+        ObjectName serviceCounterName = null;
         if (ex.get("org.apache.cxf.management.service.counter.name") != null) {
             buffer.append((String)ex.get("org.apache.cxf.management.service.counter.name"));
+            try {
+                serviceCounterName = new ObjectName(buffer.toString());
+            } catch (MalformedObjectNameException e) {
+                LOG.log(Level.WARNING, "CREATE_COUNTER_OBJECTNAME_FAILED", e);
+            }
         } else {
             Service service = ex.get(Service.class);
             Endpoint endpoint = ex.get(Endpoint.class);
-
-            String serviceName = "\"" + escapePatternChars(service.getName().toString())
+ "\"";
-            String portName = "\"" + endpoint.getEndpointInfo().getName().getLocalPart()
+ "\"";
-
-            buffer.append(ManagementConstants.DEFAULT_DOMAIN_NAME + ":");
-            buffer.append(ManagementConstants.BUS_ID_PROP + "=" + bus.getId() + ",");
-            Message message = ex.getOutMessage();
-            if (isClient(message)) {
-                buffer.append(ManagementConstants.TYPE_PROP + "=" + Counter.PERFORMANCE_COUNTER
-                              + ".Client,");
-            } else {
-                buffer.append(ManagementConstants.TYPE_PROP + "=" + Counter.PERFORMANCE_COUNTER
-                              + ".Server,");
+                
+            serviceCounterName = (ObjectName)endpoint.get("javax.management.ObjectName");
+            if (serviceCounterName == null) {
+                String serviceName = "\"" + escapePatternChars(service.getName().toString())
+ "\"";
+                String portName = "\"" + endpoint.getEndpointInfo().getName().getLocalPart()
+ "\"";
+    
+                buffer.append(ManagementConstants.DEFAULT_DOMAIN_NAME + ":");
+                buffer.append(ManagementConstants.BUS_ID_PROP + "=" + bus.getId() + ",");
+                Message message = ex.getOutMessage();
+                if (isClient(message)) {
+                    buffer.append(ManagementConstants.TYPE_PROP + "=" + Counter.PERFORMANCE_COUNTER
+                                  + ".Client,");
+                } else {
+                    buffer.append(ManagementConstants.TYPE_PROP + "=" + Counter.PERFORMANCE_COUNTER
+                                  + ".Server,");
+                }
+                buffer.append(ManagementConstants.SERVICE_NAME_PROP + "=" + serviceName +
",");
+    
+                buffer.append(ManagementConstants.PORT_NAME_PROP + "=" + portName);
+                
+                try {
+                    serviceCounterName = new ObjectName(buffer.toString());
+                    endpoint.put("javax.management.ObjectName", serviceCounterName);
+                } catch (MalformedObjectNameException e) {
+                    LOG.log(Level.WARNING, "CREATE_COUNTER_OBJECTNAME_FAILED", e);
+                }
             }
-            buffer.append(ManagementConstants.SERVICE_NAME_PROP + "=" + serviceName + ",");
-
-            buffer.append(ManagementConstants.PORT_NAME_PROP + "=" + portName);
-        }
-        ObjectName serviceCounterName = null;
-        try {
-            serviceCounterName = new ObjectName(buffer.toString());
-        } catch (MalformedObjectNameException e) {
-            LOG.log(Level.WARNING, "CREATE_COUNTER_OBJECTNAME_FAILED", e);
         }
         return serviceCounterName;
         
@@ -162,7 +172,14 @@ public abstract class AbstractMessageResponseTimeInterceptor extends
AbstractPha
     }
     
     protected ObjectName getOperationCounterName(Exchange ex, ObjectName sericeCounterName)
{
-        OperationInfo opInfo = ex.get(OperationInfo.class);
+        BindingOperationInfo bop = ex.getBindingOperationInfo();
+        OperationInfo opInfo = bop == null ? null : bop.getOperationInfo();
+        if (opInfo != null) {
+            ObjectName o = opInfo.getProperty("javax.management.ObjectName", ObjectName.class);
+            if (o != null) {
+                return o;
+            }
+        }
         String operationName = opInfo == null ? null : "\"" + opInfo.getName().getLocalPart()
+ "\"";
 
         if (operationName == null) {
@@ -179,16 +196,15 @@ public abstract class AbstractMessageResponseTimeInterceptor extends
AbstractPha
         ObjectName operationCounter = null;
         try {
             operationCounter = new ObjectName(operationCounterName);
-            
+            if (opInfo != null) {
+                opInfo.setProperty("javax.management.ObjectName", operationCounter);
+            }
         } catch (MalformedObjectNameException e) {
             LOG.log(Level.WARNING, "CREATE_COUNTER_OBJECTNAME_FAILED", e);
         }
         return operationCounter;
         
     }
-    
-    
-
     protected String escapePatternChars(String value) {
         // This can be replaced if really needed with pattern-based matching
         if (value.lastIndexOf(QUESTION_MARK) != -1) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/0d7ec247/rt/management/src/test/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTestBase.java
----------------------------------------------------------------------
diff --git a/rt/management/src/test/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTestBase.java
b/rt/management/src/test/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTestBase.java
index 751f903..15ffa71 100644
--- a/rt/management/src/test/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTestBase.java
+++ b/rt/management/src/test/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTestBase.java
@@ -118,6 +118,10 @@ public class AbstractMessageResponseTestBase extends Assert {
         EasyMock.expect(endpointInfo.getName()).andReturn(PORT_NAME).anyTimes();
         EasyMock.expect(endpoint.getEndpointInfo()).andReturn(endpointInfo).anyTimes();
         EasyMock.expect(exchange.get(Endpoint.class)).andReturn(endpoint).anyTimes();
+        EasyMock.expect(endpoint.get("javax.management.ObjectName")).andReturn(null).anyTimes();
+        EasyMock.expect(endpoint.put(EasyMock.eq("javax.management.ObjectName"), EasyMock.anyObject(ObjectName.class)))
+            .andReturn(null).anyTimes();
+        EasyMock.expect(exchange.getEndpoint()).andReturn(endpoint).anyTimes();
         EasyMock.replay(endpointInfo);
         EasyMock.replay(endpoint);
         
@@ -128,9 +132,15 @@ public class AbstractMessageResponseTestBase extends Assert {
       
     protected void setupOperationForMessage() {
         OperationInfo op = EasyMock.createMock(OperationInfo.class);
-        EasyMock.expect(op.getName()).andReturn(OPERATION_NAME);        
-        EasyMock.expect(exchange.get(OperationInfo.class)).andReturn(op);
-        EasyMock.replay(op);
+        BindingOperationInfo bop = EasyMock.createMock(BindingOperationInfo.class);
+        EasyMock.expect(exchange.getBindingOperationInfo()).andReturn(bop);
+        EasyMock.expect(bop.getOperationInfo()).andReturn(op);
+        EasyMock.expect(op.getName()).andReturn(OPERATION_NAME);
+        EasyMock.expect(op.getProperty("javax.management.ObjectName", ObjectName.class)).andReturn(null).anyTimes();
+        op.setProperty(EasyMock.eq("javax.management.ObjectName"),
+                                       EasyMock.anyObject(ObjectName.class));
+        EasyMock.expectLastCall();
+        EasyMock.replay(bop, op);
     }
 
 }


Mime
View raw message