cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [19/48] cxf git commit: Cache the object names to help performance
Date Wed, 29 Jun 2016 22:44:17 GMT
Cache the object names to help performance


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

Branch: refs/heads/master-jaxrs-2.1
Commit: 18a907c98af0e917ce4f35000ff2d93c14603b11
Parents: a1d8f84
Author: Daniel Kulp <dkulp@apache.org>
Authored: Mon Jun 20 12:24:42 2016 -0400
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Mon Jun 20 13:28:27 2016 -0400

----------------------------------------------------------------------
 .../AbstractMessageResponseTimeInterceptor.java | 66 ++++++++++++--------
 .../AbstractMessageResponseTestBase.java        |  7 +++
 2 files changed, 47 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/18a907c9/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 41fe5fd..f1c0e57 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,43 @@ public abstract class AbstractMessageResponseTimeInterceptor extends
AbstractPha
     protected ObjectName getServiceCounterName(Exchange ex) {
         Bus bus = ex.getBus();
         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.getService();
             Endpoint endpoint = ex.getEndpoint();
-
-            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;
         
@@ -161,6 +170,12 @@ public abstract class AbstractMessageResponseTimeInterceptor extends
AbstractPha
     protected ObjectName getOperationCounterName(Exchange ex, ObjectName sericeCounterName)
{
         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) {
@@ -177,16 +192,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/18a907c9/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 122396b..59f0c46 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,9 @@ public class AbstractMessageResponseTestBase extends Assert {
         EndpointInfo endpointInfo = EasyMock.createMock(EndpointInfo.class);
         EasyMock.expect(endpointInfo.getName()).andReturn(PORT_NAME).anyTimes();
         EasyMock.expect(endpoint.getEndpointInfo()).andReturn(endpointInfo).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);
@@ -133,6 +136,10 @@ public class AbstractMessageResponseTestBase extends Assert {
         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