cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r537737 [1/2] - in /incubator/cxf/trunk: rt/core/src/main/java/org/apache/cxf/bus/ rt/core/src/test/java/org/apache/cxf/bus/ rt/management/src/main/java/org/apache/cxf/management/ rt/management/src/main/java/org/apache/cxf/management/counte...
Date Mon, 14 May 2007 07:11:16 GMT
Author: ningjiang
Date: Mon May 14 00:11:13 2007
New Revision: 537737

URL: http://svn.apache.org/viewvc?view=rev&rev=537737
Log:
[CXF-649]
Added ResponseTimeCounter Intercepters to collect the message response time inforamtion.
Added the CounterRepository which holds the counters' reference and exports the counters to JMX. 
Also Changed the CXFBusImpl's getBusID() to retrun the default busID and the bus instance's hashcode.

Please have a look at the systest's CountersClientServerTest for more information.

Added:
    incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/CounterRepository.java   (with props)
    incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/MessageHandlingTimeRecorder.java   (with props)
    incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/Messages.properties   (with props)
    incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/PerformanceCounter.java   (with props)
    incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/PerformanceCounterMBean.java   (with props)
    incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/ResponseTimeCounter.java   (with props)
    incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/ResponseTimeCounterMBean.java   (with props)
    incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/
    incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTimeInterceptor.java   (with props)
    incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/Messages.properties   (with props)
    incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeFeature.java   (with props)
    incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInInterceptor.java   (with props)
    incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInvokerInterceptor.java   (with props)
    incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeMessageOutInterceptor.java   (with props)
    incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/counters/CounterRepositoryTest.java   (with props)
    incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/interceptor/
    incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTestBase.java   (with props)
    incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInInterceptorTest.java   (with props)
    incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInvokerInterceptorTest.java   (with props)
    incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageOutInterceptorTest.java   (with props)
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/management/CountersClientServerTest.java   (with props)
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/management/counter-spring.xml   (with props)
Removed:
    incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/Messages.properties
    incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/TransportClientCounters.java
    incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/TransportServerCounters.java
    incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/counters/CountersTest.java
Modified:
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/CXFBusImpl.java
    incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/CXFBusImplTest.java
    incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/Counter.java

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/CXFBusImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/CXFBusImpl.java?view=diff&rev=537737&r1=537736&r2=537737
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/CXFBusImpl.java (original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/CXFBusImpl.java Mon May 14 00:11:13 2007
@@ -77,8 +77,8 @@
         extensions.put(extensionType, extension);
     }
      
-    public String getId() {
-        return null == id ? DEFAULT_BUS_ID : id;
+    public String getId() {        
+        return null == id ? DEFAULT_BUS_ID + Integer.toString(this.hashCode()) : id;
     }
 
     public void run() {

Modified: incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/CXFBusImplTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/CXFBusImplTest.java?view=diff&rev=537737&r1=537736&r2=537737
==============================================================================
--- incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/CXFBusImplTest.java (original)
+++ incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/CXFBusImplTest.java Mon May 14 00:11:13 2007
@@ -98,7 +98,7 @@
     public void testBusID() {
         CXFBusImpl bus = new CXFBusImpl();
         String id = bus.getId();
-        assertEquals("The bus id should be cxf", id, CXFBusImpl.DEFAULT_BUS_ID);
+        assertEquals("The bus id should be cxf", id, CXFBusImpl.DEFAULT_BUS_ID + bus.hashCode());
         bus.setId("test");
         assertEquals("The bus id should be changed", bus.getId(), "test");
     }

Modified: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/Counter.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/Counter.java?view=diff&rev=537737&r1=537736&r2=537737
==============================================================================
--- incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/Counter.java (original)
+++ incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/Counter.java Mon May 14 00:11:13 2007
@@ -19,58 +19,12 @@
 
 package org.apache.cxf.management.counters;
 
-/** class for the performance couter */
-public class Counter {
-    
-    private String discription;
-    private int value;
-    private float rate;
-    private Boolean runFlag;
-    
-    Counter(String disc) {
-        discription = disc;
-        runFlag = false;
-    }
-    
-    public void reset() {
-        value = 0;
-        runFlag = true;
-    }
-    
-    public int add(int i) {
-        value = value + i;
-        return value;
-    }
-    
-    public final void increase() {
-        if (runFlag) {
-            value++;
-        }
-    }
-    
-    public String getDiscription() {
-        return discription;
-    }
-    
-    float getRate() {
-        return rate;
-    }
-    
-    public int getValue() {
-        return value;
-    }
-    
-    public void stop() {
-        value = 0;
-        runFlag = false;
-    }
-    
-    void setRate(float r) {
-        if (rate < 1 && rate > 0) {
-            rate = r;
-        }
-        // else do nothing           
-    }
-    
-    
+import org.apache.cxf.management.ManagedComponent;
+
+public interface Counter extends ManagedComponent {
+    String DEFAULT_DOMAIN_NAME  = "com.iona.tandoori";
+    
+    void increase(MessageHandlingTimeRecorder mhtr);  
+        
+    Number getNumInvocations();
 }

Added: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/CounterRepository.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/CounterRepository.java?view=auto&rev=537737
==============================================================================
--- incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/CounterRepository.java (added)
+++ incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/CounterRepository.java Mon May 14 00:11:13 2007
@@ -0,0 +1,116 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.management.counters;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
+import javax.management.JMException;
+import javax.management.ObjectName;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.management.InstrumentationManager;
+import org.apache.cxf.management.interceptor.ResponseTimeMessageInInterceptor;
+import org.apache.cxf.management.interceptor.ResponseTimeMessageInvokerInterceptor;
+import org.apache.cxf.management.interceptor.ResponseTimeMessageOutInterceptor;
+
+/* Counters are created and managed by CounterRepository 
+ * If a counter which is queried form the counterRepository is not exist,
+ * the CounterRepository will create a counter and expose it to the JMX
+ * Because we can get the instance of the counter object, 
+ * it is not need to qurey the counter object from JMX 
+ * */
+public class CounterRepository {
+    private static final Logger LOG = LogUtils.getL7dLogger(CounterRepository.class);
+    
+    private Map<ObjectName, Counter> counters;
+    private Bus bus;
+    
+    public CounterRepository() {
+        counters = new ConcurrentHashMap<ObjectName, Counter>();
+    }
+    
+    @Resource(name = "bus")
+    public void setBus(Bus b) {
+        bus = b;
+    }
+
+    public Bus getBus() {
+        return bus;
+    }
+        
+    public Map<ObjectName, Counter> getCounters() {
+        return counters;
+    }
+    
+    @PostConstruct
+    void registerInterceptorsToBus() {
+        Interceptor in = new ResponseTimeMessageInInterceptor();
+        Interceptor invoker = new ResponseTimeMessageInvokerInterceptor();
+        Interceptor out = new ResponseTimeMessageOutInterceptor();
+        
+        bus.getInInterceptors().add(in);
+        bus.getInInterceptors().add(invoker);
+        bus.getOutInterceptors().add(out);
+        bus.setExtension(this, CounterRepository.class); 
+        
+        //create CounterRepositroyMoniter to writer the counter log
+        
+        //if the service is stopped or removed, the counters should remove itself
+    }
+    
+    public void increaseCounter(ObjectName on, MessageHandlingTimeRecorder mhtr) {
+        Counter counter = getCounter(on);
+        if (null == counter) {            
+            counter = createCounter(on, mhtr);
+            counters.put(on, counter);
+        }
+        counter.increase(mhtr);        
+    }
+    
+    //find a counter
+    public Counter getCounter(ObjectName on) {
+        return counters.get(on);
+    }
+    
+    public Counter createCounter(ObjectName on, MessageHandlingTimeRecorder mhtr) {
+        Counter counter = null;
+        counter = new ResponseTimeCounter(on);
+        InstrumentationManager im = bus.getExtension(InstrumentationManager.class);
+        if (null != im) {
+            try {
+                im.register(counter);
+            } catch (JMException e) {
+                LOG.log(Level.WARNING, "INSTRUMENTATION_REGISTER_FAULT_MSG",
+                        new Object[]{e});
+            }
+        }    
+        return counter;
+    }
+    
+    
+
+}

Propchange: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/CounterRepository.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/CounterRepository.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/MessageHandlingTimeRecorder.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/MessageHandlingTimeRecorder.java?view=auto&rev=537737
==============================================================================
--- incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/MessageHandlingTimeRecorder.java (added)
+++ incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/MessageHandlingTimeRecorder.java Mon May 14 00:11:13 2007
@@ -0,0 +1,64 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.management.counters;
+
+import org.apache.cxf.message.Exchange;
+
+/* recoder the message actually handle begin and end time */ 
+public class MessageHandlingTimeRecorder {
+    private Exchange exchange;
+    private long beginTime;
+    private long endTime;
+    private boolean oneWay;
+    
+    public MessageHandlingTimeRecorder(Exchange ex) {
+        exchange = ex;
+        exchange.put(MessageHandlingTimeRecorder.class, this);
+    }
+    
+    public boolean isOneWay() {
+        return oneWay;
+    }
+    
+    public void setOneWay(boolean ow) {
+        oneWay = ow;
+    }
+    
+    public Exchange getHandleExchange() {
+        return exchange;    
+    }
+    
+    public void beginHandling() {
+        beginTime = System.nanoTime() / 1000;
+    }
+    
+    public void endHandling() {
+        endTime = System.nanoTime() / 1000;
+    }
+    
+    public long getEndTime() {
+        return endTime;
+    }
+    
+    public long getHandlingTime() {        
+        return endTime - beginTime;
+    }
+
+}

Propchange: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/MessageHandlingTimeRecorder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/MessageHandlingTimeRecorder.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/Messages.properties
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/Messages.properties?view=auto&rev=537737
==============================================================================
--- incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/Messages.properties (added)
+++ incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/Messages.properties Mon May 14 00:11:13 2007
@@ -0,0 +1,25 @@
+#
+#
+#    Licensed to the Apache Software Foundation (ASF) under one
+#    or more contributor license agreements. See the NOTICE file
+#    distributed with this work for additional information
+#    regarding copyright ownership. The ASF licenses this file
+#    to you under the Apache License, Version 2.0 (the
+#    "License"); you may not use this file except in compliance
+#    with the License. You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing,
+#    software distributed under the License is distributed on an
+#    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#    KIND, either express or implied. See the License for the
+#    specific language governing permissions and limitations
+#    under the License.
+#
+#
+CANNOT_FIND_THE_COUNTERREPOSITORY = CounterRepositoryMoniter can't find the CounterResponsitory from bus.
+CANNOT_CREATE_LOGGER_FILE = Can't create the logger file for the response time counters. {0}
+CANNOT_FIND_THE_COUNTER_OBJECTNAME = Can't find the counter object name. {0}
+CANNOT_FIND_STATUS = Can't find the status. {0}
+

Propchange: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/Messages.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/Messages.properties
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/Messages.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/PerformanceCounter.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/PerformanceCounter.java?view=auto&rev=537737
==============================================================================
--- incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/PerformanceCounter.java (added)
+++ incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/PerformanceCounter.java Mon May 14 00:11:13 2007
@@ -0,0 +1,45 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.management.counters;
+
+import javax.management.JMException;
+import javax.management.ObjectName;
+
+public class PerformanceCounter implements PerformanceCounterMBean, Counter {
+    private int invocations;
+    private ObjectName objectName;
+
+    public PerformanceCounter(ObjectName on) {
+        objectName = on;
+    }
+
+    public Number getNumInvocations() {        
+        return invocations;
+    }
+
+    public synchronized void increase(MessageHandlingTimeRecorder mhtr) {
+        invocations++;
+    }
+
+    public ObjectName getObjectName() throws JMException {        
+        return objectName;
+    }
+    
+}

Propchange: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/PerformanceCounter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/PerformanceCounter.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/PerformanceCounterMBean.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/PerformanceCounterMBean.java?view=auto&rev=537737
==============================================================================
--- incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/PerformanceCounterMBean.java (added)
+++ incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/PerformanceCounterMBean.java Mon May 14 00:11:13 2007
@@ -0,0 +1,24 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.management.counters;
+
+public interface PerformanceCounterMBean {
+    Number getNumInvocations();
+}

Propchange: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/PerformanceCounterMBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/PerformanceCounterMBean.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/ResponseTimeCounter.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/ResponseTimeCounter.java?view=auto&rev=537737
==============================================================================
--- incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/ResponseTimeCounter.java (added)
+++ incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/ResponseTimeCounter.java Mon May 14 00:11:13 2007
@@ -0,0 +1,83 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.management.counters;
+
+
+import javax.management.ObjectName;
+
+public class ResponseTimeCounter implements ResponseTimeCounterMBean, Counter {    
+    
+    private ObjectName objectName;
+    private int invocations;
+    private long totalHandlingTime;    
+    private long maxHandlingTime;
+    private long minHandlingTime = Integer.MAX_VALUE;
+    
+    public ResponseTimeCounter(ObjectName on) {
+        objectName = on;     
+    }
+    
+    public synchronized void  increase(MessageHandlingTimeRecorder mhtr) {
+        invocations++;
+        long handlingTime = 0;
+        if (mhtr.isOneWay()) {
+            // We can count the response time 
+            if (mhtr.getEndTime() > 0) {
+                handlingTime = mhtr.getHandlingTime(); 
+            }    
+        } else {
+            handlingTime = mhtr.getHandlingTime(); 
+        }
+            
+        totalHandlingTime = totalHandlingTime + handlingTime;
+        if (maxHandlingTime < handlingTime) {
+            maxHandlingTime = handlingTime;
+        }
+        if (minHandlingTime > handlingTime) {
+            minHandlingTime = handlingTime;
+        }         
+    }
+    
+    
+    
+    public ObjectName getObjectName() {
+        return objectName;
+    }
+
+    public Number getAvgResponseTime() {        
+        return (int)(totalHandlingTime / invocations);
+    }
+
+    
+    public Number getMaxResponseTime() {        
+        return maxHandlingTime;
+    }
+
+    public Number getMinResponseTime() {        
+        return minHandlingTime;
+    }
+
+    public Number getNumInvocations() {        
+        return invocations;
+    }
+
+   
+    
+    
+}

Propchange: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/ResponseTimeCounter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/ResponseTimeCounter.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/ResponseTimeCounterMBean.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/ResponseTimeCounterMBean.java?view=auto&rev=537737
==============================================================================
--- incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/ResponseTimeCounterMBean.java (added)
+++ incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/ResponseTimeCounterMBean.java Mon May 14 00:11:13 2007
@@ -0,0 +1,27 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.management.counters;
+
+public interface ResponseTimeCounterMBean {   
+    Number getNumInvocations();
+    Number getAvgResponseTime();
+    Number getMaxResponseTime();
+    Number getMinResponseTime();   
+    
+}

Propchange: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/ResponseTimeCounterMBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/ResponseTimeCounterMBean.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTimeInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTimeInterceptor.java?view=auto&rev=537737
==============================================================================
--- incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTimeInterceptor.java (added)
+++ incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTimeInterceptor.java Mon May 14 00:11:13 2007
@@ -0,0 +1,137 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.management.interceptor;
+
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.management.ObjectName;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.management.counters.Counter;
+import org.apache.cxf.management.counters.CounterRepository;
+import org.apache.cxf.management.counters.MessageHandlingTimeRecorder;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.service.Service;
+import org.apache.cxf.service.model.OperationInfo;
+
+public abstract class AbstractMessageResponseTimeInterceptor extends AbstractPhaseInterceptor<Message> {
+    private static final Logger LOG = LogUtils.getL7dLogger(AbstractMessageResponseTimeInterceptor.class);
+    
+    AbstractMessageResponseTimeInterceptor() {
+        super();
+    }
+    
+    protected boolean isClient(Message msg) {
+        return msg == null ? false : Boolean.TRUE.equals(msg.get(Message.REQUESTOR_ROLE));        
+    }
+   
+    protected void beginHandlingMessage(Exchange ex) {
+        if (null == ex) {
+            return;
+        }
+        MessageHandlingTimeRecorder mhtr = ex.get(MessageHandlingTimeRecorder.class);        
+        if (null != mhtr) {
+            mhtr.beginHandling();
+        } else {
+            mhtr = new MessageHandlingTimeRecorder(ex);
+            mhtr.beginHandling();
+        }        
+    }
+    
+    protected void endHandlingMessage(Exchange ex) {                
+        if (null == ex) {
+            return;
+        }
+        MessageHandlingTimeRecorder mhtr = ex.get(MessageHandlingTimeRecorder.class);
+        if (null != mhtr) {
+            mhtr.endHandling();            
+            increaseCounter(ex, mhtr);
+                        
+        } // else can't get the MessageHandling Infor  
+    }
+    
+    protected void setOneWayMessage(Exchange ex) {
+        MessageHandlingTimeRecorder mhtr = ex.get(MessageHandlingTimeRecorder.class);        
+        if (null == mhtr) {
+            mhtr = new MessageHandlingTimeRecorder(ex);            
+        } else {
+            mhtr.endHandling();
+        }
+        mhtr.setOneWay(true);
+        increaseCounter(ex, mhtr);
+    }    
+    
+    private void increaseCounter(Exchange ex, MessageHandlingTimeRecorder mhtr) {
+        Bus bus = ex.get(Bus.class);
+        if (null == bus) {
+            LOG.log(Level.INFO, "CAN_NOT_GET_BUS_FROM_EXCHANGE");
+            BusFactory.getDefaultBus();
+        }
+        
+        Message message = ex.getOutMessage();
+        
+        CounterRepository cr = bus.getExtension(CounterRepository.class);
+        
+        if (null == cr) {
+            LOG.log(Level.WARNING, "NO_COUNTER_REPOSITORY");
+            return;
+        } else {            
+            Service service = ex.get(Service.class);            
+            OperationInfo opInfo = ex.get(OperationInfo.class);
+            Endpoint endpoint = ex.get(Endpoint.class);
+            
+            String portName = "\"" + endpoint.getEndpointInfo().getName() + "\"";
+            String serviceName = "\"" + service.getName() + "\"";            
+            String operationName = "\"" + opInfo.getName().toString() + "\"";
+            
+            StringBuffer buffer = new StringBuffer();
+            buffer.append(Counter.DEFAULT_DOMAIN_NAME + ":");
+            buffer.append("BusID=" + bus.getId() + ",");
+            if (isClient(message)) {
+                buffer.append("Type=Counter_Client,");
+            } else {
+                buffer.append("Type=Counter_Server,");
+            }
+            buffer.append("ServiceName=" + serviceName + ",");
+           
+            buffer.append("PortName=" + portName);
+            String serviceCounterName = buffer.toString();
+            
+            buffer.append(",OperationName=" + operationName);
+            String operationCounterName = buffer.toString();
+            try {               
+                ObjectName serviceCounter = 
+                    new ObjectName(serviceCounterName);                
+                cr.increaseCounter(serviceCounter, mhtr);
+                ObjectName operationCounter = new ObjectName(operationCounterName);
+                cr.increaseCounter(operationCounter, mhtr);                
+            } catch (Exception exception) {
+                LOG.log(Level.WARNING, "CREATE_COUNTER_OBJECTNAME_FAILED", exception);
+            }
+        }
+    }
+        
+}

Propchange: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTimeInterceptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTimeInterceptor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/Messages.properties
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/Messages.properties?view=auto&rev=537737
==============================================================================
--- incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/Messages.properties (added)
+++ incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/Messages.properties Mon May 14 00:11:13 2007
@@ -0,0 +1,23 @@
+#
+#
+#    Licensed to the Apache Software Foundation (ASF) under one
+#    or more contributor license agreements. See the NOTICE file
+#    distributed with this work for additional information
+#    regarding copyright ownership. The ASF licenses this file
+#    to you under the Apache License, Version 2.0 (the
+#    "License"); you may not use this file except in compliance
+#    with the License. You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing,
+#    software distributed under the License is distributed on an
+#    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#    KIND, either express or implied. See the License for the
+#    specific language governing permissions and limitations
+#    under the License.
+#
+#
+CAN_NOT_GET_BUS_FROM_EXCHANGE = Can't get bus instance from exchange, get the bus from defautl bus
+CREATE_COUNTER_OBJECTNAME_FAILED = Create Counter's ObjectName failed. {0}
+NO_COUNTER_REPOSITORY = Can't find the CounterRepository from default Bus
\ No newline at end of file

Propchange: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/Messages.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/Messages.properties
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/Messages.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeFeature.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeFeature.java?view=auto&rev=537737
==============================================================================
--- incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeFeature.java (added)
+++ incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeFeature.java Mon May 14 00:11:13 2007
@@ -0,0 +1,41 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.management.interceptor;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.feature.AbstractFeature;
+import org.apache.cxf.interceptor.InterceptorProvider;
+
+public class ResponseTimeFeature extends AbstractFeature {
+    private static final ResponseTimeMessageInInterceptor IN =
+        new ResponseTimeMessageInInterceptor();
+    private static final ResponseTimeMessageInvokerInterceptor INVOKER = 
+        new ResponseTimeMessageInvokerInterceptor();
+    private static final ResponseTimeMessageOutInterceptor OUT = 
+        new ResponseTimeMessageOutInterceptor();
+    
+    @Override
+    protected void initializeProvider(InterceptorProvider provider, Bus bus) {
+        provider.getInInterceptors().add(IN);
+        provider.getInInterceptors().add(INVOKER);
+        provider.getOutInterceptors().add(OUT);
+        
+    }
+
+}

Propchange: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeFeature.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeFeature.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInInterceptor.java?view=auto&rev=537737
==============================================================================
--- incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInInterceptor.java (added)
+++ incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInInterceptor.java Mon May 14 00:11:13 2007
@@ -0,0 +1,44 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.management.interceptor;
+
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.Phase;
+
+public class ResponseTimeMessageInInterceptor extends AbstractMessageResponseTimeInterceptor {
+    
+    public ResponseTimeMessageInInterceptor() {
+        super();
+        setPhase(Phase.RECEIVE);
+    }
+    
+    public void handleMessage(Message message) throws Fault {
+        
+        Exchange ex = message.getExchange();        
+        if (isClient(message)) {
+            endHandlingMessage(ex);
+        } else {            
+            beginHandlingMessage(ex);            
+        }
+    }
+    
+}

Propchange: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInInterceptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInInterceptor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInvokerInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInvokerInterceptor.java?view=auto&rev=537737
==============================================================================
--- incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInvokerInterceptor.java (added)
+++ incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInvokerInterceptor.java Mon May 14 00:11:13 2007
@@ -0,0 +1,58 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.management.interceptor;
+
+import java.util.Collections;
+import java.util.Set;
+
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.interceptor.ServiceInvokerInterceptor;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.Phase;
+
+/* When the message get from the server side
+ * The exchange.isOneWay() is workable when the message
+ * handler by the binging interceptor  
+ * */ 
+public class ResponseTimeMessageInvokerInterceptor 
+    extends AbstractMessageResponseTimeInterceptor {
+    //this interceptor should be add after the serviceInvokerInterceptor
+    private Set<String> before = Collections.singleton(ServiceInvokerInterceptor.class.getName());
+      
+    public ResponseTimeMessageInvokerInterceptor() {
+        super();
+        setPhase(Phase.INVOKE);
+        
+        
+    }
+
+    public void handleMessage(Message message) throws Fault {
+        Exchange ex = message.getExchange();
+        if (ex.isOneWay()) {
+            setOneWayMessage(ex); 
+        }
+    }
+    
+    @Override
+    public Set<String> getBefore() {
+        return before;
+    }
+}

Propchange: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInvokerInterceptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInvokerInterceptor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeMessageOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeMessageOutInterceptor.java?view=auto&rev=537737
==============================================================================
--- incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeMessageOutInterceptor.java (added)
+++ incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeMessageOutInterceptor.java Mon May 14 00:11:13 2007
@@ -0,0 +1,45 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.management.interceptor;
+
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.Phase;
+
+public class ResponseTimeMessageOutInterceptor extends AbstractMessageResponseTimeInterceptor {
+    
+    public ResponseTimeMessageOutInterceptor() {
+        super();
+        setPhase(Phase.SEND);
+    }
+    
+    public void handleMessage(Message message) throws Fault {
+        Exchange ex = message.getExchange();
+        if (isClient(message)) {
+            if (ex.isOneWay()) {
+                setOneWayMessage(ex);
+            } else {
+                beginHandlingMessage(ex); 
+            }
+        } else { // the message is handled by server
+            endHandlingMessage(ex);
+        }
+    }
+}

Propchange: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeMessageOutInterceptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/ResponseTimeMessageOutInterceptor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/counters/CounterRepositoryTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/counters/CounterRepositoryTest.java?view=auto&rev=537737
==============================================================================
--- incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/counters/CounterRepositoryTest.java (added)
+++ incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/counters/CounterRepositoryTest.java Mon May 14 00:11:13 2007
@@ -0,0 +1,137 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.management.counters;
+
+import javax.management.ObjectName;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.management.InstrumentationManager;
+import org.easymock.classextension.EasyMock;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class CounterRepositoryTest extends Assert {
+    private Bus bus;
+    //private InstrumentationManager im;
+    private ObjectName serviceCounter;
+    private ObjectName operationCounter;
+    
+    @Before
+    public void setUp() throws Exception {
+        
+        serviceCounter = new ObjectName("tandoori:type=counter,service=help");
+        operationCounter = new ObjectName("tandoori:type=counter,service=help,operation=me");
+        bus = EasyMock.createMock(Bus.class);        
+        bus.getExtension(InstrumentationManager.class);
+        EasyMock.expectLastCall().andReturn(null).anyTimes();
+        EasyMock.replay(bus);
+    }
+    
+    @Test
+    public void testIncreaseOneWayResponseCounter() throws Exception {        
+        
+        CounterRepository cr = new CounterRepository();
+        cr.setBus(bus);
+        //cr.createCounter(operationCounter, true);
+        MessageHandlingTimeRecorder mhtr = EasyMock.createMock(MessageHandlingTimeRecorder.class);
+        EasyMock.expect(mhtr.isOneWay()).andReturn(true).anyTimes();
+        EasyMock.expect(mhtr.getEndTime()).andReturn((long)100000000).anyTimes();
+        EasyMock.expect(mhtr.getHandlingTime()).andReturn((long)1000).anyTimes();
+        
+        EasyMock.replay(mhtr);
+        cr.increaseCounter(serviceCounter, mhtr);
+        cr.increaseCounter(operationCounter, mhtr);
+        ResponseTimeCounter opCounter = (ResponseTimeCounter) cr.getCounter(operationCounter);
+        ResponseTimeCounter sCounter = (ResponseTimeCounter) cr.getCounter(serviceCounter);
+        
+        assertEquals("The operation counter isn't increased", opCounter.getNumInvocations(), 1);
+        assertEquals("The Service counter isn't increased", sCounter.getNumInvocations(), 1);
+        
+        EasyMock.verify(bus);
+        EasyMock.verify(mhtr);        
+    }
+    
+    @Test
+    public void testIncreaseOneWayNoResponseCounter() throws Exception {        
+        
+        CounterRepository cr = new CounterRepository();
+        cr.setBus(bus);
+        //cr.createCounter(operationCounter, true);
+        MessageHandlingTimeRecorder mhtr = EasyMock.createMock(MessageHandlingTimeRecorder.class);
+        EasyMock.expect(mhtr.isOneWay()).andReturn(true).anyTimes();
+        EasyMock.expect(mhtr.getEndTime()).andReturn((long)0).anyTimes();
+        EasyMock.replay(mhtr);
+        cr.increaseCounter(serviceCounter, mhtr);
+        cr.increaseCounter(operationCounter, mhtr);
+        ResponseTimeCounter opCounter = (ResponseTimeCounter) cr.getCounter(operationCounter);
+        ResponseTimeCounter sCounter = (ResponseTimeCounter) cr.getCounter(serviceCounter);
+        
+        assertEquals("The operation counter isn't increased", opCounter.getNumInvocations(), 1);
+        assertEquals("The Service counter isn't increased", sCounter.getNumInvocations(), 1);
+        
+        EasyMock.verify(bus);
+        EasyMock.verify(mhtr);        
+    }
+    
+    @Test
+    public void testIncreaseResponseCounter() throws Exception {
+        CounterRepository cr = new CounterRepository();
+        cr.setBus(bus);
+        
+        MessageHandlingTimeRecorder mhtr1 = EasyMock.createMock(MessageHandlingTimeRecorder.class);
+        EasyMock.expect(mhtr1.isOneWay()).andReturn(false).anyTimes();
+        EasyMock.expect(mhtr1.getHandlingTime()).andReturn((long)1000).anyTimes();
+        EasyMock.replay(mhtr1);
+        cr.createCounter(operationCounter, mhtr1);
+        cr.increaseCounter(serviceCounter, mhtr1);
+        cr.increaseCounter(operationCounter, mhtr1);
+        ResponseTimeCounter opCounter = (ResponseTimeCounter) cr.getCounter(operationCounter);
+        ResponseTimeCounter sCounter = (ResponseTimeCounter) cr.getCounter(serviceCounter);
+        
+        assertEquals("The operation counter isn't increased", opCounter.getNumInvocations(), 1);
+        assertEquals("The operation counter's AvgResponseTime is wrong ",
+                     opCounter.getAvgResponseTime(), 1000);
+        assertEquals("The operation counter's MaxResponseTime is wrong ", 
+                     opCounter.getMaxResponseTime(), (long)1000);
+        assertEquals("The operation counter's MinResponseTime is wrong ", 
+                     opCounter.getMinResponseTime(), (long)1000);
+        assertEquals("The Service counter isn't increased", sCounter.getNumInvocations(), 1);
+        
+        MessageHandlingTimeRecorder mhtr2 = EasyMock.createMock(MessageHandlingTimeRecorder.class);
+        EasyMock.expect(mhtr2.isOneWay()).andReturn(false).anyTimes();
+        EasyMock.expect(mhtr2.getHandlingTime()).andReturn((long)2000).anyTimes();
+        EasyMock.replay(mhtr2);
+        cr.increaseCounter(serviceCounter, mhtr2);
+        cr.increaseCounter(operationCounter, mhtr2);
+        assertEquals("The operation counter isn't increased", opCounter.getNumInvocations(), 2);
+        assertEquals("The operation counter's AvgResponseTime is wrong ",
+                     opCounter.getAvgResponseTime(), 1500);
+        assertEquals("The operation counter's MaxResponseTime is wrong ",
+                     opCounter.getMaxResponseTime(), (long)2000);
+        assertEquals("The operation counter's MinResponseTime is wrong ",
+                     opCounter.getMinResponseTime(), (long)1000);
+        assertEquals("The Service counter isn't increased", sCounter.getNumInvocations(), 2);
+        
+        EasyMock.verify(bus);
+        EasyMock.verify(mhtr1);
+        EasyMock.verify(mhtr2);
+    }
+   
+}

Propchange: incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/counters/CounterRepositoryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/counters/CounterRepositoryTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTestBase.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTestBase.java?view=auto&rev=537737
==============================================================================
--- incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTestBase.java (added)
+++ incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTestBase.java Mon May 14 00:11:13 2007
@@ -0,0 +1,136 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.management.interceptor;
+
+import javax.management.ObjectName;
+import javax.xml.namespace.QName;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.management.counters.CounterRepository;
+import org.apache.cxf.management.counters.MessageHandlingTimeRecorder;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.service.Service;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.service.model.OperationInfo;
+import org.easymock.classextension.EasyMock;
+import org.junit.Assert;
+import org.junit.Before;
+
+
+
+public class AbstractMessageResponseTestBase extends Assert {
+    protected static final QName SERVICE_NAME = new QName("http://com.iona.tandoori", "hello");
+    protected static final QName OPERATION_NAME = new QName("http://com.iona.tandoori", "world");
+    protected static final QName PORT_NAME = new QName("http://com.iona.tandoori", "port");
+    
+    protected static final String CLIENT_SERVICE_ONAME =
+        "com.iona.tandoori:Type=Counter_Client,BusID=tandoori,ServiceName=\"" 
+        + SERVICE_NAME.toString() + "\",PortName=\"" 
+        + PORT_NAME + "\"";
+    protected static final String SERVER_SERVICE_ONAME = 
+        "com.iona.tandoori:Type=Counter_Server,BusID=tandoori,ServiceName=\"" 
+        + SERVICE_NAME.toString() + "\",PortName=\"" 
+        + PORT_NAME + "\"";
+    protected ObjectName clientServiceCounterOName;
+    protected ObjectName serverServiceCounterOName;
+    protected ObjectName clientOperationCounterOName;
+    protected ObjectName serverOperationCounterOName;
+    
+    protected Bus bus;
+    protected Message message;
+    protected Exchange exchange;
+    protected CounterRepository cRepository;
+    
+    @Before
+    public void setUp() throws Exception {
+        message = EasyMock.createMock(Message.class);
+        exchange = EasyMock.createMock(Exchange.class);
+        bus = EasyMock.createMock(Bus.class);
+        cRepository = EasyMock.createMock(CounterRepository.class);
+        clientServiceCounterOName = new ObjectName(CLIENT_SERVICE_ONAME);
+        serverServiceCounterOName = new ObjectName(SERVER_SERVICE_ONAME);
+        clientOperationCounterOName = new ObjectName(CLIENT_SERVICE_ONAME 
+                                               + ",OperationName=\"" 
+                                               + OPERATION_NAME.toString() + "\"");
+        serverOperationCounterOName = new ObjectName(SERVER_SERVICE_ONAME 
+                                                     + ",OperationName=\"" 
+                                                     + OPERATION_NAME.toString() + "\"");
+        
+        
+    }
+    
+    protected void setupCounterRepository(boolean increase, boolean isClient) {
+        ObjectName serviceCounterOName;
+        ObjectName operationCounterOName;
+        if (isClient) {
+            serviceCounterOName = clientServiceCounterOName;
+            operationCounterOName = clientOperationCounterOName;            
+        } else {
+            serviceCounterOName = serverServiceCounterOName;
+            operationCounterOName = serverOperationCounterOName;
+        }
+        BusFactory.setDefaultBus(bus);      
+        bus.getExtension(CounterRepository.class);
+        EasyMock.expectLastCall().andReturn(cRepository);
+        if (increase) {
+            EasyMock.expect(bus.getId()).andReturn("tandoori");
+            cRepository.increaseCounter(EasyMock.eq(serviceCounterOName),
+                                               EasyMock.isA(MessageHandlingTimeRecorder.class));
+            EasyMock.expectLastCall();
+            cRepository.increaseCounter(EasyMock.eq(operationCounterOName), 
+                EasyMock.isA(MessageHandlingTimeRecorder.class));
+            EasyMock.expectLastCall(); 
+            EasyMock.replay(cRepository);
+        }
+        
+        EasyMock.replay(bus);
+        // increase the number
+    }
+    
+    protected void setupExchangeForMessage() {
+        EasyMock.expect(exchange.get(Bus.class)).andReturn(bus);
+       
+        Service service = EasyMock.createMock(Service.class);
+        EasyMock.expect(service.getName()).andReturn(SERVICE_NAME);        
+        EasyMock.expect(exchange.get(Service.class)).andReturn(service);
+        EasyMock.replay(service);
+        
+        Endpoint endpoint = EasyMock.createMock(Endpoint.class);
+        EndpointInfo endpointInfo = EasyMock.createMock(EndpointInfo.class);
+        EasyMock.expect(endpointInfo.getName()).andReturn(PORT_NAME);
+        EasyMock.expect(endpoint.getEndpointInfo()).andReturn(endpointInfo);
+        EasyMock.expect(exchange.get(Endpoint.class)).andReturn(endpoint);
+        EasyMock.replay(endpointInfo);
+        EasyMock.replay(endpoint);
+        
+        OperationInfo op = EasyMock.createMock(OperationInfo.class);
+        EasyMock.expect(op.getName()).andReturn(OPERATION_NAME);        
+        EasyMock.expect(exchange.get(OperationInfo.class)).andReturn(op);
+        EasyMock.replay(op);
+      
+        
+    }
+      
+    
+
+}

Propchange: incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTestBase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/interceptor/AbstractMessageResponseTestBase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInInterceptorTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInInterceptorTest.java?view=auto&rev=537737
==============================================================================
--- incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInInterceptorTest.java (added)
+++ incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInInterceptorTest.java Mon May 14 00:11:13 2007
@@ -0,0 +1,112 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.management.interceptor;
+
+import org.apache.cxf.management.counters.MessageHandlingTimeRecorder;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageImpl;
+import org.easymock.classextension.EasyMock;
+import org.junit.Test;
+
+public class ResponseTimeMessageInInterceptorTest extends AbstractMessageResponseTestBase {
+   
+    private ResponseTimeMessageInInterceptor rtmii = new ResponseTimeMessageInInterceptor();
+    
+    @Test
+    public void testClientMessageIn() {
+        // need to increase the counter and is a client
+        setupCounterRepository(true, true);
+        setupExchangeForMessage();
+        EasyMock.expect(message.getExchange()).andReturn(exchange);
+        EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.TRUE).anyTimes();
+        EasyMock.expect(exchange.getOutMessage()).andReturn(message);
+        MessageHandlingTimeRecorder mhtr = EasyMock.createMock(MessageHandlingTimeRecorder.class);
+        mhtr.endHandling();
+        EasyMock.expectLastCall();              
+         
+        EasyMock.replay(mhtr);
+        EasyMock.expect(exchange.get(MessageHandlingTimeRecorder.class)).andReturn(mhtr);        
+        EasyMock.replay(exchange);
+        EasyMock.replay(message);
+        
+        rtmii.handleMessage(message);
+        EasyMock.verify(message);
+        EasyMock.verify(bus);
+        EasyMock.verify(exchange);
+        EasyMock.verify(mhtr);
+        EasyMock.verify(cRepository);
+        
+    }
+    
+    
+    // it would not fire the counter increase action now
+    @Test
+    public void testServerOneWayMessageIn() {
+        // need to increase the counter and is not a client
+        //setupCounterRepository(false, false);
+        //setupExchangeForMessage();
+        EasyMock.expect(message.getExchange()).andReturn(exchange);
+        EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.FALSE).anyTimes();
+        //EasyMock.expect(exchange.getOutMessage()).andReturn(message);
+        MessageHandlingTimeRecorder mhtr = EasyMock.createMock(MessageHandlingTimeRecorder.class);
+        mhtr.beginHandling();
+        EasyMock.expectLastCall();
+         
+        EasyMock.replay(mhtr);
+        //EasyMock.expect(exchange.isOneWay()).andReturn(true);
+        EasyMock.expect(exchange.get(MessageHandlingTimeRecorder.class)).andReturn(mhtr);        
+        EasyMock.replay(exchange);
+        EasyMock.replay(message);
+        
+        rtmii.handleMessage(message);
+        EasyMock.verify(message);
+        //EasyMock.verify(bus);
+        EasyMock.verify(exchange);
+        EasyMock.verify(mhtr);
+        //EasyMock.verify(cRepository);
+    }
+    
+    @Test
+    public void testServiceMessageIn() {
+        EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.FALSE);
+        EasyMock.expect(message.getExchange()).andReturn(exchange);
+        //EasyMock.expect(exchange.isOneWay()).andReturn(false);
+        EasyMock.expect(exchange.get(MessageHandlingTimeRecorder.class)).andReturn(null);     
+        exchange.put(EasyMock.eq(MessageHandlingTimeRecorder.class), 
+                     EasyMock.isA(MessageHandlingTimeRecorder.class));
+        EasyMock.replay(exchange);
+        EasyMock.replay(message);
+        rtmii.handleMessage(message);        
+        EasyMock.verify(message);        
+        EasyMock.verify(exchange);
+        
+    }
+    
+    public void testIsClient() {
+        Message message1 = null;
+        Message message2 = new MessageImpl();
+        Message message3 = new MessageImpl();
+        message3.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
+        assertTrue("the message should not be client", !rtmii.isClient(message1));
+        assertTrue("the message should not be client", !rtmii.isClient(message2));
+        assertTrue("the message should be client", rtmii.isClient(message3));
+    }
+
+}

Propchange: incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInInterceptorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInInterceptorTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInvokerInterceptorTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInvokerInterceptorTest.java?view=auto&rev=537737
==============================================================================
--- incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInvokerInterceptorTest.java (added)
+++ incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInvokerInterceptorTest.java Mon May 14 00:11:13 2007
@@ -0,0 +1,59 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.management.interceptor;
+
+import org.apache.cxf.management.counters.MessageHandlingTimeRecorder;
+
+import org.apache.cxf.message.Message;
+import org.easymock.classextension.EasyMock;
+import org.junit.Test;
+
+public class ResponseTimeMessageInvokerInterceptorTest extends AbstractMessageResponseTestBase {
+
+    private ResponseTimeMessageInvokerInterceptor rtmii = new ResponseTimeMessageInvokerInterceptor();
+    
+    @Test
+    public void testServerOneWayMessageIn() {
+        // need to increase the counter and is not a client
+        setupCounterRepository(true, false);
+        setupExchangeForMessage();
+        EasyMock.expect(message.getExchange()).andReturn(exchange);
+        EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.FALSE).anyTimes();
+        EasyMock.expect(exchange.getOutMessage()).andReturn(message);
+        MessageHandlingTimeRecorder mhtr = EasyMock.createMock(MessageHandlingTimeRecorder.class);
+        mhtr.setOneWay(true);
+        EasyMock.expectLastCall();
+        mhtr.endHandling();
+        EasyMock.expectLastCall();
+         
+        EasyMock.replay(mhtr);
+        EasyMock.expect(exchange.isOneWay()).andReturn(true);
+        EasyMock.expect(exchange.get(MessageHandlingTimeRecorder.class)).andReturn(mhtr);        
+        EasyMock.replay(exchange);
+        EasyMock.replay(message);
+        
+        rtmii.handleMessage(message);
+        EasyMock.verify(message);
+        EasyMock.verify(bus);
+        EasyMock.verify(exchange);
+        EasyMock.verify(mhtr);
+        EasyMock.verify(cRepository);
+    }
+}

Propchange: incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInvokerInterceptorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageInvokerInterceptorTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageOutInterceptorTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageOutInterceptorTest.java?view=auto&rev=537737
==============================================================================
--- incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageOutInterceptorTest.java (added)
+++ incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageOutInterceptorTest.java Mon May 14 00:11:13 2007
@@ -0,0 +1,99 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.management.interceptor;
+import org.apache.cxf.management.counters.MessageHandlingTimeRecorder;
+import org.apache.cxf.message.Message;
+import org.easymock.classextension.EasyMock;
+import org.junit.Test;
+
+public class ResponseTimeMessageOutInterceptorTest extends AbstractMessageResponseTestBase {
+    private ResponseTimeMessageOutInterceptor rtmoi = new ResponseTimeMessageOutInterceptor();
+    
+    @Test
+    public void testServerMessageOut() {
+        // need to increase the counter and is not a client
+        setupCounterRepository(true, false);
+        setupExchangeForMessage();
+        EasyMock.expect(message.getExchange()).andReturn(exchange);
+        EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.FALSE).anyTimes();
+        EasyMock.expect(exchange.getOutMessage()).andReturn(message);
+        MessageHandlingTimeRecorder mhtr = EasyMock.createMock(MessageHandlingTimeRecorder.class);
+        mhtr.endHandling();
+        EasyMock.expectLastCall();              
+         
+        EasyMock.replay(mhtr);
+        EasyMock.expect(exchange.get(MessageHandlingTimeRecorder.class)).andReturn(mhtr);        
+        EasyMock.replay(exchange);
+        EasyMock.replay(message);
+        
+        rtmoi.handleMessage(message);
+        EasyMock.verify(message);
+        EasyMock.verify(bus);
+        EasyMock.verify(exchange);
+        EasyMock.verify(mhtr);
+        EasyMock.verify(cRepository);
+        
+    }
+    
+    @Test
+    public void testClientOneWayMessageOut() {
+        //need to increase the counter and is a client
+        setupCounterRepository(true, true);
+        setupExchangeForMessage();
+        EasyMock.expect(message.getExchange()).andReturn(exchange);
+        EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.TRUE).anyTimes(); 
+        EasyMock.expect(exchange.getOutMessage()).andReturn(message);
+        //MessageHandlingTimeRecorder mhtr = EasyMock.createMock(MessageHandlingTimeRecorder.class);
+        //mhtr.setOneWay(true);
+        //EasyMock.expectLastCall();
+         
+        //EasyMock.replay(mhtr);
+        EasyMock.expect(exchange.isOneWay()).andReturn(true);
+        EasyMock.expect(exchange.get(MessageHandlingTimeRecorder.class)).andReturn(null);        
+        exchange.put(EasyMock.eq(MessageHandlingTimeRecorder.class), 
+                     EasyMock.isA(MessageHandlingTimeRecorder.class));
+        EasyMock.expectLastCall();
+        EasyMock.replay(exchange);
+        EasyMock.replay(message);
+        
+        rtmoi.handleMessage(message);
+        EasyMock.verify(message);
+        EasyMock.verify(bus);
+        EasyMock.verify(exchange);
+        //EasyMock.verify(mhtr);
+        EasyMock.verify(cRepository);
+    }
+    
+    @Test
+    public void testClientMessageOut() {
+        EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.TRUE);
+        EasyMock.expect(message.getExchange()).andReturn(exchange);
+        EasyMock.expect(exchange.isOneWay()).andReturn(false);
+        EasyMock.expect(exchange.get(MessageHandlingTimeRecorder.class)).andReturn(null);     
+        exchange.put(EasyMock.eq(MessageHandlingTimeRecorder.class), 
+                     EasyMock.isA(MessageHandlingTimeRecorder.class));
+        EasyMock.replay(exchange);
+        EasyMock.replay(message);
+        rtmoi.handleMessage(message);        
+        EasyMock.verify(message);        
+        EasyMock.verify(exchange);
+        
+    }
+}

Propchange: incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageOutInterceptorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/interceptor/ResponseTimeMessageOutInterceptorTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/management/CountersClientServerTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/management/CountersClientServerTest.java?view=auto&rev=537737
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/management/CountersClientServerTest.java (added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/management/CountersClientServerTest.java Mon May 14 00:11:13 2007
@@ -0,0 +1,156 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.systest.management;
+
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.xml.namespace.QName;
+import javax.xml.ws.Endpoint;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.bus.spring.SpringBusFactory;
+import org.apache.cxf.management.InstrumentationManager;
+import org.apache.cxf.management.counters.Counter;
+import org.apache.cxf.management.counters.CounterRepository;
+import org.apache.cxf.management.jmx.InstrumentationManagerImpl;
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+import org.apache.hello_world_soap_http.Greeter;
+import org.apache.hello_world_soap_http.GreeterImpl;
+import org.apache.hello_world_soap_http.SOAPService;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+
+public class CountersClientServerTest extends AbstractBusClientServerTestBase {
+    
+    private final QName portName = 
+        new QName("http://apache.org/hello_world_soap_http",
+                  "SoapPort"); 
+         
+    public static class Server extends AbstractBusTestServerBase {        
+        
+        protected void run() {
+            SpringBusFactory bf = new SpringBusFactory();
+            Bus bus = bf.createBus("org/apache/cxf/systest/management/counter-spring.xml", true);
+            BusFactory.setDefaultBus(bus);
+            Object implementor = new GreeterImpl();
+            Endpoint.publish("http://localhost:9000/SoapContext/SoapPort", implementor);
+        }
+
+        public static void main(String[] args) {
+            try {
+                Server s = new Server();
+                s.start();
+            } catch (Exception ex) {
+                ex.printStackTrace();
+                System.exit(-1);
+            } finally {
+                System.out.println("done!");
+            }
+        }
+    }
+    
+    @BeforeClass
+    public static void startServers() throws Exception {
+        assertTrue("server did not launch correctly", launchServer(Server.class, true));
+    }
+    
+    @Test
+    public void testCountersWithInstrumentationManager() throws Exception {
+        // create Client with other bus
+        Bus bus = BusFactory.getDefaultBus();
+                                
+        CounterRepository cr = bus.getExtension(CounterRepository.class);
+        InstrumentationManager im = bus.getExtension(InstrumentationManager.class);
+        assertNotNull(im);
+        InstrumentationManagerImpl impl = (InstrumentationManagerImpl)im;
+        assertTrue(impl.isEnabled());
+        assertNotNull(impl.getMBeanServer());
+        
+        MBeanServer mbs = im.getMBeanServer();
+        ObjectName name = new ObjectName(Counter.DEFAULT_DOMAIN_NAME 
+                                         + ":BusID=cxf" + bus.hashCode() + ",*");        
+        
+        SOAPService service = new SOAPService();
+        assertNotNull(service);        
+        
+        Greeter greeter = service.getPort(portName, Greeter.class);
+        
+        String response = new String("Bonjour");
+        String reply = greeter.sayHi();
+        
+        //assertNotNull("no response received from service", reply);
+        //assertEquals(response, reply);  
+        
+        assertEquals("The Counters are not create yet", 4, cr.getCounters().size());
+        Set counterNames = mbs.queryNames(name, null);
+        assertEquals("The Counters are not export to JMX ", 4, counterNames.size());
+       
+        ObjectName sayHiCounter =  new ObjectName(Counter.DEFAULT_DOMAIN_NAME 
+            + ":OperationName=\"{http://apache.org/hello_world_soap_http}sayHi\",*"); 
+        
+        Set s = mbs.queryNames(sayHiCounter, null);        
+        Iterator it = s.iterator();
+        
+        while (it.hasNext()) {
+            ObjectName counterName = (ObjectName)it.next();
+            Object val = mbs.getAttribute(counterName, "NumInvocations");    
+            assertEquals("Wrong Counters Number of Invocations", val, 1);
+        }
+                
+        reply = greeter.sayHi();
+        assertNotNull("no response received from service", reply);
+        assertEquals(response, reply); 
+        
+        s = mbs.queryNames(sayHiCounter, null);        
+        it = s.iterator();
+        
+        while (it.hasNext()) {
+            ObjectName counterName = (ObjectName)it.next();
+            Object val = mbs.getAttribute(counterName, "NumInvocations");    
+            assertEquals("Wrong Counters Number of Invocations", val, 2);
+        }
+        
+        greeter.greetMeOneWay("hello");
+        assertEquals("The Counters are not create yet", 6, cr.getCounters().size());
+        counterNames = mbs.queryNames(name, null);
+        assertEquals("The Counters are not export to JMX ", 6, counterNames.size());
+        
+        ObjectName greetMeOneWayCounter =  new ObjectName(Counter.DEFAULT_DOMAIN_NAME 
+            + ":OperationName=\"{http://apache.org/hello_world_soap_http}greetMeOneWay\",*");
+        
+        s = mbs.queryNames(greetMeOneWayCounter, null);        
+        it = s.iterator();
+        
+        while (it.hasNext()) {
+            ObjectName counterName = (ObjectName)it.next();
+            Object val = mbs.getAttribute(counterName, "NumInvocations");    
+            assertEquals("Wrong Counters Number of Invocations", val, 1);
+        }
+        
+       
+    }
+    
+}

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/management/CountersClientServerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/management/CountersClientServerTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/management/counter-spring.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/management/counter-spring.xml?view=auto&rev=537737
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/management/counter-spring.xml (added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/management/counter-spring.xml Mon May 14 00:11:13 2007
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements. See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership. The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License. You may obtain a copy of the License at
+ 
+  http://www.apache.org/licenses/LICENSE-2.0
+ 
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied. See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:im="http://cxf.apache.org/management"
+       xsi:schemaLocation="
+http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
+  
+    <bean id="org.apache.cxf.management.InstrumentationManager" class="org.apache.cxf.management.jmx.InstrumentationManagerImpl">
+        <property name="bus" ref="cxf" />
+        <property name="enabled" value="true" />
+        <property name="JMXServiceURL" value="service:jmx:rmi:///jndi/rmi://localhost:9914/jmxrmi" />
+    </bean>
+    
+    <bean id="org.apache.cxf.management.counters.CounterRepository" class="org.apache.cxf.management.counters.CounterRepository">
+        <property name="bus" ref="cxf" />        
+    </bean>
+ 
+</beans>
\ No newline at end of file



Mime
View raw message