You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2015/03/20 19:17:35 UTC
[3/4] cxf git commit: Move the metrics stuff into it's own "feature"
that can be activated as a feature
Move the metrics stuff into it's own "feature" that can be activated as a feature
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/fd5abbd3
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/fd5abbd3
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/fd5abbd3
Branch: refs/heads/master
Commit: fd5abbd3793e232638e4d0793ebb9765e49c638a
Parents: ad700a5
Author: Daniel Kulp <dk...@apache.org>
Authored: Fri Mar 20 13:44:14 2015 -0400
Committer: Daniel Kulp <dk...@apache.org>
Committed: Fri Mar 20 14:17:27 2015 -0400
----------------------------------------------------------------------
.../src/main/release/samples/throttling/pom.xml | 5 +
.../java/demo/throttling/server/Customer.java | 4 +-
.../server/CustomerMetricsInterceptor.java | 4 +-
.../java/demo/throttling/server/Server.java | 8 +-
.../src/main/release/samples/wsdl_first/pom.xml | 6 +-
.../resources/server-applicationContext.xml | 12 +-
rt/features/logging/pom.xml | 3 +
rt/features/metrics/pom.xml | 41 +++
.../org/apache/cxf/metrics/ExchangeMetrics.java | 79 +++++
.../org/apache/cxf/metrics/MetricsContext.java | 47 +++
.../org/apache/cxf/metrics/MetricsFeature.java | 57 ++++
.../org/apache/cxf/metrics/MetricsProvider.java | 34 ++
.../codahale/CodahaleMetricsContext.java | 152 +++++++++
.../codahale/CodahaleMetricsProvider.java | 133 ++++++++
.../AbstractMetricsInterceptor.java | 156 +++++++++
.../interceptors/CountingInputStream.java | 76 +++++
.../interceptors/CountingOutInterceptor.java | 47 +++
.../interceptors/CountingOutputStream.java | 49 +++
.../MetricsMessageInInterceptor.java | 53 +++
.../MetricsMessageInOneWayInterceptor.java | 39 +++
.../MetricsMessageInPreInvokeInterceptor.java | 43 +++
.../MetricsMessageOutInterceptor.java | 38 +++
.../resources/META-INF/cxf/bus-extensions.txt | 2 +
rt/features/throttling/pom.xml | 2 +
rt/management/pom.xml | 5 -
.../codahale/CodahaleMetricsContext.java | 149 ---------
.../codahale/CountingInputStream.java | 76 -----
.../codahale/CountingOutputStream.java | 49 ---
.../cxf/management/codahale/MessageMetrics.java | 77 -----
.../apache/cxf/management/codahale/Metrics.java | 321 -------------------
.../cxf/management/codahale/MetricsContext.java | 47 ---
rt/pom.xml | 1 +
32 files changed, 1074 insertions(+), 741 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/fd5abbd3/distribution/src/main/release/samples/throttling/pom.xml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/throttling/pom.xml b/distribution/src/main/release/samples/throttling/pom.xml
index c553c5f..4cf69c6 100644
--- a/distribution/src/main/release/samples/throttling/pom.xml
+++ b/distribution/src/main/release/samples/throttling/pom.xml
@@ -139,6 +139,11 @@
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-features-metrics</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-features-throttling</artifactId>
<version>${project.version}</version>
</dependency>
http://git-wip-us.apache.org/repos/asf/cxf/blob/fd5abbd3/distribution/src/main/release/samples/throttling/src/main/java/demo/throttling/server/Customer.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/throttling/src/main/java/demo/throttling/server/Customer.java b/distribution/src/main/release/samples/throttling/src/main/java/demo/throttling/server/Customer.java
index 184468c..eecad80 100644
--- a/distribution/src/main/release/samples/throttling/src/main/java/demo/throttling/server/Customer.java
+++ b/distribution/src/main/release/samples/throttling/src/main/java/demo/throttling/server/Customer.java
@@ -21,9 +21,9 @@ package demo.throttling.server;
import com.codahale.metrics.MetricRegistry;
-import org.apache.cxf.management.codahale.CodahaleMetricsContext;
-import org.apache.cxf.management.codahale.MetricsContext;
import org.apache.cxf.message.Message;
+import org.apache.cxf.metrics.MetricsContext;
+import org.apache.cxf.metrics.codahale.CodahaleMetricsContext;
/**
*
http://git-wip-us.apache.org/repos/asf/cxf/blob/fd5abbd3/distribution/src/main/release/samples/throttling/src/main/java/demo/throttling/server/CustomerMetricsInterceptor.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/throttling/src/main/java/demo/throttling/server/CustomerMetricsInterceptor.java b/distribution/src/main/release/samples/throttling/src/main/java/demo/throttling/server/CustomerMetricsInterceptor.java
index c84eaee..8339ad3 100644
--- a/distribution/src/main/release/samples/throttling/src/main/java/demo/throttling/server/CustomerMetricsInterceptor.java
+++ b/distribution/src/main/release/samples/throttling/src/main/java/demo/throttling/server/CustomerMetricsInterceptor.java
@@ -28,8 +28,8 @@ import org.apache.cxf.common.util.Base64Exception;
import org.apache.cxf.common.util.Base64Utility;
import org.apache.cxf.helpers.CastUtils;
import org.apache.cxf.interceptor.Fault;
-import org.apache.cxf.management.codahale.MessageMetrics;
import org.apache.cxf.message.Message;
+import org.apache.cxf.metrics.ExchangeMetrics;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;
@@ -47,7 +47,7 @@ public class CustomerMetricsInterceptor extends AbstractPhaseInterceptor<Message
@Override
public void handleMessage(Message message) throws Fault {
- MessageMetrics m = message.getExchange().get(MessageMetrics.class);
+ ExchangeMetrics m = message.getExchange().get(ExchangeMetrics.class);
if (m != null) {
Map<String, List<String>> h = CastUtils.cast((Map<?,?>)message.get(Message.PROTOCOL_HEADERS));
String auth = h.get("Authorization").toString();
http://git-wip-us.apache.org/repos/asf/cxf/blob/fd5abbd3/distribution/src/main/release/samples/throttling/src/main/java/demo/throttling/server/Server.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/throttling/src/main/java/demo/throttling/server/Server.java b/distribution/src/main/release/samples/throttling/src/main/java/demo/throttling/server/Server.java
index bb01535..926ae31 100644
--- a/distribution/src/main/release/samples/throttling/src/main/java/demo/throttling/server/Server.java
+++ b/distribution/src/main/release/samples/throttling/src/main/java/demo/throttling/server/Server.java
@@ -28,8 +28,8 @@ import com.codahale.metrics.MetricRegistry;
import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
-import org.apache.cxf.management.codahale.Metrics;
import org.apache.cxf.message.Message;
+import org.apache.cxf.metrics.MetricsFeature;
import org.apache.cxf.phase.Phase;
import org.apache.cxf.throttling.ThrottlingInterceptor;
import org.apache.cxf.throttling.ThrottlingManager;
@@ -47,9 +47,7 @@ public class Server {
Bus b = BusFactory.getDefaultBus();
MetricRegistry registry = new MetricRegistry();
- b.setExtension(registry, MetricRegistry.class);
- new Metrics(b);
-
+ b.setExtension(registry, MetricRegistry.class);
ThrottlingManager manager = new ThrottlingManager() {
@Override
@@ -68,7 +66,7 @@ public class Server {
Object implementor = new GreeterImpl();
String address = "http://localhost:9001/SoapContext/SoapPort";
- Endpoint.publish(address, implementor);
+ Endpoint.publish(address, implementor, new MetricsFeature());
}
public static void main(String args[]) throws Exception {
http://git-wip-us.apache.org/repos/asf/cxf/blob/fd5abbd3/distribution/src/main/release/samples/wsdl_first/pom.xml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/wsdl_first/pom.xml b/distribution/src/main/release/samples/wsdl_first/pom.xml
index ce78ec4..7e90755 100644
--- a/distribution/src/main/release/samples/wsdl_first/pom.xml
+++ b/distribution/src/main/release/samples/wsdl_first/pom.xml
@@ -262,6 +262,11 @@
<version>3.1.0-SNAPSHOT</version>
</dependency>
<dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-features-metrics</artifactId>
+ <version>3.1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.cxf.xjc-utils</groupId>
<artifactId>cxf-xjc-runtime</artifactId>
<version>${cxf.xjc-utils.version}</version>
@@ -279,7 +284,6 @@
<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId>
- <version>3.1.0</version>
</dependency>
</dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/cxf/blob/fd5abbd3/distribution/src/main/release/samples/wsdl_first/src/main/resources/server-applicationContext.xml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/wsdl_first/src/main/resources/server-applicationContext.xml b/distribution/src/main/release/samples/wsdl_first/src/main/resources/server-applicationContext.xml
index 59b247d..623bbb9 100644
--- a/distribution/src/main/release/samples/wsdl_first/src/main/resources/server-applicationContext.xml
+++ b/distribution/src/main/release/samples/wsdl_first/src/main/resources/server-applicationContext.xml
@@ -18,7 +18,11 @@
xmlns:cxf="http://cxf.apache.org/core"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd ">
- <cxf:bus name="cxf"/>
+ <cxf:bus name="cxf">
+ <cxf:features>
+ <bean class="org.apache.cxf.metrics.MetricsFeature"/>
+ </cxf:features>
+ </cxf:bus>
<bean id="org.apache.cxf.management.InstrumentationManager" class="org.apache.cxf.management.jmx.InstrumentationManagerImpl"
init-method="init">
@@ -28,13 +32,7 @@
</bean>
<bean id="org.apache.cxf.management.counters.CounterRepository" class="org.apache.cxf.management.counters.CounterRepository">
<property name="bus" ref="cxf"/>
-
</bean>
- <bean id="org.apache.cxf.management.codahale.Metrics" class="org.apache.cxf.management.codahale.Metrics">
- <property name="bus" ref="cxf"/>
-
- </bean>
-
<!-- HTTP Endpoint -->
<jaxws:endpoint xmlns:customer="http://customerservice.example.com/" id="CustomerServiceHTTP" address="http://localhost:9090/CustomerServicePort" serviceName="customer:CustomerServiceService" endpointName="customer:CustomerServiceEndpoint" implementor="com.example.customerservice.server.CustomerServiceImpl">
http://git-wip-us.apache.org/repos/asf/cxf/blob/fd5abbd3/rt/features/logging/pom.xml
----------------------------------------------------------------------
diff --git a/rt/features/logging/pom.xml b/rt/features/logging/pom.xml
index 48f95bd..78c3333 100644
--- a/rt/features/logging/pom.xml
+++ b/rt/features/logging/pom.xml
@@ -12,6 +12,9 @@
<artifactId>cxf-rt-features-logging</artifactId>
<packaging>bundle</packaging>
+ <name>Apache CXF Advanced Logging Feature</name>
+ <description>Apache CXF Advanced Logging Feature</description>
+
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
http://git-wip-us.apache.org/repos/asf/cxf/blob/fd5abbd3/rt/features/metrics/pom.xml
----------------------------------------------------------------------
diff --git a/rt/features/metrics/pom.xml b/rt/features/metrics/pom.xml
new file mode 100644
index 0000000..5aa07d4
--- /dev/null
+++ b/rt/features/metrics/pom.xml
@@ -0,0 +1,41 @@
+<project
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-parent</artifactId>
+ <version>3.1.0-SNAPSHOT</version>
+ <relativePath>../../../parent/pom.xml</relativePath>
+ </parent>
+ <artifactId>cxf-rt-features-metrics</artifactId>
+ <packaging>bundle</packaging>
+ <name>Apache CXF Metrics Feature</name>
+ <description>Apache CXF Metrics Feature</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>io.dropwizard.metrics</groupId>
+ <artifactId>metrics-core</artifactId>
+ <optional>true</optional>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cxf/blob/fd5abbd3/rt/features/metrics/src/main/java/org/apache/cxf/metrics/ExchangeMetrics.java
----------------------------------------------------------------------
diff --git a/rt/features/metrics/src/main/java/org/apache/cxf/metrics/ExchangeMetrics.java b/rt/features/metrics/src/main/java/org/apache/cxf/metrics/ExchangeMetrics.java
new file mode 100644
index 0000000..342d921
--- /dev/null
+++ b/rt/features/metrics/src/main/java/org/apache/cxf/metrics/ExchangeMetrics.java
@@ -0,0 +1,79 @@
+/**
+ * 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.metrics;
+
+import java.util.Deque;
+import java.util.LinkedList;
+
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.metrics.interceptors.CountingInputStream;
+import org.apache.cxf.metrics.interceptors.CountingOutputStream;
+
+/**
+ *
+ */
+public class ExchangeMetrics {
+ Deque<MetricsContext> contexts = new LinkedList<MetricsContext>();
+ Exchange exchange;
+ boolean started;
+ long startTime = -1;
+
+ public ExchangeMetrics(Exchange e) {
+ exchange = e;
+ }
+
+ public ExchangeMetrics addContext(MetricsContext ctx) {
+ contexts.addLast(ctx);
+ if (started) {
+ ctx.start(exchange);
+ }
+ return this;
+ }
+
+ public void start() {
+ started = true;
+ startTime = System.nanoTime();
+ for (MetricsContext ctx : contexts) {
+ ctx.start(exchange);
+ }
+ }
+
+ public void stop() {
+ started = false;
+ if (startTime == -1) {
+ return;
+ }
+ CountingInputStream in = exchange.get(CountingInputStream.class);
+ long inSize = -1;
+ long outSize = -1;
+ if (in != null) {
+ inSize = in.getCount();
+ }
+ CountingOutputStream out = exchange.get(CountingOutputStream.class);
+ if (out != null) {
+ outSize = out.getCount();
+ }
+ long l = System.nanoTime() - startTime;
+ for (MetricsContext ctx : contexts) {
+ ctx.stop(l, inSize, outSize, exchange);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cxf/blob/fd5abbd3/rt/features/metrics/src/main/java/org/apache/cxf/metrics/MetricsContext.java
----------------------------------------------------------------------
diff --git a/rt/features/metrics/src/main/java/org/apache/cxf/metrics/MetricsContext.java b/rt/features/metrics/src/main/java/org/apache/cxf/metrics/MetricsContext.java
new file mode 100644
index 0000000..2c28b2e
--- /dev/null
+++ b/rt/features/metrics/src/main/java/org/apache/cxf/metrics/MetricsContext.java
@@ -0,0 +1,47 @@
+/**
+ * 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.metrics;
+
+
+import org.apache.cxf.message.Exchange;
+
+
+/**
+ * Class to hold all the various metric pieces for a given context (Endpoint, Customer, Operation, etc...)
+ */
+public interface MetricsContext {
+
+ /**
+ * Will be called at the start of invoke (or when added to a started MessageMetrics). This is
+ * when the metrics should increment "inFlight" counts and other stats. There is no need to
+ * record a "start time" as the invoke time will be passed into the stop method.
+ */
+ void start(Exchange m);
+
+ /**
+ * Called when the invocation is complete.
+ *
+ * @param timeInNS
+ * @param inSize
+ * @param outSize
+ * @param fm
+ */
+ void stop(long timeInNS, long inSize, long outSize, Exchange m);
+}
http://git-wip-us.apache.org/repos/asf/cxf/blob/fd5abbd3/rt/features/metrics/src/main/java/org/apache/cxf/metrics/MetricsFeature.java
----------------------------------------------------------------------
diff --git a/rt/features/metrics/src/main/java/org/apache/cxf/metrics/MetricsFeature.java b/rt/features/metrics/src/main/java/org/apache/cxf/metrics/MetricsFeature.java
new file mode 100644
index 0000000..9e8b363
--- /dev/null
+++ b/rt/features/metrics/src/main/java/org/apache/cxf/metrics/MetricsFeature.java
@@ -0,0 +1,57 @@
+/**
+ * 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.metrics;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.common.injection.NoJSR250Annotations;
+import org.apache.cxf.feature.AbstractFeature;
+import org.apache.cxf.interceptor.InterceptorProvider;
+import org.apache.cxf.metrics.interceptors.CountingOutInterceptor;
+import org.apache.cxf.metrics.interceptors.MetricsMessageInInterceptor;
+import org.apache.cxf.metrics.interceptors.MetricsMessageInOneWayInterceptor;
+import org.apache.cxf.metrics.interceptors.MetricsMessageInPreInvokeInterceptor;
+import org.apache.cxf.metrics.interceptors.MetricsMessageOutInterceptor;
+
+/**
+ *
+ */
+@NoJSR250Annotations
+public class MetricsFeature extends AbstractFeature {
+
+ /**
+ *
+ */
+ public MetricsFeature() {
+ }
+
+ @Override
+ protected void initializeProvider(InterceptorProvider provider, Bus bus) {
+ MetricsMessageOutInterceptor out = new MetricsMessageOutInterceptor();
+ CountingOutInterceptor countingOut = new CountingOutInterceptor();
+
+ provider.getInInterceptors().add(new MetricsMessageInInterceptor());
+ provider.getInInterceptors().add(new MetricsMessageInOneWayInterceptor());
+ provider.getInInterceptors().add(new MetricsMessageInPreInvokeInterceptor());
+ provider.getOutInterceptors().add(countingOut);
+ provider.getOutInterceptors().add(out);
+ provider.getOutFaultInterceptors().add(countingOut);
+ provider.getOutFaultInterceptors().add(out);
+ }
+}
http://git-wip-us.apache.org/repos/asf/cxf/blob/fd5abbd3/rt/features/metrics/src/main/java/org/apache/cxf/metrics/MetricsProvider.java
----------------------------------------------------------------------
diff --git a/rt/features/metrics/src/main/java/org/apache/cxf/metrics/MetricsProvider.java b/rt/features/metrics/src/main/java/org/apache/cxf/metrics/MetricsProvider.java
new file mode 100644
index 0000000..50d0fbd
--- /dev/null
+++ b/rt/features/metrics/src/main/java/org/apache/cxf/metrics/MetricsProvider.java
@@ -0,0 +1,34 @@
+/**
+ * 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.metrics;
+
+import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.service.model.BindingOperationInfo;
+
+/**
+ *
+ */
+public interface MetricsProvider {
+
+ MetricsContext createEndpointContext(Endpoint endpoint, boolean asClient);
+
+ MetricsContext createOperationContext(Endpoint endpoint, BindingOperationInfo boi, boolean asClient);
+
+}
http://git-wip-us.apache.org/repos/asf/cxf/blob/fd5abbd3/rt/features/metrics/src/main/java/org/apache/cxf/metrics/codahale/CodahaleMetricsContext.java
----------------------------------------------------------------------
diff --git a/rt/features/metrics/src/main/java/org/apache/cxf/metrics/codahale/CodahaleMetricsContext.java b/rt/features/metrics/src/main/java/org/apache/cxf/metrics/codahale/CodahaleMetricsContext.java
new file mode 100644
index 0000000..9670b55
--- /dev/null
+++ b/rt/features/metrics/src/main/java/org/apache/cxf/metrics/codahale/CodahaleMetricsContext.java
@@ -0,0 +1,152 @@
+/**
+ * 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.metrics.codahale;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.concurrent.TimeUnit;
+
+import com.codahale.metrics.Counter;
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.Timer;
+
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.FaultMode;
+import org.apache.cxf.metrics.MetricsContext;
+
+/**
+ *
+ */
+public class CodahaleMetricsContext implements MetricsContext, Closeable {
+ protected Counter inFlight;
+ protected Timer totals;
+ protected Timer uncheckedApplicationFaults;
+ protected Timer checkedApplicationFaults;
+ protected Timer runtimeFaults;
+ protected Timer logicalRuntimeFaults;
+ protected Meter incomingData;
+ protected Meter outgoingData;
+
+ protected final String baseName;
+ protected final MetricRegistry registry;
+
+ public CodahaleMetricsContext(String prefix, MetricRegistry registry) {
+ baseName = prefix;
+ this.registry = registry;
+ totals = registry.timer(baseName + "Attribute=Totals");
+ uncheckedApplicationFaults = registry.timer(baseName
+ + "Attribute=Unchecked Application Faults");
+ checkedApplicationFaults = registry.timer(baseName + "Attribute=Checked Application Faults");
+ runtimeFaults = registry.timer(baseName + "Attribute=Runtime Faults");
+ logicalRuntimeFaults = registry.timer(baseName + "Attribute=Logical Runtime Faults");
+ inFlight = registry.counter(baseName + "Attribute=In Flight");
+ incomingData = registry.meter(baseName + "Attribute=Data Read");
+ outgoingData = registry.meter(baseName + "Attribute=Data Written");
+ }
+
+ @Override
+ public void close() throws IOException {
+ registry.remove(baseName + "Attribute=Totals");
+ registry.remove(baseName + "Attribute=Unchecked Application Faults");
+ registry.remove(baseName + "Attribute=Checked Application Faults");
+ registry.remove(baseName + "Attribute=Runtime Faults");
+ registry.remove(baseName + "Attribute=Logical Runtime Faults");
+ registry.remove(baseName + "Attribute=In Flight");
+ registry.remove(baseName + "Attribute=Data Read");
+ registry.remove(baseName + "Attribute=Data Written");
+ }
+
+
+ public void start(Exchange ex) {
+ inFlight.inc();
+ }
+
+ public void stop(long timeInNS, long inSize, long outSize, Exchange ex) {
+ totals.update(timeInNS, TimeUnit.NANOSECONDS);
+
+ if (inSize != -1) {
+ incomingData.mark(inSize);
+ }
+ if (outSize != -1) {
+ outgoingData.mark(outSize);
+ }
+ FaultMode fm = ex.get(FaultMode.class);
+ if (fm != null) {
+ switch (fm) {
+ case CHECKED_APPLICATION_FAULT:
+ checkedApplicationFaults.update(timeInNS, TimeUnit.NANOSECONDS);
+ break;
+ case UNCHECKED_APPLICATION_FAULT:
+ uncheckedApplicationFaults.update(timeInNS, TimeUnit.NANOSECONDS);
+ break;
+ case RUNTIME_FAULT:
+ runtimeFaults.update(timeInNS, TimeUnit.NANOSECONDS);
+ break;
+ case LOGICAL_RUNTIME_FAULT:
+ logicalRuntimeFaults.update(timeInNS, TimeUnit.NANOSECONDS);
+ break;
+ default:
+ }
+ }
+ inFlight.dec();
+ }
+
+ public Counter getInFlight() {
+ return inFlight;
+ }
+
+ public Timer getTotals() {
+ return totals;
+ }
+
+ public Timer getUncheckedApplicationFaults() {
+ return uncheckedApplicationFaults;
+ }
+
+ public Timer getCheckedApplicationFaults() {
+ return checkedApplicationFaults;
+ }
+
+ public Timer getRuntimeFaults() {
+ return runtimeFaults;
+ }
+
+ public Timer getLogicalRuntimeFaults() {
+ return logicalRuntimeFaults;
+ }
+
+ public Meter getIncomingData() {
+ return incomingData;
+ }
+
+ public Meter getOutgoingData() {
+ return outgoingData;
+ }
+
+ public String getBaseName() {
+ return baseName;
+ }
+
+ public MetricRegistry getRegistry() {
+ return registry;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cxf/blob/fd5abbd3/rt/features/metrics/src/main/java/org/apache/cxf/metrics/codahale/CodahaleMetricsProvider.java
----------------------------------------------------------------------
diff --git a/rt/features/metrics/src/main/java/org/apache/cxf/metrics/codahale/CodahaleMetricsProvider.java b/rt/features/metrics/src/main/java/org/apache/cxf/metrics/codahale/CodahaleMetricsProvider.java
new file mode 100644
index 0000000..818dfe4
--- /dev/null
+++ b/rt/features/metrics/src/main/java/org/apache/cxf/metrics/codahale/CodahaleMetricsProvider.java
@@ -0,0 +1,133 @@
+/**
+ * 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.metrics.codahale;
+
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import com.codahale.metrics.JmxReporter;
+import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.ObjectNameFactory;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.common.injection.NoJSR250Annotations;
+import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.management.InstrumentationManager;
+import org.apache.cxf.management.ManagementConstants;
+import org.apache.cxf.metrics.MetricsContext;
+import org.apache.cxf.metrics.MetricsProvider;
+import org.apache.cxf.service.Service;
+import org.apache.cxf.service.model.BindingOperationInfo;
+
+/**
+ *
+ */
+@NoJSR250Annotations
+public class CodahaleMetricsProvider implements MetricsProvider {
+ private static final String QUESTION_MARK = "?";
+ private static final String ESCAPED_QUESTION_MARK = "\\?";
+
+ protected Bus bus;
+ protected MetricRegistry registry;
+
+ /**
+ *
+ */
+ public CodahaleMetricsProvider(Bus b) {
+ this.bus = b;
+ registry = b.getExtension(MetricRegistry.class);
+ bus = b;
+ if (registry == null) {
+ registry = new MetricRegistry();
+ setupJMXReporter(b, registry);
+ }
+
+ }
+
+ protected final void setupJMXReporter(Bus b, MetricRegistry reg) {
+ InstrumentationManager im = b.getExtension(InstrumentationManager.class);
+ if (im != null) {
+ JmxReporter reporter = JmxReporter.forRegistry(reg).registerWith(im.getMBeanServer())
+ .inDomain("org.apache.cxf")
+ .createsObjectNamesWith(new ObjectNameFactory() {
+ public ObjectName createName(String type, String domain, String name) {
+ try {
+ return new ObjectName(name);
+ } catch (MalformedObjectNameException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ })
+ .build();
+ reporter.start();
+ }
+ }
+
+ protected String escapePatternChars(String value) {
+ // This can be replaced if really needed with pattern-based matching
+ if (value.lastIndexOf(QUESTION_MARK) != -1) {
+ value = value.replace(QUESTION_MARK, ESCAPED_QUESTION_MARK);
+ }
+ return value;
+ }
+
+ StringBuilder getBaseServiceName(Endpoint endpoint, boolean asClient) {
+ StringBuilder buffer = new StringBuilder();
+ if (endpoint.get("org.apache.cxf.management.service.counter.name") != null) {
+ buffer.append((String)endpoint.get("org.apache.cxf.management.service.counter.name"));
+ } else {
+ Service service = endpoint.getService();
+
+ 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() + ",");
+ buffer.append(ManagementConstants.TYPE_PROP).append("=Metrics");
+ if (asClient) {
+ buffer.append(".Client,");
+ } else {
+ buffer.append(".Server,");
+ }
+ buffer.append(ManagementConstants.SERVICE_NAME_PROP + "=" + serviceName + ",");
+
+ buffer.append(ManagementConstants.PORT_NAME_PROP + "=" + portName + ",");
+ }
+ return buffer;
+ }
+
+
+ /** {@inheritDoc}*/
+ @Override
+ public MetricsContext createEndpointContext(final Endpoint endpoint, boolean asClient) {
+ StringBuilder buffer = getBaseServiceName(endpoint, asClient);
+ final String baseName = buffer.toString();
+ return new CodahaleMetricsContext(baseName, registry);
+ }
+
+ /** {@inheritDoc}*/
+ @Override
+ public MetricsContext createOperationContext(Endpoint endpoint, BindingOperationInfo boi, boolean asClient) {
+ StringBuilder buffer = getBaseServiceName(endpoint, asClient);
+ buffer.append("Operation=").append(boi.getName().getLocalPart()).append(',');
+ return new CodahaleMetricsContext(buffer.toString(), registry);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cxf/blob/fd5abbd3/rt/features/metrics/src/main/java/org/apache/cxf/metrics/interceptors/AbstractMetricsInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/features/metrics/src/main/java/org/apache/cxf/metrics/interceptors/AbstractMetricsInterceptor.java b/rt/features/metrics/src/main/java/org/apache/cxf/metrics/interceptors/AbstractMetricsInterceptor.java
new file mode 100644
index 0000000..97eeb2d
--- /dev/null
+++ b/rt/features/metrics/src/main/java/org/apache/cxf/metrics/interceptors/AbstractMetricsInterceptor.java
@@ -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.metrics.interceptors;
+
+import java.io.Closeable;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.cxf.configuration.ConfiguredBeanLocator;
+import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageUtils;
+import org.apache.cxf.metrics.ExchangeMetrics;
+import org.apache.cxf.metrics.MetricsContext;
+import org.apache.cxf.metrics.MetricsProvider;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.service.model.BindingOperationInfo;
+
+
+
+public abstract class AbstractMetricsInterceptor extends AbstractPhaseInterceptor<Message> {
+
+ public AbstractMetricsInterceptor(String phase) {
+ super(phase);
+ }
+
+ protected ExchangeMetrics getExchangeMetrics(Message m, boolean create) {
+ ExchangeMetrics ctx = m.getExchange().get(ExchangeMetrics.class);
+ if (ctx == null && create) {
+ ctx = new ExchangeMetrics(m.getExchange());
+ m.getExchange().put(ExchangeMetrics.class, ctx);
+
+ addEndpointMetrics(ctx, m);
+ }
+ return ctx;
+ }
+
+ private void addEndpointMetrics(ExchangeMetrics ctx, Message m) {
+ Endpoint ep = m.getExchange().getEndpoint();
+ Object o = ep.get(MetricsContext.class.getName());
+ if (o == null) {
+ synchronized (ep) {
+ o = createEndpointMetrics(m);
+ }
+ }
+ if (o instanceof List) {
+ List<MetricsContext> list = CastUtils.cast((List<?>)o);
+ for (MetricsContext c : list) {
+ ctx.addContext(c);
+ }
+ } else if (o instanceof MetricsContext) {
+ ctx.addContext((MetricsContext)o);
+ }
+ }
+
+ private Object createEndpointMetrics(Message m) {
+ final Endpoint ep = m.getExchange().getEndpoint();
+ Object o = ep.get(MetricsContext.class.getName());
+ if (o == null) {
+ ConfiguredBeanLocator b = m.getExchange().getBus().getExtension(ConfiguredBeanLocator.class);
+ if (b == null) {
+ return null;
+ }
+ List<MetricsContext> contexts = new ArrayList<MetricsContext>();
+ for (MetricsProvider p : b.getBeansOfType(MetricsProvider.class)) {
+ MetricsContext c = p.createEndpointContext(ep, MessageUtils.isRequestor(m));
+ if (c != null) {
+ contexts.add(c);
+ }
+ if (c instanceof Closeable) {
+ ep.addCleanupHook((Closeable)c);
+ }
+ }
+ if (contexts.size() == 1) {
+ o = contexts.get(0);
+ } else {
+ o = contexts;
+ }
+ ep.put(MetricsContext.class.getName(), o);
+ }
+ return o;
+ }
+
+ protected void addOperationMetrics(ExchangeMetrics ctx, Message m, BindingOperationInfo boi) {
+ if (boi.isUnwrapped()) {
+ boi = boi.getWrappedOperation();
+ }
+ Object o = boi.getProperty(MetricsContext.class.getName());
+ if (o == null) {
+ synchronized (boi) {
+ o = createMetricsContextForOperation(m, boi);
+ }
+ }
+ if (o instanceof List) {
+ List<MetricsContext> list = CastUtils.cast((List<?>)o);
+ for (MetricsContext c : list) {
+ ctx.addContext(c);
+ }
+ } else if (o instanceof MetricsContext) {
+ ctx.addContext((MetricsContext)o);
+ }
+ }
+
+ private Object createMetricsContextForOperation(Message message, BindingOperationInfo boi) {
+ Object o = boi.getProperty(MetricsContext.class.getName());
+ if (o == null) {
+ ConfiguredBeanLocator b = message.getExchange().getBus().getExtension(ConfiguredBeanLocator.class);
+ if (b == null) {
+ return null;
+ }
+ List<MetricsContext> contexts = new ArrayList<MetricsContext>();
+ for (MetricsProvider p : b.getBeansOfType(MetricsProvider.class)) {
+ MetricsContext c = p.createOperationContext(message.getExchange().getEndpoint(),
+ boi, MessageUtils.isRequestor(message));
+ if (c != null) {
+ contexts.add(c);
+ }
+ if (c instanceof Closeable) {
+ message.getExchange().getEndpoint().addCleanupHook((Closeable)c);
+ }
+ }
+ if (contexts.size() == 1) {
+ o = contexts.get(0);
+ } else {
+ o = contexts;
+ }
+ boi.setProperty(MetricsContext.class.getName(), o);
+ }
+ return o;
+ }
+
+ public void stop(Message m) {
+ ExchangeMetrics ctx = getExchangeMetrics(m, false);
+ if (ctx != null) {
+ ctx.stop();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/cxf/blob/fd5abbd3/rt/features/metrics/src/main/java/org/apache/cxf/metrics/interceptors/CountingInputStream.java
----------------------------------------------------------------------
diff --git a/rt/features/metrics/src/main/java/org/apache/cxf/metrics/interceptors/CountingInputStream.java b/rt/features/metrics/src/main/java/org/apache/cxf/metrics/interceptors/CountingInputStream.java
new file mode 100644
index 0000000..e6cb5f3
--- /dev/null
+++ b/rt/features/metrics/src/main/java/org/apache/cxf/metrics/interceptors/CountingInputStream.java
@@ -0,0 +1,76 @@
+/**
+ * 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.metrics.interceptors;
+
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+public final class CountingInputStream extends FilterInputStream {
+
+ private long count;
+ private long mark = -1;
+
+ public CountingInputStream(InputStream in) {
+ super(in);
+ }
+
+ public long getCount() {
+ return count;
+ }
+
+ public int read() throws IOException {
+ int result = in.read();
+ if (result != -1) {
+ count++;
+ }
+ return result;
+ }
+
+ public int read(byte[] b, int off, int len) throws IOException {
+ int result = in.read(b, off, len);
+ if (result != -1) {
+ count += result;
+ }
+ return result;
+ }
+
+ public long skip(long n) throws IOException {
+ long result = in.skip(n);
+ count += result;
+ return result;
+ }
+
+ public synchronized void mark(int readlimit) {
+ in.mark(readlimit);
+ mark = count;
+ }
+
+ public synchronized void reset() throws IOException {
+ if (!in.markSupported()) {
+ throw new IOException("Mark not supported");
+ }
+ if (mark == -1) {
+ throw new IOException("Mark not set");
+ }
+
+ in.reset();
+ count = mark;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cxf/blob/fd5abbd3/rt/features/metrics/src/main/java/org/apache/cxf/metrics/interceptors/CountingOutInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/features/metrics/src/main/java/org/apache/cxf/metrics/interceptors/CountingOutInterceptor.java b/rt/features/metrics/src/main/java/org/apache/cxf/metrics/interceptors/CountingOutInterceptor.java
new file mode 100644
index 0000000..4d20a9d
--- /dev/null
+++ b/rt/features/metrics/src/main/java/org/apache/cxf/metrics/interceptors/CountingOutInterceptor.java
@@ -0,0 +1,47 @@
+/**
+ * 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.metrics.interceptors;
+
+import java.io.OutputStream;
+
+import org.apache.cxf.interceptor.AttachmentOutInterceptor;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+
+public class CountingOutInterceptor extends AbstractPhaseInterceptor<Message> {
+ public CountingOutInterceptor() {
+ super(Phase.PRE_STREAM);
+ addBefore(AttachmentOutInterceptor.class.getName());
+ }
+ public void handleMessage(Message message) throws Fault {
+ if (isRequestor(message)) {
+ //
+ } else {
+ OutputStream out = message.getContent(OutputStream.class);
+ if (out != null) {
+ CountingOutputStream newOut = new CountingOutputStream(out);
+ message.setContent(OutputStream.class, newOut);
+ message.getExchange().put(CountingOutputStream.class, newOut);
+ }
+
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cxf/blob/fd5abbd3/rt/features/metrics/src/main/java/org/apache/cxf/metrics/interceptors/CountingOutputStream.java
----------------------------------------------------------------------
diff --git a/rt/features/metrics/src/main/java/org/apache/cxf/metrics/interceptors/CountingOutputStream.java b/rt/features/metrics/src/main/java/org/apache/cxf/metrics/interceptors/CountingOutputStream.java
new file mode 100644
index 0000000..5247e21
--- /dev/null
+++ b/rt/features/metrics/src/main/java/org/apache/cxf/metrics/interceptors/CountingOutputStream.java
@@ -0,0 +1,49 @@
+/**
+ * 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.metrics.interceptors;
+
+import java.io.FilterOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+public final class CountingOutputStream extends FilterOutputStream {
+ private long count;
+
+ public CountingOutputStream(OutputStream out) {
+ super(out);
+ }
+
+ public long getCount() {
+ return count;
+ }
+
+ public void write(byte[] b, int off, int len) throws IOException {
+ out.write(b, off, len);
+ count += len;
+ }
+
+ public void write(int b) throws IOException {
+ out.write(b);
+ count++;
+ }
+
+ public void close() throws IOException {
+ out.close();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cxf/blob/fd5abbd3/rt/features/metrics/src/main/java/org/apache/cxf/metrics/interceptors/MetricsMessageInInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/features/metrics/src/main/java/org/apache/cxf/metrics/interceptors/MetricsMessageInInterceptor.java b/rt/features/metrics/src/main/java/org/apache/cxf/metrics/interceptors/MetricsMessageInInterceptor.java
new file mode 100644
index 0000000..75d6f5c
--- /dev/null
+++ b/rt/features/metrics/src/main/java/org/apache/cxf/metrics/interceptors/MetricsMessageInInterceptor.java
@@ -0,0 +1,53 @@
+/**
+ * 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.metrics.interceptors;
+
+import java.io.InputStream;
+
+import org.apache.cxf.interceptor.AttachmentInInterceptor;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.metrics.ExchangeMetrics;
+import org.apache.cxf.phase.Phase;
+
+public class MetricsMessageInInterceptor extends AbstractMetricsInterceptor {
+ public MetricsMessageInInterceptor() {
+ super(Phase.RECEIVE);
+ addBefore(AttachmentInInterceptor.class.getName());
+ }
+ public void handleMessage(Message message) throws Fault {
+ if (isRequestor(message)) {
+ //
+ } else {
+ ExchangeMetrics ctx = getExchangeMetrics(message, true);
+ InputStream in = message.getContent(InputStream.class);
+ if (in != null) {
+ CountingInputStream newIn = new CountingInputStream(in);
+ message.setContent(InputStream.class, newIn);
+ message.getExchange().put(CountingInputStream.class, newIn);
+ }
+ ctx.start();
+ }
+ }
+ public void handleFault(Message message) {
+ if (message.getExchange().isOneWay()) {
+ stop(message);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cxf/blob/fd5abbd3/rt/features/metrics/src/main/java/org/apache/cxf/metrics/interceptors/MetricsMessageInOneWayInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/features/metrics/src/main/java/org/apache/cxf/metrics/interceptors/MetricsMessageInOneWayInterceptor.java b/rt/features/metrics/src/main/java/org/apache/cxf/metrics/interceptors/MetricsMessageInOneWayInterceptor.java
new file mode 100644
index 0000000..9f99954
--- /dev/null
+++ b/rt/features/metrics/src/main/java/org/apache/cxf/metrics/interceptors/MetricsMessageInOneWayInterceptor.java
@@ -0,0 +1,39 @@
+/**
+ * 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.metrics.interceptors;
+
+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;
+
+public class MetricsMessageInOneWayInterceptor extends AbstractMetricsInterceptor {
+ public MetricsMessageInOneWayInterceptor() {
+ super(Phase.INVOKE);
+ addAfter(ServiceInvokerInterceptor.class.getName());
+ }
+
+ public void handleMessage(Message message) throws Fault {
+ Exchange ex = message.getExchange();
+ if (ex.isOneWay() && !isRequestor(message)) {
+ stop(message);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cxf/blob/fd5abbd3/rt/features/metrics/src/main/java/org/apache/cxf/metrics/interceptors/MetricsMessageInPreInvokeInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/features/metrics/src/main/java/org/apache/cxf/metrics/interceptors/MetricsMessageInPreInvokeInterceptor.java b/rt/features/metrics/src/main/java/org/apache/cxf/metrics/interceptors/MetricsMessageInPreInvokeInterceptor.java
new file mode 100644
index 0000000..f614ffb
--- /dev/null
+++ b/rt/features/metrics/src/main/java/org/apache/cxf/metrics/interceptors/MetricsMessageInPreInvokeInterceptor.java
@@ -0,0 +1,43 @@
+/**
+ * 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.metrics.interceptors;
+
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.metrics.ExchangeMetrics;
+import org.apache.cxf.phase.Phase;
+
+public class MetricsMessageInPreInvokeInterceptor extends AbstractMetricsInterceptor {
+
+ public MetricsMessageInPreInvokeInterceptor() {
+ super(Phase.PRE_INVOKE);
+ }
+
+ public void handleMessage(Message message) throws Fault {
+ Exchange ex = message.getExchange();
+ if (ex.getBindingOperationInfo() != null) {
+ //we now know the operation, start metrics for it
+ ExchangeMetrics ctx = getExchangeMetrics(message, false);
+ if (ctx != null) {
+ addOperationMetrics(ctx, message, ex.getBindingOperationInfo());
+ }
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cxf/blob/fd5abbd3/rt/features/metrics/src/main/java/org/apache/cxf/metrics/interceptors/MetricsMessageOutInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/features/metrics/src/main/java/org/apache/cxf/metrics/interceptors/MetricsMessageOutInterceptor.java b/rt/features/metrics/src/main/java/org/apache/cxf/metrics/interceptors/MetricsMessageOutInterceptor.java
new file mode 100644
index 0000000..c993a2a
--- /dev/null
+++ b/rt/features/metrics/src/main/java/org/apache/cxf/metrics/interceptors/MetricsMessageOutInterceptor.java
@@ -0,0 +1,38 @@
+/**
+ * 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.metrics.interceptors;
+
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.interceptor.MessageSenderInterceptor;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.Phase;
+
+public class MetricsMessageOutInterceptor extends AbstractMetricsInterceptor {
+ public MetricsMessageOutInterceptor() {
+ super(Phase.PREPARE_SEND_ENDING);
+ addBefore(MessageSenderInterceptor.MessageSenderEndingInterceptor.class.getName());
+ }
+ public void handleMessage(Message message) throws Fault {
+ if (isRequestor(message)) {
+ //
+ } else {
+ stop(message);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cxf/blob/fd5abbd3/rt/features/metrics/src/main/resources/META-INF/cxf/bus-extensions.txt
----------------------------------------------------------------------
diff --git a/rt/features/metrics/src/main/resources/META-INF/cxf/bus-extensions.txt b/rt/features/metrics/src/main/resources/META-INF/cxf/bus-extensions.txt
new file mode 100644
index 0000000..33976dd
--- /dev/null
+++ b/rt/features/metrics/src/main/resources/META-INF/cxf/bus-extensions.txt
@@ -0,0 +1,2 @@
+org.apache.cxf.metrics.codahale.CodahaleMetricsProvider:org.apache.cxf.metrics.MetricsProvider:true:true
+
http://git-wip-us.apache.org/repos/asf/cxf/blob/fd5abbd3/rt/features/throttling/pom.xml
----------------------------------------------------------------------
diff --git a/rt/features/throttling/pom.xml b/rt/features/throttling/pom.xml
index 1cf7d1c..0b43671 100644
--- a/rt/features/throttling/pom.xml
+++ b/rt/features/throttling/pom.xml
@@ -11,6 +11,8 @@
</parent>
<artifactId>cxf-rt-features-throttling</artifactId>
<packaging>bundle</packaging>
+ <name>Apache CXF Throttling Feature</name>
+ <description>Apache CXF Throttling Feature</description>
<dependencies>
<dependency>
http://git-wip-us.apache.org/repos/asf/cxf/blob/fd5abbd3/rt/management/pom.xml
----------------------------------------------------------------------
diff --git a/rt/management/pom.xml b/rt/management/pom.xml
index ed034af..1239711 100644
--- a/rt/management/pom.xml
+++ b/rt/management/pom.xml
@@ -42,11 +42,6 @@
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>io.dropwizard.metrics</groupId>
- <artifactId>metrics-core</artifactId>
- <optional>true</optional>
- </dependency>
- <dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<scope>test</scope>
http://git-wip-us.apache.org/repos/asf/cxf/blob/fd5abbd3/rt/management/src/main/java/org/apache/cxf/management/codahale/CodahaleMetricsContext.java
----------------------------------------------------------------------
diff --git a/rt/management/src/main/java/org/apache/cxf/management/codahale/CodahaleMetricsContext.java b/rt/management/src/main/java/org/apache/cxf/management/codahale/CodahaleMetricsContext.java
deleted file mode 100644
index 8c547b3..0000000
--- a/rt/management/src/main/java/org/apache/cxf/management/codahale/CodahaleMetricsContext.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/**
- * 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.codahale;
-
-import java.io.Closeable;
-import java.io.IOException;
-import java.util.concurrent.TimeUnit;
-
-import com.codahale.metrics.Counter;
-import com.codahale.metrics.Meter;
-import com.codahale.metrics.MetricRegistry;
-import com.codahale.metrics.Timer;
-
-import org.apache.cxf.message.FaultMode;
-
-/**
- *
- */
-public class CodahaleMetricsContext implements MetricsContext, Closeable {
- protected Counter inFlight;
- protected Timer totals;
- protected Timer uncheckedApplicationFaults;
- protected Timer checkedApplicationFaults;
- protected Timer runtimeFaults;
- protected Timer logicalRuntimeFaults;
- protected Meter incomingData;
- protected Meter outgoingData;
-
- protected final String baseName;
- protected final MetricRegistry registry;
-
- public CodahaleMetricsContext(String prefix, MetricRegistry registry) {
- baseName = prefix;
- this.registry = registry;
- totals = registry.timer(baseName + "Attribute=Totals");
- uncheckedApplicationFaults = registry.timer(baseName
- + "Attribute=Unchecked Application Faults");
- checkedApplicationFaults = registry.timer(baseName + "Attribute=Checked Application Faults");
- runtimeFaults = registry.timer(baseName + "Attribute=Runtime Faults");
- logicalRuntimeFaults = registry.timer(baseName + "Attribute=Logical Runtime Faults");
- inFlight = registry.counter(baseName + "Attribute=In Flight");
- incomingData = registry.meter(baseName + "Attribute=Data Read");
- outgoingData = registry.meter(baseName + "Attribute=Data Written");
- }
-
- @Override
- public void close() throws IOException {
- registry.remove(baseName + "Attribute=Totals");
- registry.remove(baseName + "Attribute=Unchecked Application Faults");
- registry.remove(baseName + "Attribute=Checked Application Faults");
- registry.remove(baseName + "Attribute=Runtime Faults");
- registry.remove(baseName + "Attribute=Logical Runtime Faults");
- registry.remove(baseName + "Attribute=In Flight");
- registry.remove(baseName + "Attribute=Data Read");
- registry.remove(baseName + "Attribute=Data Written");
- }
-
-
- public void start() {
- inFlight.inc();
- }
-
- public void stop(long timeInNS, long inSize, long outSize, FaultMode fm) {
- totals.update(timeInNS, TimeUnit.NANOSECONDS);
-
- if (inSize != -1) {
- incomingData.mark(inSize);
- }
- if (outSize != -1) {
- outgoingData.mark(outSize);
- }
- if (fm != null) {
- switch (fm) {
- case CHECKED_APPLICATION_FAULT:
- checkedApplicationFaults.update(timeInNS, TimeUnit.NANOSECONDS);
- break;
- case UNCHECKED_APPLICATION_FAULT:
- uncheckedApplicationFaults.update(timeInNS, TimeUnit.NANOSECONDS);
- break;
- case RUNTIME_FAULT:
- runtimeFaults.update(timeInNS, TimeUnit.NANOSECONDS);
- break;
- case LOGICAL_RUNTIME_FAULT:
- logicalRuntimeFaults.update(timeInNS, TimeUnit.NANOSECONDS);
- break;
- default:
- }
- }
- inFlight.dec();
- }
-
- public Counter getInFlight() {
- return inFlight;
- }
-
- public Timer getTotals() {
- return totals;
- }
-
- public Timer getUncheckedApplicationFaults() {
- return uncheckedApplicationFaults;
- }
-
- public Timer getCheckedApplicationFaults() {
- return checkedApplicationFaults;
- }
-
- public Timer getRuntimeFaults() {
- return runtimeFaults;
- }
-
- public Timer getLogicalRuntimeFaults() {
- return logicalRuntimeFaults;
- }
-
- public Meter getIncomingData() {
- return incomingData;
- }
-
- public Meter getOutgoingData() {
- return outgoingData;
- }
-
- public String getBaseName() {
- return baseName;
- }
-
- public MetricRegistry getRegistry() {
- return registry;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/cxf/blob/fd5abbd3/rt/management/src/main/java/org/apache/cxf/management/codahale/CountingInputStream.java
----------------------------------------------------------------------
diff --git a/rt/management/src/main/java/org/apache/cxf/management/codahale/CountingInputStream.java b/rt/management/src/main/java/org/apache/cxf/management/codahale/CountingInputStream.java
deleted file mode 100644
index 84d691d..0000000
--- a/rt/management/src/main/java/org/apache/cxf/management/codahale/CountingInputStream.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/**
- * 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.codahale;
-
-import java.io.FilterInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-public final class CountingInputStream extends FilterInputStream {
-
- private long count;
- private long mark = -1;
-
- public CountingInputStream(InputStream in) {
- super(in);
- }
-
- public long getCount() {
- return count;
- }
-
- public int read() throws IOException {
- int result = in.read();
- if (result != -1) {
- count++;
- }
- return result;
- }
-
- public int read(byte[] b, int off, int len) throws IOException {
- int result = in.read(b, off, len);
- if (result != -1) {
- count += result;
- }
- return result;
- }
-
- public long skip(long n) throws IOException {
- long result = in.skip(n);
- count += result;
- return result;
- }
-
- public synchronized void mark(int readlimit) {
- in.mark(readlimit);
- mark = count;
- }
-
- public synchronized void reset() throws IOException {
- if (!in.markSupported()) {
- throw new IOException("Mark not supported");
- }
- if (mark == -1) {
- throw new IOException("Mark not set");
- }
-
- in.reset();
- count = mark;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cxf/blob/fd5abbd3/rt/management/src/main/java/org/apache/cxf/management/codahale/CountingOutputStream.java
----------------------------------------------------------------------
diff --git a/rt/management/src/main/java/org/apache/cxf/management/codahale/CountingOutputStream.java b/rt/management/src/main/java/org/apache/cxf/management/codahale/CountingOutputStream.java
deleted file mode 100644
index bc5cffd..0000000
--- a/rt/management/src/main/java/org/apache/cxf/management/codahale/CountingOutputStream.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * 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.codahale;
-
-import java.io.FilterOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-
-public final class CountingOutputStream extends FilterOutputStream {
- private long count;
-
- public CountingOutputStream(OutputStream out) {
- super(out);
- }
-
- public long getCount() {
- return count;
- }
-
- public void write(byte[] b, int off, int len) throws IOException {
- out.write(b, off, len);
- count += len;
- }
-
- public void write(int b) throws IOException {
- out.write(b);
- count++;
- }
-
- public void close() throws IOException {
- out.close();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cxf/blob/fd5abbd3/rt/management/src/main/java/org/apache/cxf/management/codahale/MessageMetrics.java
----------------------------------------------------------------------
diff --git a/rt/management/src/main/java/org/apache/cxf/management/codahale/MessageMetrics.java b/rt/management/src/main/java/org/apache/cxf/management/codahale/MessageMetrics.java
deleted file mode 100644
index 3f4845b..0000000
--- a/rt/management/src/main/java/org/apache/cxf/management/codahale/MessageMetrics.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/**
- * 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.codahale;
-
-import java.util.Deque;
-import java.util.LinkedList;
-
-import org.apache.cxf.message.FaultMode;
-import org.apache.cxf.message.Message;
-
-/**
- *
- */
-public class MessageMetrics {
- Deque<MetricsContext> contexts = new LinkedList<MetricsContext>();
- boolean started;
- long startTime = -1;
-
- public MessageMetrics() {
- }
-
- public MessageMetrics addContext(MetricsContext ctx) {
- contexts.addLast(ctx);
- if (started) {
- ctx.start();
- }
- return this;
- }
-
- public void start() {
- started = true;
- startTime = System.nanoTime();
- for (MetricsContext ctx : contexts) {
- ctx.start();
- }
- }
-
- public void stop(Message m) {
- started = false;
- if (startTime == -1) {
- return;
- }
- FaultMode fm = m.getExchange().get(FaultMode.class);
- CountingInputStream in = m.getExchange().get(CountingInputStream.class);
- long inSize = -1;
- long outSize = -1;
- if (in != null) {
- inSize = in.getCount();
- }
- CountingOutputStream out = m.getExchange().get(CountingOutputStream.class);
- if (out != null) {
- outSize = out.getCount();
- }
- long l = System.nanoTime() - startTime;
- for (MetricsContext ctx : contexts) {
- ctx.stop(l, inSize, outSize, fm);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/cxf/blob/fd5abbd3/rt/management/src/main/java/org/apache/cxf/management/codahale/Metrics.java
----------------------------------------------------------------------
diff --git a/rt/management/src/main/java/org/apache/cxf/management/codahale/Metrics.java b/rt/management/src/main/java/org/apache/cxf/management/codahale/Metrics.java
deleted file mode 100644
index 09d90a5..0000000
--- a/rt/management/src/main/java/org/apache/cxf/management/codahale/Metrics.java
+++ /dev/null
@@ -1,321 +0,0 @@
-/**
- * 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.codahale;
-
-
-import java.io.Closeable;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-
-import com.codahale.metrics.JmxReporter;
-import com.codahale.metrics.MetricRegistry;
-import com.codahale.metrics.ObjectNameFactory;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.endpoint.Endpoint;
-import org.apache.cxf.interceptor.AttachmentInInterceptor;
-import org.apache.cxf.interceptor.AttachmentOutInterceptor;
-import org.apache.cxf.interceptor.Fault;
-import org.apache.cxf.interceptor.MessageSenderInterceptor;
-import org.apache.cxf.interceptor.ServiceInvokerInterceptor;
-import org.apache.cxf.management.InstrumentationManager;
-import org.apache.cxf.management.ManagementConstants;
-import org.apache.cxf.message.Exchange;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.message.MessageUtils;
-import org.apache.cxf.phase.AbstractPhaseInterceptor;
-import org.apache.cxf.phase.Phase;
-import org.apache.cxf.service.Service;
-import org.apache.cxf.service.model.BindingOperationInfo;
-
-public class Metrics {
- private static final String QUESTION_MARK = "?";
- private static final String ESCAPED_QUESTION_MARK = "\\?";
-
- private MetricRegistry registry;
- private Bus bus;
-
- public Metrics() {
- registry = new MetricRegistry();
- }
- public Metrics(MetricRegistry reg) {
- registry = reg;
- }
- public Metrics(Bus b) {
- registry = b.getExtension(MetricRegistry.class);
- bus = b;
- registerInterceptorsToBus();
- if (registry == null) {
- registry = new MetricRegistry();
- setupJMXReporter(b, registry);
- }
- }
-
- protected final void setupJMXReporter(Bus b, MetricRegistry reg) {
- InstrumentationManager im = b.getExtension(InstrumentationManager.class);
- if (im != null) {
- JmxReporter reporter = JmxReporter.forRegistry(reg).registerWith(im.getMBeanServer())
- .inDomain("org.apache.cxf")
- .createsObjectNamesWith(new ObjectNameFactory() {
- public ObjectName createName(String type, String domain, String name) {
- try {
- return new ObjectName(name);
- } catch (MalformedObjectNameException e) {
- throw new RuntimeException(e);
- }
- }
- })
- .build();
- reporter.start();
- }
- }
- public void setBus(Bus b) {
- bus = b;
- if (bus != null) {
- registerInterceptorsToBus();
- setupJMXReporter(bus, registry);
- }
- }
-
- public Bus getBus() {
- return bus;
- }
-
- private void registerInterceptorsToBus() {
- ResponseTimeMessageInInterceptor in = new ResponseTimeMessageInInterceptor();
- ResponseTimeMessageInOneWayInterceptor oneway = new ResponseTimeMessageInOneWayInterceptor();
- ResponseTimeMessageOutInterceptor out = new ResponseTimeMessageOutInterceptor();
- CountingOutInterceptor countingOut = new CountingOutInterceptor();
-
- bus.getInInterceptors().add(in);
- bus.getInInterceptors().add(oneway);
- bus.getInInterceptors().add(new ResponseTimeMessageInPreInvokeInterceptor());
- bus.getOutInterceptors().add(countingOut);
- bus.getOutInterceptors().add(out);
- bus.getOutFaultInterceptors().add(countingOut);
- bus.getOutFaultInterceptors().add(out);
- }
-
- MetricsContext getMetricsContextForEndpoint(Message message) {
- MetricsContext ti = (MetricsContext)message.getExchange().getEndpoint().get(MetricsContext.class.getName());
- if (ti == null) {
- synchronized (message.getExchange().getEndpoint()) {
- return createMetricsContextForEndpoint(message);
- }
- }
- return ti;
- }
- MetricsContext getMetricsContextForOperation(Message message, BindingOperationInfo boi) {
- if (boi.isUnwrapped()) {
- boi = boi.getWrappedOperation();
- }
- MetricsContext ti = (MetricsContext)boi.getProperty(MetricsContext.class.getName());
- if (ti == null) {
- synchronized (boi) {
- return createMetricsContextForOperation(message, boi);
- }
- }
- return ti;
- }
- private MetricsContext createMetricsContextForOperation(Message message, BindingOperationInfo boi) {
- MetricsContext ti = (MetricsContext)boi.getProperty(MetricsContext.class.getName());
- if (ti == null) {
- StringBuilder buffer = getBaseServiceName(message);
- buffer.append("Operation=").append(boi.getName().getLocalPart()).append(',');
- ti = new CodahaleMetricsContext(buffer.toString(), registry);
- boi.setProperty(MetricsContext.class.getName(), ti);
- }
- return ti;
- }
- StringBuilder getBaseServiceName(Message message) {
- Exchange ex = message.getExchange();
- StringBuilder buffer = new StringBuilder();
- if (ex.get("org.apache.cxf.management.service.counter.name") != null) {
- buffer.append((String)ex.get("org.apache.cxf.management.service.counter.name"));
- } else {
- Service service = ex.getService();
- Endpoint endpoint = ex.getEndpoint();
- Bus b = ex.getBus();
-
- String serviceName = "\"" + escapePatternChars(service.getName().toString()) + "\"";
- String portName = "\"" + endpoint.getEndpointInfo().getName().getLocalPart() + "\"";
-
- buffer.append(ManagementConstants.DEFAULT_DOMAIN_NAME + ":");
- buffer.append(ManagementConstants.BUS_ID_PROP + "=" + b.getId() + ",");
- buffer.append(ManagementConstants.TYPE_PROP).append("=Metrics");
- if (MessageUtils.isRequestor(message)) {
- buffer.append(".Client,");
- } else {
- buffer.append(".Server,");
- }
- buffer.append(ManagementConstants.SERVICE_NAME_PROP + "=" + serviceName + ",");
-
- buffer.append(ManagementConstants.PORT_NAME_PROP + "=" + portName + ",");
- }
- return buffer;
- }
- private MetricsContext createMetricsContextForEndpoint(Message message) {
- Exchange ex = message.getExchange();
- final Endpoint endpoint = ex.get(Endpoint.class);
- MetricsContext ti = (MetricsContext)endpoint.get(MetricsContext.class.getName());
- if (ti == null) {
- StringBuilder buffer = getBaseServiceName(message);
- final String baseName = buffer.toString();
- ti = new CodahaleMetricsContext(baseName, registry);
-
-
- endpoint.put(MetricsContext.class.getName(), ti);
- endpoint.addCleanupHook(new Closeable() {
- public void close() throws IOException {
- try {
- MetricsContext mct = (MetricsContext)endpoint.remove(MetricsContext.class.getName());
- if (mct instanceof Closeable) {
- ((Closeable)mct).close();
- }
- for (BindingOperationInfo boi : endpoint.getBinding().getBindingInfo().getOperations()) {
- MetricsContext ti = (MetricsContext)boi.removeProperty(MetricsContext.class.getName());
- if (ti instanceof Closeable) {
- ((Closeable)ti).close();
- }
- }
- } catch (Throwable t) {
- t.printStackTrace();
- }
- }
- });
- }
- return ti;
- }
- protected String escapePatternChars(String value) {
- // This can be replaced if really needed with pattern-based matching
- if (value.lastIndexOf(QUESTION_MARK) != -1) {
- value = value.replace(QUESTION_MARK, ESCAPED_QUESTION_MARK);
- }
- return value;
- }
-
- public void stopTimers(Message m) {
- MessageMetrics ctx = m.getExchange().get(MessageMetrics.class);
- if (ctx != null) {
- ctx.stop(m);
- }
- }
-
-
- class ResponseTimeMessageInInterceptor extends AbstractPhaseInterceptor<Message> {
- public ResponseTimeMessageInInterceptor() {
- super(Phase.RECEIVE);
- addBefore(AttachmentInInterceptor.class.getName());
- }
- public void handleMessage(Message message) throws Fault {
- if (isRequestor(message)) {
- //
- } else {
- MessageMetrics ctx = message.getExchange().get(MessageMetrics.class);
- if (ctx == null) {
- ctx = new MessageMetrics();
- MetricsContext ti = getMetricsContextForEndpoint(message);
- ctx.addContext(ti);
- message.getExchange().put(MessageMetrics.class, ctx);
- }
- InputStream in = message.getContent(InputStream.class);
- if (in != null) {
- CountingInputStream newIn = new CountingInputStream(in);
- message.setContent(InputStream.class, newIn);
- message.getExchange().put(CountingInputStream.class, newIn);
- }
- ctx.start();
- }
- }
- public void handleFault(Message message) {
- if (message.getExchange().isOneWay()) {
- stopTimers(message);
- }
- }
- };
-
- class CountingOutInterceptor extends AbstractPhaseInterceptor<Message> {
- public CountingOutInterceptor() {
- super(Phase.PRE_STREAM);
- addBefore(AttachmentOutInterceptor.class.getName());
- }
- public void handleMessage(Message message) throws Fault {
- if (isRequestor(message)) {
- //
- } else {
- OutputStream out = message.getContent(OutputStream.class);
- if (out != null) {
- CountingOutputStream newOut = new CountingOutputStream(out);
- message.setContent(OutputStream.class, newOut);
- message.getExchange().put(CountingOutputStream.class, newOut);
- }
-
- }
- }
- };
-
- class ResponseTimeMessageOutInterceptor extends AbstractPhaseInterceptor<Message> {
- public ResponseTimeMessageOutInterceptor() {
- super(Phase.PREPARE_SEND_ENDING);
- addBefore(MessageSenderInterceptor.MessageSenderEndingInterceptor.class.getName());
- }
- public void handleMessage(Message message) throws Fault {
- if (isRequestor(message)) {
- //
- } else {
- stopTimers(message);
- }
- }
- };
- class ResponseTimeMessageInPreInvokeInterceptor extends AbstractPhaseInterceptor<Message> {
- public ResponseTimeMessageInPreInvokeInterceptor() {
- super(Phase.PRE_INVOKE);
- }
-
- public void handleMessage(Message message) throws Fault {
- Exchange ex = message.getExchange();
- if (ex.getBindingOperationInfo() != null) {
- //we now know the operation, start metrics for it
- MessageMetrics ctx = message.getExchange().get(MessageMetrics.class);
- if (ctx != null) {
- MetricsContext ti = getMetricsContextForOperation(message, ex.getBindingOperationInfo());
- ctx.addContext(ti);
- }
- }
- }
- }
- class ResponseTimeMessageInOneWayInterceptor extends AbstractPhaseInterceptor<Message> {
- public ResponseTimeMessageInOneWayInterceptor() {
- super(Phase.INVOKE);
- addAfter(ServiceInvokerInterceptor.class.getName());
- }
-
- public void handleMessage(Message message) throws Fault {
- Exchange ex = message.getExchange();
- if (ex.isOneWay() && !isRequestor(message)) {
- stopTimers(message);
- }
- }
- }
-}