This is an automated email from the ASF dual-hosted git repository.
enorman pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git
The following commit(s) were added to refs/heads/master by this push:
new 8427688 SLING-12918 Update to Parent 62 and apply spotless formatting
8427688 is described below
commit 8427688051ef2f644225f6603790bcf970dba9da
Author: Eric Norman <[email protected]>
AuthorDate: Thu Aug 28 10:18:57 2025 -0700
SLING-12918 Update to Parent 62 and apply spotless formatting
---
.sling-module.json | 2 +-
pom.xml | 457 +++++++++++----------
.../org/apache/sling/commons/metrics/Counter.java | 4 +-
.../org/apache/sling/commons/metrics/Counting.java | 2 -
.../org/apache/sling/commons/metrics/Gauge.java | 14 +-
.../apache/sling/commons/metrics/Histogram.java | 2 -
.../org/apache/sling/commons/metrics/Meter.java | 4 +-
.../org/apache/sling/commons/metrics/Metric.java | 2 -
.../sling/commons/metrics/MetricsService.java | 9 +-
.../commons/metrics/MetricsServiceFactory.java | 26 +-
.../apache/sling/commons/metrics/NoopMetric.java | 39 +-
.../org/apache/sling/commons/metrics/Timer.java | 4 +-
.../metrics/internal/BundleMetricsMapper.java | 18 +-
.../commons/metrics/internal/CounterImpl.java | 4 +-
.../sling/commons/metrics/internal/GaugeImpl.java | 5 +-
.../commons/metrics/internal/GaugeManager.java | 22 +-
.../commons/metrics/internal/HistogramImpl.java | 4 +-
.../internal/InternalMetricsServiceFactory.java | 6 +-
.../commons/metrics/internal/JSONReporter.java | 45 +-
.../metrics/internal/JmxExporterFactory.java | 120 +++---
.../sling/commons/metrics/internal/JmxUtil.java | 30 +-
.../commons/metrics/internal/LogReporter.java | 56 +--
.../sling/commons/metrics/internal/MeterImpl.java | 5 +-
.../metrics/internal/MetricWebConsolePlugin.java | 74 ++--
.../metrics/internal/MetricsServiceImpl.java | 33 +-
.../sling/commons/metrics/internal/TimerImpl.java | 2 -
.../apache/sling/commons/metrics/package-info.java | 3 +-
.../metrics/internal/BundleMetricsMapperTest.java | 10 +-
.../InternalMetricsServiceFactoryTest.java | 23 +-
.../commons/metrics/internal/JSONReporterTest.java | 24 +-
.../metrics/internal/JmxExporterFactoryTest.java | 181 ++++----
.../internal/JmxNotificationListenerTest.java | 7 +-
.../commons/metrics/internal/JmxUtilTest.java | 10 +-
.../commons/metrics/internal/LogReporterTest.java | 44 +-
.../metrics/internal/MetricServiceTest.java | 55 ++-
.../internal/MetricWebConsolePluginTest.java | 57 ++-
.../metrics/internal/MetricWrapperTest.java | 4 +-
.../metrics/test/MetricsServiceFactoryIT.java | 23 +-
38 files changed, 686 insertions(+), 744 deletions(-)
diff --git a/.sling-module.json b/.sling-module.json
index 9097f10..d4268ec 100644
--- a/.sling-module.json
+++ b/.sling-module.json
@@ -2,7 +2,7 @@
"jenkins": {
"jdks": [
17,
- 11
+ 21
]
}
}
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index fe199d5..c109d9b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -19,239 +19,244 @@
-->
<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>
+ <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.sling</groupId>
- <artifactId>sling-bundle-parent</artifactId>
- <version>48</version>
- <relativePath />
- </parent>
+ <parent>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>sling-bundle-parent</artifactId>
+ <version>62</version>
+ <relativePath />
+ </parent>
- <artifactId>org.apache.sling.commons.metrics</artifactId>
- <version>1.2.15-SNAPSHOT</version>
+ <artifactId>org.apache.sling.commons.metrics</artifactId>
+ <version>1.2.15-SNAPSHOT</version>
- <name>Apache Sling Commons Metrics</name>
- <description>
- Integrates Metric library with Sling. Refer to
+ <name>Apache Sling Commons Metrics</name>
+ <description>Integrates Metric library with Sling. Refer to
https://sling.apache.org/documentation/bundles/metrics.html
- for details
- </description>
+ for details</description>
- <properties>
- <org.ops4j.pax.exam.version>4.13.4</org.ops4j.pax.exam.version>
- <project.build.outputTimestamp>1728906048</project.build.outputTimestamp>
- </properties>
+ <scm>
+
<connection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git</connection>
+
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git</developerConnection>
+ <tag>HEAD</tag>
+
<url>https://github.com/apache/sling-org-apache-sling-commons-metrics/tree/${project.scm.tag}</url>
+ </scm>
- <scm>
-
<connection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git</connection>
-
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git</developerConnection>
-
<url>https://github.com/apache/sling-org-apache-sling-commons-metrics.git</url>
- <tag>HEAD</tag>
- </scm>
+ <properties>
+ <sling.java.version>17</sling.java.version>
+ <org.ops4j.pax.exam.version>4.14.0</org.ops4j.pax.exam.version>
+
<project.build.outputTimestamp>1728906048</project.build.outputTimestamp>
+ </properties>
- <build>
- <plugins>
- <plugin>
- <groupId>biz.aQute.bnd</groupId>
- <artifactId>bnd-maven-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>biz.aQute.bnd</groupId>
- <artifactId>bnd-baseline-maven-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-failsafe-plugin</artifactId>
- <executions>
- <execution>
- <goals>
- <goal>integration-test</goal>
- <goal>verify</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <redirectTestOutputToFile>true</redirectTestOutputToFile>
- <systemProperties>
- <property>
- <name>bundle.filename</name>
- <value>${basedir}/target/${project.build.finalName}.jar</value>
- </property>
- </systemProperties>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.servicemix.tooling</groupId>
- <artifactId>depends-maven-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
+ <dependencies>
+ <!-- javax -->
+ <dependency>
+ <groupId>javax.inject</groupId>
+ <artifactId>javax.inject</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <scope>provided</scope>
+ <optional>true</optional>
+ </dependency>
+ <!-- OSGi -->
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.framework</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.util.tracker</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.annotation.versioning</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.service.component.annotations</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.service.metatype.annotations</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <!-- Apache Commons -->
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.8.0</version>
+ <scope>provided</scope>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>3.12.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <!-- Apache Felix -->
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.framework</artifactId>
+ <version>7.0.5</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.inventory</artifactId>
+ <version>1.0.2</version>
+ <scope>provided</scope>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.utils</artifactId>
+ <version>1.9.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <!-- Apache Sling -->
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.sling-mock.junit4</artifactId>
+ <version>3.5.4</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.paxexam</artifactId>
+ <version>4.1.2</version>
+ <scope>test</scope>
+ </dependency>
+ <!-- Dropwizard Metrics -->
+ <dependency>
+ <groupId>io.dropwizard.metrics</groupId>
+ <artifactId>metrics-core</artifactId>
+ <version>3.2.3</version>
+ <scope>provided</scope>
+ </dependency>
+ <!-- logging -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <!-- testing -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit-addons</groupId>
+ <artifactId>junit-addons</artifactId>
+ <version>1.4</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-all</artifactId>
+ <version>1.3</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>5.19.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-inline</artifactId>
+ <version>5.2.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.htmlunit</groupId>
+ <artifactId>htmlunit</artifactId>
+ <version>2.63.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam</artifactId>
+ <version>${org.ops4j.pax.exam.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-cm</artifactId>
+ <version>${org.ops4j.pax.exam.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-container-forked</artifactId>
+ <version>${org.ops4j.pax.exam.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-junit4</artifactId>
+ <version>${org.ops4j.pax.exam.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-link-mvn</artifactId>
+ <version>${org.ops4j.pax.exam.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
- <dependencies>
- <!-- javax -->
- <dependency>
- <groupId>javax.inject</groupId>
- <artifactId>javax.inject</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>javax.servlet-api</artifactId>
- <optional>true</optional>
- </dependency>
- <!-- OSGi -->
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>osgi.core</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.annotation.versioning</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.service.component.annotations</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.service.metatype.annotations</artifactId>
- <scope>provided</scope>
- </dependency>
- <!-- Apache Commons -->
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- <version>2.8.0</version>
- <scope>provided</scope>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
- <version>3.12.0</version>
- <scope>provided</scope>
- </dependency>
- <!-- Apache Felix -->
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.framework</artifactId>
- <version>6.0.3</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.inventory</artifactId>
- <version>1.0.2</version>
- <scope>provided</scope>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.utils</artifactId>
- <version>1.9.0</version>
- <scope>provided</scope>
- </dependency>
- <!-- Apache Sling -->
- <dependency>
- <groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.testing.sling-mock.junit4</artifactId>
- <version>2.6.0</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.testing.paxexam</artifactId>
- <version>3.1.0</version>
- <scope>test</scope>
- </dependency>
- <!-- Dropwizard Metrics -->
- <dependency>
- <groupId>io.dropwizard.metrics</groupId>
- <artifactId>metrics-core</artifactId>
- <version>3.2.3</version>
- <scope>provided</scope>
- </dependency>
- <!-- logging -->
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-simple</artifactId>
- <scope>test</scope>
- </dependency>
- <!-- testing -->
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>junit-addons</groupId>
- <artifactId>junit-addons</artifactId>
- <version>1.4</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-all</artifactId>
- <version>1.3</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <version>4.6.1</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-inline</artifactId>
- <version>4.6.1</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>net.sourceforge.htmlunit</groupId>
- <artifactId>htmlunit</artifactId>
- <version>2.63.0</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.ops4j.pax.exam</groupId>
- <artifactId>pax-exam</artifactId>
- <version>${org.ops4j.pax.exam.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.ops4j.pax.exam</groupId>
- <artifactId>pax-exam-cm</artifactId>
- <version>${org.ops4j.pax.exam.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.ops4j.pax.exam</groupId>
- <artifactId>pax-exam-container-forked</artifactId>
- <version>${org.ops4j.pax.exam.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.ops4j.pax.exam</groupId>
- <artifactId>pax-exam-junit4</artifactId>
- <version>${org.ops4j.pax.exam.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.ops4j.pax.exam</groupId>
- <artifactId>pax-exam-link-mvn</artifactId>
- <version>${org.ops4j.pax.exam.version}</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>biz.aQute.bnd</groupId>
+ <artifactId>bnd-maven-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>biz.aQute.bnd</groupId>
+ <artifactId>bnd-baseline-maven-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <configuration>
+ <redirectTestOutputToFile>true</redirectTestOutputToFile>
+ <systemProperties>
+ <property>
+ <name>bundle.filename</name>
+
<value>${basedir}/target/${project.build.finalName}.jar</value>
+ </property>
+ </systemProperties>
+ </configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.servicemix.tooling</groupId>
+ <artifactId>depends-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/src/main/java/org/apache/sling/commons/metrics/Counter.java
b/src/main/java/org/apache/sling/commons/metrics/Counter.java
index 64730dd..e9268b8 100644
--- a/src/main/java/org/apache/sling/commons/metrics/Counter.java
+++ b/src/main/java/org/apache/sling/commons/metrics/Counter.java
@@ -16,17 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.sling.commons.metrics;
-
import org.osgi.annotation.versioning.ProviderType;
/**
* An incrementing and decrementing counter metric.
*/
@ProviderType
-public interface Counter extends Counting, Metric{
+public interface Counter extends Counting, Metric {
/**
* Increment the counter by one.
*/
diff --git a/src/main/java/org/apache/sling/commons/metrics/Counting.java
b/src/main/java/org/apache/sling/commons/metrics/Counting.java
index f974ea6..15c8926 100644
--- a/src/main/java/org/apache/sling/commons/metrics/Counting.java
+++ b/src/main/java/org/apache/sling/commons/metrics/Counting.java
@@ -16,10 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.sling.commons.metrics;
-
import org.osgi.annotation.versioning.ProviderType;
@ProviderType
diff --git a/src/main/java/org/apache/sling/commons/metrics/Gauge.java
b/src/main/java/org/apache/sling/commons/metrics/Gauge.java
index 6a32dd5..da0f438 100644
--- a/src/main/java/org/apache/sling/commons/metrics/Gauge.java
+++ b/src/main/java/org/apache/sling/commons/metrics/Gauge.java
@@ -16,22 +16,20 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.sling.commons.metrics;
-
import org.osgi.annotation.versioning.ConsumerType;
/**
- * A gauge metric is an instantaneous reading of a particular value.
- *
+ * A gauge metric is an instantaneous reading of a particular value.
+ *
* Since package version 1.3.0 a gauge can directly created via the
MetricsService {@link MetricsService#gauge(String,Supplier)},
* which should be used for the majority of cases.
- *
+ *
* <p> Nevertheless it's still possible to register a gauge instance with OSGi
ServiceRegistry with {@code Gauge#NAME} set
* to Gauge name. Then the Gauge instance would be registered with
MetricService via the whiteboard
* pattern.
- *
+ *
* To instrument a queue's depth,
* for example:<br>
* <pre><code>
@@ -43,7 +41,7 @@ import org.osgi.annotation.versioning.ConsumerType;
* };
* </code></pre>
*
-
+ *
*
* @param <T> the type of the metric's value
*/
@@ -59,4 +57,4 @@ public interface Gauge<T> {
* @return the metric's current value
*/
T getValue();
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/apache/sling/commons/metrics/Histogram.java
b/src/main/java/org/apache/sling/commons/metrics/Histogram.java
index d78f3a8..9426554 100644
--- a/src/main/java/org/apache/sling/commons/metrics/Histogram.java
+++ b/src/main/java/org/apache/sling/commons/metrics/Histogram.java
@@ -16,10 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.sling.commons.metrics;
-
import org.osgi.annotation.versioning.ProviderType;
/**
diff --git a/src/main/java/org/apache/sling/commons/metrics/Meter.java
b/src/main/java/org/apache/sling/commons/metrics/Meter.java
index 6674fbf..8a10ddb 100644
--- a/src/main/java/org/apache/sling/commons/metrics/Meter.java
+++ b/src/main/java/org/apache/sling/commons/metrics/Meter.java
@@ -16,17 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.sling.commons.metrics;
-
import org.osgi.annotation.versioning.ProviderType;
/**
* A meter metric which measures mean throughput
*/
@ProviderType
-public interface Meter extends Counting, Metric{
+public interface Meter extends Counting, Metric {
/**
* Mark the occurrence of an event.
*/
diff --git a/src/main/java/org/apache/sling/commons/metrics/Metric.java
b/src/main/java/org/apache/sling/commons/metrics/Metric.java
index bf07b69..7895d8b 100644
--- a/src/main/java/org/apache/sling/commons/metrics/Metric.java
+++ b/src/main/java/org/apache/sling/commons/metrics/Metric.java
@@ -16,10 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.sling.commons.metrics;
-
import org.osgi.annotation.versioning.ProviderType;
@ProviderType
diff --git a/src/main/java/org/apache/sling/commons/metrics/MetricsService.java
b/src/main/java/org/apache/sling/commons/metrics/MetricsService.java
index 60f69e3..53dab26 100644
--- a/src/main/java/org/apache/sling/commons/metrics/MetricsService.java
+++ b/src/main/java/org/apache/sling/commons/metrics/MetricsService.java
@@ -16,10 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.sling.commons.metrics;
-
import java.util.function.Supplier;
import org.osgi.annotation.versioning.ProviderType;
@@ -126,14 +124,11 @@ public interface MetricsService {
* or null if this metric cannot be adapted to the specified type.
*/
<A> A adaptTo(Class<A> type);
-
-
+
/**
* Unregister a metric by its name
* @param name the name of the metric
* @return true if the metric was correctly unregistered, false otherwise.
*/
- public boolean unregister (String name);
-
-
+ public boolean unregister(String name);
}
diff --git
a/src/main/java/org/apache/sling/commons/metrics/MetricsServiceFactory.java
b/src/main/java/org/apache/sling/commons/metrics/MetricsServiceFactory.java
index cd1c23f..d7dbad1 100644
--- a/src/main/java/org/apache/sling/commons/metrics/MetricsServiceFactory.java
+++ b/src/main/java/org/apache/sling/commons/metrics/MetricsServiceFactory.java
@@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.sling.commons.metrics;
import org.osgi.framework.Bundle;
@@ -30,33 +29,32 @@ import org.osgi.framework.ServiceReference;
* as it is to get a Logger, for example.
*/
public class MetricsServiceFactory {
-
- /** Provide a MetricsService mapped to the Bundle that loaded class c
+
+ /** Provide a MetricsService mapped to the Bundle that loaded class c
* @param c a Class loaded by an OSGi bundle
* @return a MetricsService
*/
public static MetricsService getMetricsService(Class<?> c) {
- if(c == null) {
+ if (c == null) {
throw new IllegalArgumentException("Class parameter is required");
}
-
+
final Bundle b = FrameworkUtil.getBundle(c);
- if(b == null) {
- throw new IllegalArgumentException("No BundleContext, Class was
not loaded from a Bundle?: "
+ if (b == null) {
+ throw new IllegalArgumentException("No BundleContext, Class was
not loaded from a Bundle?: "
+ c.getClass().getName());
}
-
+
final BundleContext ctx = b.getBundleContext();
// In theory we should unget this reference, but the OSGi framework
// ungets all references held by a bundle when it stops and we cannot
// do much better than that anyway.
final ServiceReference ref =
ctx.getServiceReference(MetricsService.class.getName());
- if(ref == null) {
- throw new IllegalStateException("MetricsService not found for
Bundle "
- + b.getSymbolicName());
+ if (ref == null) {
+ throw new IllegalStateException("MetricsService not found for
Bundle " + b.getSymbolicName());
}
-
- return (MetricsService)ctx.getService(ref);
+
+ return (MetricsService) ctx.getService(ref);
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/apache/sling/commons/metrics/NoopMetric.java
b/src/main/java/org/apache/sling/commons/metrics/NoopMetric.java
index e2aaac4..34b3570 100644
--- a/src/main/java/org/apache/sling/commons/metrics/NoopMetric.java
+++ b/src/main/java/org/apache/sling/commons/metrics/NoopMetric.java
@@ -16,12 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.sling.commons.metrics;
import java.util.concurrent.TimeUnit;
-enum NoopMetric implements Counter, Histogram, Timer, Meter{
+enum NoopMetric implements Counter, Histogram, Timer, Meter {
INSTANCE;
@Override
@@ -30,39 +29,25 @@ enum NoopMetric implements Counter, Histogram, Timer, Meter{
}
@Override
- public void increment() {
-
- }
+ public void increment() {}
@Override
- public void decrement() {
-
- }
+ public void decrement() {}
@Override
- public void increment(long n) {
-
- }
+ public void increment(long n) {}
@Override
- public void decrement(long n) {
-
- }
+ public void decrement(long n) {}
@Override
- public void mark() {
-
- }
+ public void mark() {}
@Override
- public void mark(long n) {
-
- }
+ public void mark(long n) {}
@Override
- public void update(long duration, TimeUnit unit) {
-
- }
+ public void update(long duration, TimeUnit unit) {}
@Override
public Context time() {
@@ -70,9 +55,7 @@ enum NoopMetric implements Counter, Histogram, Timer, Meter{
}
@Override
- public void update(long value) {
-
- }
+ public void update(long value) {}
@Override
public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
@@ -88,8 +71,6 @@ enum NoopMetric implements Counter, Histogram, Timer, Meter{
}
@Override
- public void close() {
-
- }
+ public void close() {}
}
}
diff --git a/src/main/java/org/apache/sling/commons/metrics/Timer.java
b/src/main/java/org/apache/sling/commons/metrics/Timer.java
index f5d79cb..47d7a10 100644
--- a/src/main/java/org/apache/sling/commons/metrics/Timer.java
+++ b/src/main/java/org/apache/sling/commons/metrics/Timer.java
@@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.sling.commons.metrics;
import java.io.Closeable;
@@ -24,12 +23,11 @@ import java.util.concurrent.TimeUnit;
import org.osgi.annotation.versioning.ProviderType;
-
/**
* A timer metric which aggregates timing durations and provides duration
statistics.
*/
@ProviderType
-public interface Timer extends Counting, Metric{
+public interface Timer extends Counting, Metric {
/**
* A timing context.
*
diff --git
a/src/main/java/org/apache/sling/commons/metrics/internal/BundleMetricsMapper.java
b/src/main/java/org/apache/sling/commons/metrics/internal/BundleMetricsMapper.java
index c10d344..a125487 100644
---
a/src/main/java/org/apache/sling/commons/metrics/internal/BundleMetricsMapper.java
+++
b/src/main/java/org/apache/sling/commons/metrics/internal/BundleMetricsMapper.java
@@ -16,24 +16,23 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.sling.commons.metrics.internal;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
import java.util.Hashtable;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.ObjectNameFactory;
import org.osgi.framework.Bundle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-class BundleMetricsMapper implements ObjectNameFactory{
+class BundleMetricsMapper implements ObjectNameFactory {
public static final String HEADER_DOMAIN_NAME = "Sling-Metrics-Domain";
public static final String DEFAULT_DOMAIN_NAME = "org.apache.sling";
static final String JMX_TYPE_METRICS = "Metrics";
@@ -52,7 +51,7 @@ class BundleMetricsMapper implements ObjectNameFactory{
}
public boolean unregister(Set<String> registeredNames) {
- for (String name : registeredNames){
+ for (String name : registeredNames) {
registry.remove(name);
metricToBundleMapping.remove(name);
metricsService.remove(name);
@@ -85,17 +84,16 @@ class BundleMetricsMapper implements ObjectNameFactory{
}
private String getDomainName(Bundle bundle) {
- if (bundle == null){
+ if (bundle == null) {
return null;
}
String domainNameHeader = bundle.getHeaders().get(HEADER_DOMAIN_NAME);
- if (domainNameHeader != null){
+ if (domainNameHeader != null) {
return domainNameHeader;
}
- //Fallback to symbolic name
+ // Fallback to symbolic name
return bundle.getSymbolicName();
}
-
}
diff --git
a/src/main/java/org/apache/sling/commons/metrics/internal/CounterImpl.java
b/src/main/java/org/apache/sling/commons/metrics/internal/CounterImpl.java
index bda240e..11c72d3 100644
--- a/src/main/java/org/apache/sling/commons/metrics/internal/CounterImpl.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/CounterImpl.java
@@ -16,10 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.sling.commons.metrics.internal;
-
import org.apache.sling.commons.metrics.Counter;
final class CounterImpl implements Counter {
@@ -57,7 +55,7 @@ final class CounterImpl implements Counter {
@SuppressWarnings("unchecked")
@Override
public <A> A adaptTo(Class<A> type) {
- if (type == com.codahale.metrics.Counter.class){
+ if (type == com.codahale.metrics.Counter.class) {
return (A) counter;
}
return null;
diff --git
a/src/main/java/org/apache/sling/commons/metrics/internal/GaugeImpl.java
b/src/main/java/org/apache/sling/commons/metrics/internal/GaugeImpl.java
index 7ad069e..38a118a 100644
--- a/src/main/java/org/apache/sling/commons/metrics/internal/GaugeImpl.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/GaugeImpl.java
@@ -16,10 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.sling.commons.metrics.internal;
-
import org.apache.sling.commons.metrics.Gauge;
import org.apache.sling.commons.metrics.Metric;
@@ -33,7 +31,7 @@ public class GaugeImpl<T> implements Gauge<T>, Metric {
@Override
public <A> A adaptTo(Class<A> type) {
- if (type == com.codahale.metrics.Gauge.class){
+ if (type == com.codahale.metrics.Gauge.class) {
return (A) gauge;
}
return null;
@@ -43,5 +41,4 @@ public class GaugeImpl<T> implements Gauge<T>, Metric {
public T getValue() {
return this.gauge.getValue();
}
-
}
diff --git
a/src/main/java/org/apache/sling/commons/metrics/internal/GaugeManager.java
b/src/main/java/org/apache/sling/commons/metrics/internal/GaugeManager.java
index bc48066..4c56539 100644
--- a/src/main/java/org/apache/sling/commons/metrics/internal/GaugeManager.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/GaugeManager.java
@@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.sling.commons.metrics.internal;
import java.io.Closeable;
@@ -46,14 +45,17 @@ class GaugeManager implements
ServiceTrackerCustomizer<Gauge, GaugeManager.Gauge
tracker.open();
}
- //~-------------------------------------< ServiceTrackerCustomizer >
+ // ~-------------------------------------< ServiceTrackerCustomizer >
@Override
public GaugeImpl addingService(ServiceReference<Gauge> reference) {
String name = (String) reference.getProperty(Gauge.NAME);
- if (name == null){
- log.warn("A {} service is registered without [{}] property. This
Gauge would not be " +
- "registered with MetricsRegistry", reference, Gauge.NAME);
+ if (name == null) {
+ log.warn(
+ "A {} service is registered without [{}] property. This
Gauge would not be "
+ + "registered with MetricsRegistry",
+ reference,
+ Gauge.NAME);
return null;
}
@@ -66,11 +68,11 @@ class GaugeManager implements
ServiceTrackerCustomizer<Gauge, GaugeManager.Gauge
@Override
public void modifiedService(ServiceReference<Gauge> reference, GaugeImpl
service) {
String name = (String) reference.getProperty(Gauge.NAME);
- if (name == null){
+ if (name == null) {
return;
}
- if (!name.equals(service.name)){
+ if (!name.equals(service.name)) {
unregister(service);
service.name = name;
register(reference, service);
@@ -82,14 +84,14 @@ class GaugeManager implements
ServiceTrackerCustomizer<Gauge, GaugeManager.Gauge
unregister(service);
}
- //~------------------------------------< Closeable >
+ // ~------------------------------------< Closeable >
@Override
public void close() {
tracker.close();
}
- //~-------------------------------------< Internal >
+ // ~-------------------------------------< Internal >
private void unregister(GaugeImpl service) {
mapper.unregister(Collections.singleton(service.name));
@@ -100,7 +102,7 @@ class GaugeManager implements
ServiceTrackerCustomizer<Gauge, GaugeManager.Gauge
registry.register(gaugeImpl.name, gaugeImpl);
}
- //~--------------------------------------< GaugeImpl >
+ // ~--------------------------------------< GaugeImpl >
public static class GaugeImpl implements com.codahale.metrics.Gauge {
String name;
diff --git
a/src/main/java/org/apache/sling/commons/metrics/internal/HistogramImpl.java
b/src/main/java/org/apache/sling/commons/metrics/internal/HistogramImpl.java
index 3507e3a..8594f8f 100644
--- a/src/main/java/org/apache/sling/commons/metrics/internal/HistogramImpl.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/HistogramImpl.java
@@ -16,10 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.sling.commons.metrics.internal;
-
import org.apache.sling.commons.metrics.Histogram;
final class HistogramImpl implements Histogram {
@@ -42,7 +40,7 @@ final class HistogramImpl implements Histogram {
@SuppressWarnings("unchecked")
@Override
public <A> A adaptTo(Class<A> type) {
- if (type == com.codahale.metrics.Histogram.class){
+ if (type == com.codahale.metrics.Histogram.class) {
return (A) histogram;
}
return null;
diff --git
a/src/main/java/org/apache/sling/commons/metrics/internal/InternalMetricsServiceFactory.java
b/src/main/java/org/apache/sling/commons/metrics/internal/InternalMetricsServiceFactory.java
index 7056931..d659a19 100644
---
a/src/main/java/org/apache/sling/commons/metrics/internal/InternalMetricsServiceFactory.java
+++
b/src/main/java/org/apache/sling/commons/metrics/internal/InternalMetricsServiceFactory.java
@@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.sling.commons.metrics.internal;
import java.util.Collections;
@@ -50,7 +49,7 @@ class InternalMetricsServiceFactory implements
ServiceFactory<MetricsService> {
@Override
public void ungetService(Bundle bundle,
ServiceRegistration<MetricsService> registration, MetricsService service) {
- if (service instanceof BundleMetricService){
+ if (service instanceof BundleMetricService) {
((BundleMetricService) service).unregister();
}
}
@@ -92,7 +91,7 @@ class InternalMetricsServiceFactory implements
ServiceFactory<MetricsService> {
return delegate.adaptTo(type);
}
- void unregister(){
+ void unregister() {
metricsMapper.unregister(registeredNames);
}
@@ -111,6 +110,5 @@ class InternalMetricsServiceFactory implements
ServiceFactory<MetricsService> {
public boolean unregister(String name) {
return metricsMapper.unregister(Collections.singleton(name));
}
-
}
}
diff --git
a/src/main/java/org/apache/sling/commons/metrics/internal/JSONReporter.java
b/src/main/java/org/apache/sling/commons/metrics/internal/JSONReporter.java
index 1b24b3e..cabeb88 100644
--- a/src/main/java/org/apache/sling/commons/metrics/internal/JSONReporter.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/JSONReporter.java
@@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.sling.commons.metrics.internal;
import java.io.Closeable;
@@ -28,8 +27,6 @@ import java.util.Map;
import java.util.SortedMap;
import java.util.concurrent.TimeUnit;
-import org.apache.felix.utils.json.JSONWriter;
-
import com.codahale.metrics.ConsoleReporter;
import com.codahale.metrics.Counter;
import com.codahale.metrics.Gauge;
@@ -40,6 +37,7 @@ import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Reporter;
import com.codahale.metrics.Snapshot;
import com.codahale.metrics.Timer;
+import org.apache.felix.utils.json.JSONWriter;
class JSONReporter implements Reporter, Closeable {
@@ -112,11 +110,7 @@ class JSONReporter implements Reporter, Closeable {
* @return a {@link ConsoleReporter}
*/
public JSONReporter build() {
- return new JSONReporter(registry,
- output,
- rateUnit,
- durationUnit,
- filter);
+ return new JSONReporter(registry, output, rateUnit, durationUnit,
filter);
}
}
@@ -129,8 +123,12 @@ class JSONReporter implements Reporter, Closeable {
private final JSONWriter json;
private final PrintWriter pw;
- private JSONReporter(MetricRegistry registry,
- PrintStream output, TimeUnit rateUnit, TimeUnit
durationUnit, MetricFilter filter){
+ private JSONReporter(
+ MetricRegistry registry,
+ PrintStream output,
+ TimeUnit rateUnit,
+ TimeUnit durationUnit,
+ MetricFilter filter) {
this.registry = registry;
this.filter = filter;
this.pw = new PrintWriter(output);
@@ -143,7 +141,8 @@ class JSONReporter implements Reporter, Closeable {
public void report() {
try {
- report(registry.getGauges(filter),
+ report(
+ registry.getGauges(filter),
registry.getCounters(filter),
registry.getHistograms(filter),
registry.getMeters(filter),
@@ -154,13 +153,17 @@ class JSONReporter implements Reporter, Closeable {
}
@Override
- public void close(){
+ public void close() {
pw.flush();
}
- private void report(SortedMap<String, Gauge> gauges, SortedMap<String,
Counter> counters,
- SortedMap<String, Histogram> histograms,
SortedMap<String, Meter> meters,
- SortedMap<String, Timer> timers) throws IOException {
+ private void report(
+ SortedMap<String, Gauge> gauges,
+ SortedMap<String, Counter> counters,
+ SortedMap<String, Histogram> histograms,
+ SortedMap<String, Meter> meters,
+ SortedMap<String, Timer> timers)
+ throws IOException {
json.object();
if (!gauges.isEmpty()) {
json.key("gauges").object();
@@ -203,7 +206,6 @@ class JSONReporter implements Reporter, Closeable {
}
json.endObject();
-
}
private void printTimer(Map.Entry<String, Timer> e) throws IOException {
@@ -278,12 +280,12 @@ class JSONReporter implements Reporter, Closeable {
json.endObject();
}
- private static Object jsonSafeValue(Object v){
- //Json does not allow NaN or infinite doubles. So take care of that
- if (v instanceof Number){
- if (v instanceof Double){
+ private static Object jsonSafeValue(Object v) {
+ // Json does not allow NaN or infinite doubles. So take care of that
+ if (v instanceof Number) {
+ if (v instanceof Double) {
Double d = (Double) v;
- if (d.isInfinite() || d.isNaN()){
+ if (d.isInfinite() || d.isNaN()) {
return d.toString();
}
}
@@ -295,5 +297,4 @@ class JSONReporter implements Reporter, Closeable {
final String s = unit.toString().toLowerCase(Locale.US);
return s.substring(0, s.length() - 1);
}
-
}
diff --git
a/src/main/java/org/apache/sling/commons/metrics/internal/JmxExporterFactory.java
b/src/main/java/org/apache/sling/commons/metrics/internal/JmxExporterFactory.java
index db06254..2bb6ab5 100644
---
a/src/main/java/org/apache/sling/commons/metrics/internal/JmxExporterFactory.java
+++
b/src/main/java/org/apache/sling/commons/metrics/internal/JmxExporterFactory.java
@@ -18,17 +18,6 @@
*/
package org.apache.sling.commons.metrics.internal;
-import java.lang.management.ManagementFactory;
-import javax.management.MBeanServerNotification;
-import javax.management.NotificationListener;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Set;
-import java.util.function.Supplier;
-
import javax.management.AttributeNotFoundException;
import javax.management.InstanceNotFoundException;
import javax.management.IntrospectionException;
@@ -37,11 +26,22 @@ import javax.management.MBeanException;
import javax.management.MBeanInfo;
import javax.management.MBeanServer;
import javax.management.MBeanServerDelegate;
+import javax.management.MBeanServerNotification;
import javax.management.MalformedObjectNameException;
import javax.management.Notification;
+import javax.management.NotificationListener;
import javax.management.ObjectName;
import javax.management.ReflectionException;
+import java.lang.management.ManagementFactory;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Set;
+import java.util.function.Supplier;
+
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.commons.metrics.MetricsService;
import org.osgi.service.component.annotations.Activate;
@@ -54,36 +54,35 @@ import
org.osgi.service.metatype.annotations.ObjectClassDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
/**
* This ServiceFactory allows to export JMX object names as metrics (gauge).
*
*/
-
@Component()
-@Designate(ocd=JmxExporterFactory.Config.class, factory=true)
+@Designate(ocd = JmxExporterFactory.Config.class, factory = true)
public class JmxExporterFactory {
-
- @ObjectClassDefinition(name="JMX to Metrics Exporter")
+ @ObjectClassDefinition(name = "JMX to Metrics Exporter")
public @interface Config {
-
- @AttributeDefinition(name="objectnames", description="export all
attribute of the MBeans matching these objectnames as Sling Metrics"
- + "(see
https://docs.oracle.com/en/java/javase/11/docs/api/java.management/javax/management/ObjectName.html")
+
+ @AttributeDefinition(
+ name = "objectnames",
+ description =
+ "export all attribute of the MBeans matching these
objectnames as Sling Metrics"
+ + "(see
https://docs.oracle.com/en/java/javase/11/docs/api/java.management/javax/management/ObjectName.html")
String[] objectnames();
-
+
@AttributeDefinition
- String webconsole_configurationFactory_nameHint() default "Pattern:
{objectnames}"; //NOSONAR
+ String webconsole_configurationFactory_nameHint() default "Pattern:
{objectnames}"; // NOSONAR
}
String[] patterns;
-
-
+
private static final Logger LOG =
LoggerFactory.getLogger(JmxExporterFactory.class);
-
+
@Reference
MetricsService metrics;
-
+
MBeanServer server;
/**
* This listener is registered to the MBeanServerDelegate to listen for
MBean registrations.
@@ -100,7 +99,7 @@ public class JmxExporterFactory {
if
(MBeanServerNotification.REGISTRATION_NOTIFICATION.equals(notification.getType()))
{
ObjectName objectname = null;
try {
- if(notification instanceof MBeanServerNotification) {
+ if (notification instanceof MBeanServerNotification) {
MBeanServerNotification mbeanNotification =
(MBeanServerNotification) notification;
objectname = mbeanNotification.getMBeanName();
LOG.debug("JMX Notification : match {} with pattern =
{}", objectname, Arrays.asList(patterns));
@@ -112,7 +111,9 @@ public class JmxExporterFactory {
}
}
} else {
- LOG.debug("JMX Notification : Cannot handle
notification, because it's not a MBeanServerNotification ({})", notification);
+ LOG.debug(
+ "JMX Notification : Cannot handle
notification, because it's not a MBeanServerNotification ({})",
+ notification);
}
} catch (InstanceNotFoundException | ReflectionException |
IntrospectionException e) {
LOG.error("JMX Notification : Cannot register metrics for
objectname = {}", objectname, e);
@@ -134,13 +135,12 @@ public class JmxExporterFactory {
registerMetrics(patterns);
}
-
/**
* Register all applicable metrics for an objectname pattern
* @param pattern describes a objectname pattern
*/
private void registerMetrics(String[] patterns) {
-
+
for (String patternString : patterns) {
try {
ObjectName pattern = new ObjectName(patternString);
@@ -158,73 +158,75 @@ public class JmxExporterFactory {
});
}
} catch (MalformedObjectNameException e) {
- LOG.error("cannot create an objectname from pattern
{}",patternString,e);
+ LOG.error("cannot create an objectname from pattern {}",
patternString, e);
}
}
-
}
-
-
- protected void registerMBeanProperties(ObjectName objectname) throws
InstanceNotFoundException, ReflectionException, IntrospectionException {
+
+ protected void registerMBeanProperties(ObjectName objectname)
+ throws InstanceNotFoundException, ReflectionException,
IntrospectionException {
MBeanInfo info = server.getMBeanInfo(objectname);
MBeanAttributeInfo[] attributes = info.getAttributes();
for (MBeanAttributeInfo attr : attributes) {
- LOG.debug("Checking mbean = {}, name = {}, type={}",objectname,
attr.getName(), attr.getType());
-
+ LOG.debug("Checking mbean = {}, name = {}, type={}", objectname,
attr.getName(), attr.getType());
+
Supplier<?> supplier = null;
if ("int".equals(attr.getType())) {
- supplier = getSupplier(objectname, attr.getName(),0);
+ supplier = getSupplier(objectname, attr.getName(), 0);
} else if ("long".equals(attr.getType())) {
- supplier = getSupplier(objectname, attr.getName(),0L);
+ supplier = getSupplier(objectname, attr.getName(), 0L);
} else if ("java.lang.String".equals(attr.getType())) {
- supplier = getSupplier(objectname,attr.getName(),"");
+ supplier = getSupplier(objectname, attr.getName(), "");
} else if ("double".equals(attr.getType())) {
- supplier = getSupplier(objectname,attr.getName(),
Double.valueOf(0.0));
+ supplier = getSupplier(objectname, attr.getName(),
Double.valueOf(0.0));
} else if ("boolean".equals(attr.getType())) {
- supplier = getSupplier(objectname,attr.getName(),
Boolean.FALSE);
+ supplier = getSupplier(objectname, attr.getName(),
Boolean.FALSE);
}
-
+
if (supplier != null) {
String metricName = toMetricName(objectname, attr.getName());
- LOG.info("Registering metric {} from MBean (objectname=[{}],
name={}, type={})",
- metricName, objectname, attr.getName(),
attr.getType());
+ LOG.info(
+ "Registering metric {} from MBean (objectname=[{}],
name={}, type={})",
+ metricName,
+ objectname,
+ attr.getName(),
+ attr.getType());
metrics.gauge(metricName, supplier);
}
}
}
-
-
- private <T> Supplier<T> getSupplier ( ObjectName name, String
attributeName, T defaultValue ) {
-
+
+ private <T> Supplier<T> getSupplier(ObjectName name, String attributeName,
T defaultValue) {
+
return () -> {
try {
return (T) server.getAttribute(name, attributeName);
- } catch (InstanceNotFoundException | AttributeNotFoundException |
ReflectionException
- | MBeanException e) {
- LOG.warn("error when retrieving value for MBean
(objectname=[{}], attribute={})",name, attributeName,e);
+ } catch (InstanceNotFoundException | AttributeNotFoundException |
ReflectionException | MBeanException e) {
+ LOG.warn(
+ "error when retrieving value for MBean
(objectname=[{}], attribute={})",
+ name,
+ attributeName,
+ e);
return defaultValue;
}
-
};
}
-
-
+
protected String toMetricName(ObjectName objectName, String attributeName)
{
String name = "sling"; // default domain
if (!StringUtils.isBlank(objectName.getDomain())) {
name = objectName.getDomain();
}
- Hashtable<String,String> allkeys = objectName.getKeyPropertyList();
+ Hashtable<String, String> allkeys = objectName.getKeyPropertyList();
List<String> keyValues = new ArrayList<>(allkeys.values());
Collections.sort(keyValues);
-
+
StringBuilder builder = new StringBuilder(name);
- for (String s: keyValues) {
- builder.append( "." + s);
+ for (String s : keyValues) {
+ builder.append("." + s);
}
builder.append("." + attributeName);
return builder.toString();
}
-
}
diff --git
a/src/main/java/org/apache/sling/commons/metrics/internal/JmxUtil.java
b/src/main/java/org/apache/sling/commons/metrics/internal/JmxUtil.java
index 9938631..bd2b3e1 100644
--- a/src/main/java/org/apache/sling/commons/metrics/internal/JmxUtil.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/JmxUtil.java
@@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.sling.commons.metrics.internal;
import javax.management.MalformedObjectNameException;
@@ -42,44 +41,43 @@ final class JmxUtil {
String result;
String quotedValue = ObjectName.quote(unquotedValue);
- //Check if some chars are escaped or not. In that case
- //length of quoted string (excluding quotes) would differ
+ // Check if some chars are escaped or not. In that case
+ // length of quoted string (excluding quotes) would differ
if (quotedValue.substring(1, quotedValue.length() -
1).equals(unquotedValue)) {
ObjectName on = null;
try {
- //Quoting logic in ObjectName does not escape ',', '='
- //etc. So try now by constructing ObjectName. If that
- //passes then value can be used as safely
+ // Quoting logic in ObjectName does not escape ',', '='
+ // etc. So try now by constructing ObjectName. If that
+ // passes then value can be used as safely
- //Also we cannot just rely on ObjectName as it treats
- //*, ? as pattern chars and which should ideally be escaped
+ // Also we cannot just rely on ObjectName as it treats
+ // *, ? as pattern chars and which should ideally be escaped
on = new ObjectName("dummy", "dummy", unquotedValue);
} catch (MalformedObjectNameException ignore) {
- //ignore
+ // ignore
}
- if (on != null){
+ if (on != null) {
result = unquotedValue;
} else {
result = quotedValue;
}
} else {
- //Some escaping done. So do quote
+ // Some escaping done. So do quote
result = quotedValue;
}
return result;
}
-
- public static String safeDomainName(String name){
- if (name == null){
+ public static String safeDomainName(String name) {
+ if (name == null) {
return null;
}
name = name.trim();
- //Taken from javax.management.ObjectName.isDomain()
- //Following are special chars in domain name
+ // Taken from javax.management.ObjectName.isDomain()
+ // Following are special chars in domain name
name = name.replace(':', '_');
name = name.replace('*', '_');
name = name.replace('?', '_');
diff --git
a/src/main/java/org/apache/sling/commons/metrics/internal/LogReporter.java
b/src/main/java/org/apache/sling/commons/metrics/internal/LogReporter.java
index f1f872f..5bfa3b2 100644
--- a/src/main/java/org/apache/sling/commons/metrics/internal/LogReporter.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/LogReporter.java
@@ -1,21 +1,26 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.sling.commons.metrics.internal;
+import java.util.concurrent.TimeUnit;
+import java.util.regex.Pattern;
+
import com.codahale.metrics.Metric;
import com.codahale.metrics.MetricFilter;
import com.codahale.metrics.MetricRegistry;
@@ -33,10 +38,9 @@ import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;
import org.slf4j.LoggerFactory;
-import java.util.concurrent.TimeUnit;
-import java.util.regex.Pattern;
-
-@Component(service = {}, configurationPolicy = ConfigurationPolicy.REQUIRE)
+@Component(
+ service = {},
+ configurationPolicy = ConfigurationPolicy.REQUIRE)
@Designate(ocd = LogReporter.Config.class, factory = true)
public class LogReporter implements ServiceTrackerCustomizer<MetricRegistry,
Slf4jReporter> {
@@ -57,18 +61,19 @@ public class LogReporter implements
ServiceTrackerCustomizer<MetricRegistry, Slf
tracker.close();
}
- //~---------------------------------------------< ServiceTracker >
+ // ~---------------------------------------------< ServiceTracker >
@Override
public Slf4jReporter addingService(ServiceReference<MetricRegistry>
serviceReference) {
MetricRegistry registry = context.getService(serviceReference);
String metricRegistryName = (String)
serviceReference.getProperty(MetricWebConsolePlugin.METRIC_REGISTRY_NAME);
- if (config.registryName() == null || config.registryName().length() == 0
+ if (config.registryName() == null
+ || config.registryName().length() == 0
|| config.registryName().equals(metricRegistryName)) {
- Slf4jReporter.Builder builder =
Slf4jReporter.forRegistry(registry).
- outputTo(LoggerFactory.getLogger(config.loggerName())).
- withLoggingLevel(config.level());
+ Slf4jReporter.Builder builder = Slf4jReporter.forRegistry(registry)
+ .outputTo(LoggerFactory.getLogger(config.loggerName()))
+ .withLoggingLevel(config.level());
if (config.prefix() != null && config.prefix().length() > 0) {
builder.filter(new PrefixFilter(config.prefix()));
@@ -137,14 +142,17 @@ public class LogReporter implements
ServiceTrackerCustomizer<MetricRegistry, Slf
@AttributeDefinition(description = "The logger name")
String loggerName() default "metrics";
- @AttributeDefinition(description = "If specified, only metrics whose
name starts with this value are logged. If both prefix and pattern are set,
prefix is used.")
+ @AttributeDefinition(
+ description =
+ "If specified, only metrics whose name starts with
this value are logged. If both prefix and pattern are set, prefix is used.")
String prefix() default "";
- @AttributeDefinition(description = "If specified, only metrics whose
name matches this regular expression will be logged. If both prefix and pattern
are set, prefix is used.")
+ @AttributeDefinition(
+ description =
+ "If specified, only metrics whose name matches this
regular expression will be logged. If both prefix and pattern are set, prefix
is used.")
String pattern() default "";
@AttributeDefinition(description = "Restrict the metrics logged to a
specifically named registry.")
String registryName() default "";
}
-
}
diff --git
a/src/main/java/org/apache/sling/commons/metrics/internal/MeterImpl.java
b/src/main/java/org/apache/sling/commons/metrics/internal/MeterImpl.java
index 83d4ff7..1e4c71e 100644
--- a/src/main/java/org/apache/sling/commons/metrics/internal/MeterImpl.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/MeterImpl.java
@@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.sling.commons.metrics.internal;
import org.apache.sling.commons.metrics.Meter;
@@ -46,8 +45,8 @@ final class MeterImpl implements Meter {
@SuppressWarnings("unchecked")
@Override
public <A> A adaptTo(Class<A> type) {
- if (type == com.codahale.metrics.Meter.class){
- return (A)meter;
+ if (type == com.codahale.metrics.Meter.class) {
+ return (A) meter;
}
return null;
}
diff --git
a/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java
b/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java
index ea9bfec..5e4eab2 100644
---
a/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java
+++
b/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java
@@ -16,9 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.sling.commons.metrics.internal;
+import javax.servlet.Servlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
@@ -30,11 +34,6 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
-import javax.servlet.Servlet;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
import com.codahale.metrics.ConsoleReporter;
import com.codahale.metrics.Counter;
import com.codahale.metrics.Gauge;
@@ -57,29 +56,29 @@ import org.osgi.util.tracker.ServiceTrackerCustomizer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@Component(service = {InventoryPrinter.class, Servlet.class},
+@Component(
+ service = {InventoryPrinter.class, Servlet.class},
property = {
- "felix.webconsole.label=slingmetrics",
- "felix.webconsole.title=Metrics",
- "felix.webconsole.category=Sling",
- InventoryPrinter.FORMAT + "=TEXT",
- InventoryPrinter.FORMAT + "=JSON",
- InventoryPrinter.TITLE + "=Sling Metrics",
- InventoryPrinter.NAME + "=slingmetrics"
- }
-)
-public class MetricWebConsolePlugin extends HttpServlet implements
- InventoryPrinter, ServiceTrackerCustomizer<MetricRegistry,
MetricRegistry>{
+ "felix.webconsole.label=slingmetrics",
+ "felix.webconsole.title=Metrics",
+ "felix.webconsole.category=Sling",
+ InventoryPrinter.FORMAT + "=TEXT",
+ InventoryPrinter.FORMAT + "=JSON",
+ InventoryPrinter.TITLE + "=Sling Metrics",
+ InventoryPrinter.NAME + "=slingmetrics"
+ })
+public class MetricWebConsolePlugin extends HttpServlet
+ implements InventoryPrinter, ServiceTrackerCustomizer<MetricRegistry,
MetricRegistry> {
/**
* Service property name which stores the MetricRegistry name as a given
OSGi
* ServiceRegistry might have multiple instances of MetricRegistry
*/
public static final String METRIC_REGISTRY_NAME = "name";
+
private final Logger log = LoggerFactory.getLogger(getClass());
private BundleContext context;
private ServiceTracker<MetricRegistry, MetricRegistry> tracker;
- private ConcurrentMap<ServiceReference, MetricRegistry> registries
- = new ConcurrentHashMap<>();
+ private ConcurrentMap<ServiceReference, MetricRegistry> registries = new
ConcurrentHashMap<>();
private TimeUnit rateUnit = TimeUnit.SECONDS;
private TimeUnit durationUnit = TimeUnit.MILLISECONDS;
@@ -88,7 +87,7 @@ public class MetricWebConsolePlugin extends HttpServlet
implements
private MetricTimeUnits timeUnit;
@Activate
- private void activate(BundleContext context){
+ private void activate(BundleContext context) {
this.context = context;
this.timeUnit = new MetricTimeUnits(rateUnit, durationUnit,
specificRateUnits, specificDurationUnits);
tracker = new ServiceTracker<>(context, MetricRegistry.class, this);
@@ -96,11 +95,11 @@ public class MetricWebConsolePlugin extends HttpServlet
implements
}
@Deactivate
- private void deactivate(BundleContext context){
+ private void deactivate(BundleContext context) {
tracker.close();
}
- //~--------------------------------------------< InventoryPrinter >
+ // ~--------------------------------------------< InventoryPrinter >
@Override
public void print(PrintWriter printWriter, Format format, boolean isZip) {
@@ -121,8 +120,7 @@ public class MetricWebConsolePlugin extends HttpServlet
implements
}
}
-
- //~---------------------------------------------< ServiceTracker >
+ // ~---------------------------------------------< ServiceTracker >
@Override
public MetricRegistry addingService(ServiceReference<MetricRegistry>
serviceReference) {
@@ -141,7 +139,7 @@ public class MetricWebConsolePlugin extends HttpServlet
implements
registries.remove(serviceReference);
}
- //~----------------------------------------------< Servlet >
+ // ~----------------------------------------------< Servlet >
@Override
protected void doGet(final HttpServletRequest req, final
HttpServletResponse resp) throws IOException {
@@ -340,7 +338,6 @@ public class MetricWebConsolePlugin extends HttpServlet
implements
pw.printf("<td>%f</td>", s.get99thPercentile());
pw.printf("<td>%f</td>", s.get999thPercentile());
-
pw.println("</tr>");
rowClass = "odd".equals(rowClass) ? "even" : "odd";
}
@@ -421,21 +418,21 @@ public class MetricWebConsolePlugin extends HttpServlet
implements
pw.println("</div>");
}
-
- //~----------------------------------------------< internal >
+ // ~----------------------------------------------< internal >
MetricRegistry getConsolidatedRegistry() {
MetricRegistry registry = new MetricRegistry();
- for (Map.Entry<ServiceReference, MetricRegistry> registryEntry :
registries.entrySet()){
+ for (Map.Entry<ServiceReference, MetricRegistry> registryEntry :
registries.entrySet()) {
String metricRegistryName = (String)
registryEntry.getKey().getProperty(METRIC_REGISTRY_NAME);
- for (Map.Entry<String, Metric> metricEntry :
registryEntry.getValue().getMetrics().entrySet()){
+ for (Map.Entry<String, Metric> metricEntry :
+ registryEntry.getValue().getMetrics().entrySet()) {
String metricName = metricEntry.getKey();
- try{
- if (metricRegistryName != null){
+ try {
+ if (metricRegistryName != null) {
metricName = metricRegistryName + ":" + metricName;
}
registry.register(metricName, metricEntry.getValue());
- }catch (IllegalArgumentException ex){
+ } catch (IllegalArgumentException ex) {
log.warn("Duplicate Metric name found {}", metricName, ex);
}
}
@@ -454,10 +451,11 @@ public class MetricWebConsolePlugin extends HttpServlet
implements
private final Map<String, TimeUnit> rateOverrides;
private final Map<String, TimeUnit> durationOverrides;
- MetricTimeUnits(TimeUnit defaultRate,
- TimeUnit defaultDuration,
- Map<String, TimeUnit> rateOverrides,
- Map<String, TimeUnit> durationOverrides) {
+ MetricTimeUnits(
+ TimeUnit defaultRate,
+ TimeUnit defaultDuration,
+ Map<String, TimeUnit> rateOverrides,
+ Map<String, TimeUnit> durationOverrides) {
this.defaultRate = defaultRate;
this.defaultDuration = defaultDuration;
this.rateOverrides = rateOverrides;
diff --git
a/src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceImpl.java
b/src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceImpl.java
index 4387394..6d40d1a 100644
---
a/src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceImpl.java
+++
b/src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceImpl.java
@@ -16,9 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.sling.commons.metrics.internal;
+import javax.management.MBeanServer;
+
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.util.ArrayList;
@@ -30,19 +31,16 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.function.Supplier;
-import javax.management.MBeanServer;
-
import com.codahale.metrics.JmxReporter;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.MetricRegistry.MetricSupplier;
-
-import org.apache.sling.commons.metrics.Meter;
-import org.apache.sling.commons.metrics.MetricsService;
-import org.apache.sling.commons.metrics.Timer;
import org.apache.sling.commons.metrics.Counter;
import org.apache.sling.commons.metrics.Gauge;
import org.apache.sling.commons.metrics.Histogram;
+import org.apache.sling.commons.metrics.Meter;
import org.apache.sling.commons.metrics.Metric;
+import org.apache.sling.commons.metrics.MetricsService;
+import org.apache.sling.commons.metrics.Timer;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceRegistration;
@@ -52,7 +50,9 @@ import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
-@Component(service = {}, immediate = true)
+@Component(
+ service = {},
+ immediate = true)
public class MetricsServiceImpl implements MetricsService {
private final List<ServiceRegistration> regs = new ArrayList<>();
private final ConcurrentMap<String, Metric> metrics = new
ConcurrentHashMap<>();
@@ -79,8 +79,8 @@ public class MetricsServiceImpl implements MetricsService {
final Dictionary<String, String> svcProps = new Hashtable<>();
svcProps.put(Constants.SERVICE_DESCRIPTION, "Apache Sling Metrics
Service");
svcProps.put(Constants.SERVICE_VENDOR, "The Apache Software
Foundation");
- regs.add(context.registerService(MetricsService.class.getName(),
- new InternalMetricsServiceFactory(this, metricsMapper),
svcProps));
+ regs.add(context.registerService(
+ MetricsService.class.getName(), new
InternalMetricsServiceFactory(this, metricsMapper), svcProps));
final Dictionary<String, String> regProps = new Hashtable<>();
regProps.put(Constants.SERVICE_DESCRIPTION, "Apache Sling Metrics
Registry");
@@ -126,23 +126,22 @@ public class MetricsServiceImpl implements MetricsService
{
}
public <T> Gauge<T> gauge(String name, Supplier<T> supplier) {
- return getOrAddGauge(name,supplier);
+ return getOrAddGauge(name, supplier);
}
@SuppressWarnings("unchecked")
@Override
public <A> A adaptTo(Class<A> type) {
- if (type == MetricRegistry.class){
+ if (type == MetricRegistry.class) {
return (A) registry;
}
return null;
}
-
+
@Override
- public boolean unregister (String name) {
+ public boolean unregister(String name) {
return registry.remove(name);
}
-
void remove(String name) {
metrics.remove(name);
@@ -177,7 +176,7 @@ public class MetricsServiceImpl implements MetricsService {
return (Gauge<T>) metric;
} else {
try {
- return registerGauge(name,supplier);
+ return registerGauge(name, supplier);
} catch (IllegalArgumentException e) {
final Metric added = metrics.get(name);
if (added instanceof Gauge<?>) {
@@ -266,7 +265,7 @@ public class MetricsServiceImpl implements MetricsService {
}
private void enableJMXReporter() {
- if (server == null){
+ if (server == null) {
server = ManagementFactory.getPlatformMBeanServer();
}
diff --git
a/src/main/java/org/apache/sling/commons/metrics/internal/TimerImpl.java
b/src/main/java/org/apache/sling/commons/metrics/internal/TimerImpl.java
index cf9d87f..d894592 100644
--- a/src/main/java/org/apache/sling/commons/metrics/internal/TimerImpl.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/TimerImpl.java
@@ -16,14 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.sling.commons.metrics.internal;
import java.util.concurrent.TimeUnit;
import org.apache.sling.commons.metrics.Timer;
-
final class TimerImpl implements Timer {
private final com.codahale.metrics.Timer timer;
diff --git a/src/main/java/org/apache/sling/commons/metrics/package-info.java
b/src/main/java/org/apache/sling/commons/metrics/package-info.java
index 3fa3d08..029e071 100644
--- a/src/main/java/org/apache/sling/commons/metrics/package-info.java
+++ b/src/main/java/org/apache/sling/commons/metrics/package-info.java
@@ -25,5 +25,4 @@
@Version("1.4.0")
package org.apache.sling.commons.metrics;
-
-import org.osgi.annotation.versioning.Version;
\ No newline at end of file
+import org.osgi.annotation.versioning.Version;
diff --git
a/src/test/java/org/apache/sling/commons/metrics/internal/BundleMetricsMapperTest.java
b/src/test/java/org/apache/sling/commons/metrics/internal/BundleMetricsMapperTest.java
index ba1ca9e..df17b10 100644
---
a/src/test/java/org/apache/sling/commons/metrics/internal/BundleMetricsMapperTest.java
+++
b/src/test/java/org/apache/sling/commons/metrics/internal/BundleMetricsMapperTest.java
@@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.sling.commons.metrics.internal;
import javax.management.ObjectName;
@@ -33,18 +32,19 @@ import static org.junit.Assert.*;
public class BundleMetricsMapperTest {
@Rule
public final OsgiContext context = new OsgiContext();
+
private MetricRegistry registry = new MetricRegistry();
private BundleMetricsMapper mapper = new BundleMetricsMapper(new
MetricsServiceImpl(), registry);
@Test
- public void defaultDomainName() throws Exception{
+ public void defaultDomainName() throws Exception {
ObjectName name = mapper.createName("counter", "foo", "bar");
assertEquals("foo", name.getDomain());
}
@Test
- public void mappedName_SymbolicName() throws Exception{
+ public void mappedName_SymbolicName() throws Exception {
MockBundle bundle = new MockBundle(context.bundleContext());
bundle.setSymbolicName("com.example");
@@ -55,7 +55,7 @@ public class BundleMetricsMapperTest {
}
@Test
- public void mappedName_Header() throws Exception{
+ public void mappedName_Header() throws Exception {
MockBundle bundle = new MockBundle(context.bundleContext());
bundle.setSymbolicName("com.example");
bundle.setHeaders(ImmutableMap.of(BundleMetricsMapper.HEADER_DOMAIN_NAME,
"com.test"));
@@ -65,6 +65,4 @@ public class BundleMetricsMapperTest {
ObjectName name = mapper.createName("counter", "foo", "bar");
assertEquals("com.test", name.getDomain());
}
-
-
}
diff --git
a/src/test/java/org/apache/sling/commons/metrics/internal/InternalMetricsServiceFactoryTest.java
b/src/test/java/org/apache/sling/commons/metrics/internal/InternalMetricsServiceFactoryTest.java
index 3d68fae..bebb953 100644
---
a/src/test/java/org/apache/sling/commons/metrics/internal/InternalMetricsServiceFactoryTest.java
+++
b/src/test/java/org/apache/sling/commons/metrics/internal/InternalMetricsServiceFactoryTest.java
@@ -16,26 +16,27 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.sling.commons.metrics.internal;
-import com.codahale.metrics.MetricRegistry;
import javax.management.ObjectName;
+import com.codahale.metrics.MetricRegistry;
import org.apache.sling.commons.metrics.Counter;
import org.apache.sling.commons.metrics.MetricsService;
import org.apache.sling.testing.mock.osgi.MockBundle;
import org.apache.sling.testing.mock.osgi.junit.OsgiContext;
-import static org.junit.Assert.*;
import org.junit.Rule;
import org.junit.Test;
-import static org.mockito.Mockito.mock;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceRegistration;
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.mock;
+
public class InternalMetricsServiceFactoryTest {
@Rule
public final OsgiContext context = new OsgiContext();
+
private MetricsServiceImpl serviceImpl = new MetricsServiceImpl();
private MetricRegistry registry = serviceImpl.getRegistry();
private BundleMetricsMapper mapper = new BundleMetricsMapper(serviceImpl,
registry);
@@ -43,7 +44,7 @@ public class InternalMetricsServiceFactoryTest {
private ServiceRegistration<MetricsService> reg =
mock(ServiceRegistration.class);
@Test
- public void basicWorking() throws Exception{
+ public void basicWorking() throws Exception {
MetricsService service = srvFactory.getService(cb("foo"), reg);
service.meter("m1");
service.timer("t1");
@@ -56,12 +57,12 @@ public class InternalMetricsServiceFactoryTest {
ObjectName name = mapper.createName("meter", "com.foo", "m1");
- //Domain name should be bundle symbolic name
+ // Domain name should be bundle symbolic name
assertEquals("foo", name.getDomain());
}
@Test
- public void unRegistration() throws Exception{
+ public void unRegistration() throws Exception {
Bundle foo = cb("foo");
Bundle bar = cb("bar");
MetricsService srv1 = srvFactory.getService(foo, reg);
@@ -77,22 +78,20 @@ public class InternalMetricsServiceFactoryTest {
srvFactory.ungetService(foo, reg, srv1);
- //Metrics from 'foo' bundle i.e. m1 and c1 must be removed
+ // Metrics from 'foo' bundle i.e. m1 and c1 must be removed
assertFalse(registry.getMeters().containsKey("m1"));
assertFalse(registry.getCounters().containsKey("c1"));
assertNotEquals("The MetricsService should not return stale metric
references.", c1, serviceImpl.counter("c1"));
assertTrue(registry.getCounters().containsKey("c1"));
- //Metrics from 'bar' bundle should be present
+ // Metrics from 'bar' bundle should be present
assertTrue(registry.getMeters().containsKey("m2"));
}
- private Bundle cb(String name){
+ private Bundle cb(String name) {
MockBundle bundle = new MockBundle(context.bundleContext());
bundle.setSymbolicName(name);
return bundle;
}
-
-
}
diff --git
a/src/test/java/org/apache/sling/commons/metrics/internal/JSONReporterTest.java
b/src/test/java/org/apache/sling/commons/metrics/internal/JSONReporterTest.java
index 4de6cc8..07d52e7 100644
---
a/src/test/java/org/apache/sling/commons/metrics/internal/JSONReporterTest.java
+++
b/src/test/java/org/apache/sling/commons/metrics/internal/JSONReporterTest.java
@@ -16,23 +16,21 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.sling.commons.metrics.internal;
-import static org.junit.Assert.assertTrue;
-
import java.io.IOException;
import java.io.PrintStream;
import java.io.StringWriter;
import java.util.Map;
+import com.codahale.metrics.Gauge;
+import com.codahale.metrics.JvmAttributeGaugeSet;
+import com.codahale.metrics.MetricRegistry;
import org.apache.commons.io.output.WriterOutputStream;
import org.apache.felix.utils.json.JSONParser;
import org.junit.Test;
-import com.codahale.metrics.Gauge;
-import com.codahale.metrics.JvmAttributeGaugeSet;
-import com.codahale.metrics.MetricRegistry;
+import static org.junit.Assert.assertTrue;
public class JSONReporterTest {
@@ -55,15 +53,15 @@ public class JSONReporterTest {
assertTrue(json.containsKey("histograms"));
assertTrue(json.containsKey("meters"));
- assertTrue(((Map<String,
Object>)json.get("meters")).containsKey("test1"));
- assertTrue(((Map<String,
Object>)json.get("timers")).containsKey("test2"));
- assertTrue(((Map<String,
Object>)json.get("counters")).containsKey("test4"));
- assertTrue(((Map<String,
Object>)json.get("histograms")).containsKey("test3"));
+ assertTrue(((Map<String, Object>)
json.get("meters")).containsKey("test1"));
+ assertTrue(((Map<String, Object>)
json.get("timers")).containsKey("test2"));
+ assertTrue(((Map<String, Object>)
json.get("counters")).containsKey("test4"));
+ assertTrue(((Map<String, Object>)
json.get("histograms")).containsKey("test3"));
}
@SuppressWarnings("unchecked")
@Test
- public void nan_value() throws Exception{
+ public void nan_value() throws Exception {
MetricRegistry registry = new MetricRegistry();
registry.register("test", new Gauge<Double>() {
@@ -73,9 +71,8 @@ public class JSONReporterTest {
}
});
-
Map<String, Object> json = getJSON(registry);
- assertTrue(((Map<String,
Object>)json.get("gauges")).containsKey("test"));
+ assertTrue(((Map<String, Object>)
json.get("gauges")).containsKey("test"));
}
private static Map<String, Object> getJSON(MetricRegistry registry) throws
IOException {
@@ -87,5 +84,4 @@ public class JSONReporterTest {
reporter.close();
return new JSONParser(sw.toString()).getParsed();
}
-
}
diff --git
a/src/test/java/org/apache/sling/commons/metrics/internal/JmxExporterFactoryTest.java
b/src/test/java/org/apache/sling/commons/metrics/internal/JmxExporterFactoryTest.java
index b1a5f15..48911cc 100644
---
a/src/test/java/org/apache/sling/commons/metrics/internal/JmxExporterFactoryTest.java
+++
b/src/test/java/org/apache/sling/commons/metrics/internal/JmxExporterFactoryTest.java
@@ -18,17 +18,6 @@
*/
package org.apache.sling.commons.metrics.internal;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.mockito.Mockito.never;
-
-import java.lang.management.ManagementFactory;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.function.Supplier;
-
import javax.management.InstanceAlreadyExistsException;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanRegistrationException;
@@ -40,6 +29,13 @@ import javax.management.Notification;
import javax.management.NotificationListener;
import javax.management.ObjectName;
+import java.lang.management.ManagementFactory;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Supplier;
+
import org.apache.sling.commons.metrics.MetricsService;
import org.apache.sling.testing.mock.osgi.junit.OsgiContext;
import org.junit.After;
@@ -52,75 +48,81 @@ import org.mockito.Captor;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.mockito.Mockito.never;
+
@RunWith(MockitoJUnitRunner.class)
public class JmxExporterFactoryTest {
-
+
@Rule
public OsgiContext context = new OsgiContext();
-
+
@Captor
ArgumentCaptor<Supplier<Integer>> intSupplierCaptor;
-
+
@Captor
ArgumentCaptor<Supplier<Long>> longSupplierCaptor;
-
+
@Captor
ArgumentCaptor<Supplier<String>> stringSupplierCaptor;
-
+
@Captor
ArgumentCaptor<Supplier<Double>> doubleSupplierCaptor;
-
+
@Captor
ArgumentCaptor<Supplier<Boolean>> booleanSupplierCaptor;
@Captor
ArgumentCaptor<Supplier<List<String>>> listSupplierCaptor;
-
JmxExporterFactory exporter;
-
+
private static final String OBJECT_NAME_0 =
"org.apache.sling.whiteboard.jmxexporter.impl0:type=sample1";
private static final String OBJECT_NAME_1 =
"org.apache.sling.whiteboard.jmxexporter.impl0.impl2:type=sample2";
private static final String OBJECT_NAME_2 =
"org.apache.sling.whiteboard.jmxexporter.impl1:type=sample3";
-
+
// Query which will only match OBJECT_NAME_0 and OBJECT_NAME_1
private static final String OBJECT_NAME_QUERY =
"org.apache.sling.whiteboard.jmxexporter.impl0*:type=*";
-
- private static final String EXPECTED_0_INT_NAME =
"org.apache.sling.whiteboard.jmxexporter.impl0.sample1.Int";
+
+ private static final String EXPECTED_0_INT_NAME =
"org.apache.sling.whiteboard.jmxexporter.impl0.sample1.Int";
private static final String EXPECTED_0_LONG_NAME =
"org.apache.sling.whiteboard.jmxexporter.impl0.sample1.Long";
- private static final String EXPECTED_0_BOOLEAN_NAME =
"org.apache.sling.whiteboard.jmxexporter.impl0.sample1.Boolean";
+ private static final String EXPECTED_0_BOOLEAN_NAME =
+ "org.apache.sling.whiteboard.jmxexporter.impl0.sample1.Boolean";
private static final String EXPECTED_0_STRING_NAME =
"org.apache.sling.whiteboard.jmxexporter.impl0.sample1.String";
private static final String EXPECTED_0_DOUBLE_NAME =
"org.apache.sling.whiteboard.jmxexporter.impl0.sample1.Double";
private static final String EXPECTED_0_LIST_NAME =
"org.apache.sling.whiteboard.jmxexporter.impl0.sample1.List";
-
- private static final String EXPECTED_1_INT_NAME =
"org.apache.sling.whiteboard.jmxexporter.impl0.impl2.sample2.Int";
- private static final String EXPECTED_1_LONG_NAME =
"org.apache.sling.whiteboard.jmxexporter.impl0.impl2.sample2.Long";
-
- private static final String EXPECTED_2_INT_NAME =
"org.apache.sling.whiteboard.jmxexporter.impl1.sample3.Int";
-
+
+ private static final String EXPECTED_1_INT_NAME =
"org.apache.sling.whiteboard.jmxexporter.impl0.impl2.sample2.Int";
+ private static final String EXPECTED_1_LONG_NAME =
+ "org.apache.sling.whiteboard.jmxexporter.impl0.impl2.sample2.Long";
+
+ private static final String EXPECTED_2_INT_NAME =
"org.apache.sling.whiteboard.jmxexporter.impl1.sample3.Int";
+
private static final Double STATIC_DOUBLE = 1.0;
-
+
MetricsService metrics;
NotificationListener listener;
- SimpleBean mbeans[] = { new SimpleBean(0,0L), new SimpleBean(1,1L), new
SimpleBean(2,2L)};
-
-
+ SimpleBean mbeans[] = {new SimpleBean(0, 0L), new SimpleBean(1, 1L), new
SimpleBean(2, 2L)};
+
@Before
- public void setup() throws MalformedObjectNameException,
InstanceAlreadyExistsException, MBeanRegistrationException,
NotCompliantMBeanException, InstanceNotFoundException {
+ public void setup()
+ throws MalformedObjectNameException,
InstanceAlreadyExistsException, MBeanRegistrationException,
+ NotCompliantMBeanException, InstanceNotFoundException {
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
listener = Mockito.mock(NotificationListener.class);
server.addNotificationListener(MBeanServerDelegate.DELEGATE_NAME,
listener, null, null);
- server.registerMBean(mbeans[0],new ObjectName(OBJECT_NAME_0));
- server.registerMBean(mbeans[1],new ObjectName(OBJECT_NAME_1));
- server.registerMBean(mbeans[2],new ObjectName(OBJECT_NAME_2));
-
- exporter = new JmxExporterFactory();
+ server.registerMBean(mbeans[0], new ObjectName(OBJECT_NAME_0));
+ server.registerMBean(mbeans[1], new ObjectName(OBJECT_NAME_1));
+ server.registerMBean(mbeans[2], new ObjectName(OBJECT_NAME_2));
+
+ exporter = new JmxExporterFactory();
metrics = Mockito.mock(MetricsService.class);
context.registerService(MetricsService.class, metrics);
}
-
+
@After
public void shutdown() throws MBeanRegistrationException,
InstanceNotFoundException, MalformedObjectNameException {
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
@@ -128,73 +130,70 @@ public class JmxExporterFactoryTest {
server.unregisterMBean(new ObjectName(OBJECT_NAME_1));
server.unregisterMBean(new ObjectName(OBJECT_NAME_2));
}
-
+
@Test
public void test() {
- Map<String,Object> props = new HashMap<>();
- props.put("objectnames", new String[]{OBJECT_NAME_QUERY});
-
+ Map<String, Object> props = new HashMap<>();
+ props.put("objectnames", new String[] {OBJECT_NAME_QUERY});
+
// this will query all specified mbeans and create metrics for it
context.registerInjectActivateService(exporter, props);
-
+
// Integer
Mockito.verify(metrics).gauge(Mockito.eq(EXPECTED_0_INT_NAME),
intSupplierCaptor.capture());
- assertEquals(Integer.valueOf(0),intSupplierCaptor.getValue().get());
-
+ assertEquals(Integer.valueOf(0), intSupplierCaptor.getValue().get());
+
// test that an update in the mbean reflects in the metrics
- mbeans[0].setInt(10);
+ mbeans[0].setInt(10);
Mockito.verify(metrics).gauge(Mockito.eq(EXPECTED_0_INT_NAME),
intSupplierCaptor.capture());
- assertEquals(Integer.valueOf(10),intSupplierCaptor.getValue().get());
-
+ assertEquals(Integer.valueOf(10), intSupplierCaptor.getValue().get());
+
// Long
Mockito.verify(metrics).gauge(Mockito.eq(EXPECTED_0_LONG_NAME),
longSupplierCaptor.capture());
- assertEquals(Long.valueOf(0L),longSupplierCaptor.getValue().get());
-
+ assertEquals(Long.valueOf(0L), longSupplierCaptor.getValue().get());
+
// String
Mockito.verify(metrics).gauge(Mockito.eq(EXPECTED_0_STRING_NAME),
stringSupplierCaptor.capture());
- assertEquals("sample",stringSupplierCaptor.getValue().get());
-
+ assertEquals("sample", stringSupplierCaptor.getValue().get());
+
// Boolean
Mockito.verify(metrics).gauge(Mockito.eq(EXPECTED_0_BOOLEAN_NAME),
booleanSupplierCaptor.capture());
assertFalse(booleanSupplierCaptor.getValue().get());
-
+
// Double
Mockito.verify(metrics).gauge(Mockito.eq(EXPECTED_0_DOUBLE_NAME),
doubleSupplierCaptor.capture());
- assertEquals(STATIC_DOUBLE,doubleSupplierCaptor.getValue().get());
-
+ assertEquals(STATIC_DOUBLE, doubleSupplierCaptor.getValue().get());
+
// getList()
Mockito.verify(metrics,
never()).gauge(Mockito.eq(EXPECTED_0_LIST_NAME), listSupplierCaptor.capture());
-
-
+
// MBean 1
Mockito.verify(metrics).gauge(Mockito.eq(EXPECTED_1_INT_NAME),
intSupplierCaptor.capture());
- assertEquals(Integer.valueOf(1),intSupplierCaptor.getValue().get());
-
+ assertEquals(Integer.valueOf(1), intSupplierCaptor.getValue().get());
+
Mockito.verify(metrics).gauge(Mockito.eq(EXPECTED_1_LONG_NAME),
longSupplierCaptor.capture());
- assertEquals(Long.valueOf(1L),longSupplierCaptor.getValue().get());
-
+ assertEquals(Long.valueOf(1L), longSupplierCaptor.getValue().get());
+
// verify that no metrics for MBean2 have been registered
Mockito.verify(metrics,
never()).gauge(Mockito.eq(EXPECTED_2_INT_NAME), intSupplierCaptor.capture());
Mockito.verify(listener,
Mockito.times(3)).handleNotification(Mockito.any(Notification.class),
Mockito.any());
-
-
}
-
+
@Test
public void registerNonExistingMBean() {
- Map<String,Object> props = new HashMap<>();
- props.put("objectnames", new
String[]{"org.apache.sling:type=nonexistent"}); // there is no such mbean
-
+ Map<String, Object> props = new HashMap<>();
+ props.put("objectnames", new String[]
{"org.apache.sling:type=nonexistent"}); // there is no such mbean
+
context.registerInjectActivateService(exporter, props);
Mockito.verifyNoInteractions(metrics);
}
-
+
@Test
public void registerInvalidMBean() {
- Map<String,Object> props = new HashMap<>();
- props.put("objectnames", new
String[]{"org.apache.sling%type=nonexistent"}); // this is invalid
-
+ Map<String, Object> props = new HashMap<>();
+ props.put("objectnames", new String[]
{"org.apache.sling%type=nonexistent"}); // this is invalid
+
context.registerInjectActivateService(exporter, props);
Mockito.verifyNoInteractions(metrics);
}
@@ -207,42 +206,38 @@ public class JmxExporterFactoryTest {
Mockito.verify(listener,
Mockito.times(4)).handleNotification(Mockito.any(Notification.class),
Mockito.any());
}
-
-
-
static class SimpleBean implements SimpleBeanMBean {
-
int internalInt = 0;
long internalLong = 0L;
-
+
public SimpleBean(int i, long l) {
internalInt = i;
internalLong = l;
}
-
+
@Override
public int getInt() {
return internalInt;
}
-
+
@Override
public long getLong() {
return internalLong;
}
-
+
public void setInt(int value) {
internalInt = value;
}
-
+
public String getString() {
return "sample";
}
-
+
public double getDouble() {
return STATIC_DOUBLE;
}
-
+
public boolean getBoolean() {
return false;
}
@@ -250,20 +245,20 @@ public class JmxExporterFactoryTest {
public List<String> getList() {
return Collections.emptyList();
}
-
}
-
-
- static public interface SimpleBeanMBean {
-
+
+ public static interface SimpleBeanMBean {
+
public int getInt();
+
public long getLong();
+
public String getString();
+
public double getDouble();
+
public boolean getBoolean();
-
+
public List<String> getList(); // this type is not supported!
-
}
-
-}
\ No newline at end of file
+}
diff --git
a/src/test/java/org/apache/sling/commons/metrics/internal/JmxNotificationListenerTest.java
b/src/test/java/org/apache/sling/commons/metrics/internal/JmxNotificationListenerTest.java
index 5795a0a..554a4a6 100644
---
a/src/test/java/org/apache/sling/commons/metrics/internal/JmxNotificationListenerTest.java
+++
b/src/test/java/org/apache/sling/commons/metrics/internal/JmxNotificationListenerTest.java
@@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.sling.commons.metrics.internal;
import javax.management.MBeanInfo;
@@ -30,12 +29,12 @@ import org.mockito.Mockito;
public class JmxNotificationListenerTest {
- JmxExporterFactory exporter = new JmxExporterFactory();
+ JmxExporterFactory exporter = new JmxExporterFactory();
NotificationListener listener = exporter.listener;
@Test
public void testHandleNotification() throws Exception {
- exporter.patterns = new String[] { "test:type=Test" };
+ exporter.patterns = new String[] {"test:type=Test"};
exporter.server = Mockito.mock(MBeanServer.class);
MBeanInfo m = Mockito.mock(MBeanInfo.class);
MBeanServerNotification notification =
Mockito.mock(MBeanServerNotification.class);
@@ -46,7 +45,7 @@ public class JmxNotificationListenerTest {
Mockito.when(m.getAttributes()).thenReturn(new
javax.management.MBeanAttributeInfo[0]);
listener.handleNotification(notification, null);
- //Assert that MBeanInfo attribute methid is called
+ // Assert that MBeanInfo attribute methid is called
Mockito.verify(m, Mockito.times(1)).getAttributes();
}
}
diff --git
a/src/test/java/org/apache/sling/commons/metrics/internal/JmxUtilTest.java
b/src/test/java/org/apache/sling/commons/metrics/internal/JmxUtilTest.java
index 9db25c7..cd7bbe5 100644
--- a/src/test/java/org/apache/sling/commons/metrics/internal/JmxUtilTest.java
+++ b/src/test/java/org/apache/sling/commons/metrics/internal/JmxUtilTest.java
@@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.sling.commons.metrics.internal;
import junit.framework.TestCase;
@@ -28,24 +27,23 @@ import static org.junit.Assert.assertTrue;
public class JmxUtilTest {
@Test
- public void quotation() throws Exception{
+ public void quotation() throws Exception {
assertEquals("text", JmxUtil.quoteValueIfRequired("text"));
TestCase.assertEquals("", JmxUtil.quoteValueIfRequired(""));
assertTrue(JmxUtil.quoteValueIfRequired("text*with?chars").startsWith("\""));
}
@Test
- public void quoteAndComma() throws Exception{
+ public void quoteAndComma() throws Exception {
assertTrue(JmxUtil.quoteValueIfRequired("text,withComma").startsWith("\""));
assertTrue(JmxUtil.quoteValueIfRequired("text=withEqual").startsWith("\""));
}
@Test
- public void safeDomainName() throws Exception{
+ public void safeDomainName() throws Exception {
assertEquals("com.foo", JmxUtil.safeDomainName("com.foo"));
assertEquals("com_foo", JmxUtil.safeDomainName("com:foo"));
assertEquals("com_foo", JmxUtil.safeDomainName("com?foo"));
assertEquals("com_foo", JmxUtil.safeDomainName("com*foo"));
}
-
-}
\ No newline at end of file
+}
diff --git
a/src/test/java/org/apache/sling/commons/metrics/internal/LogReporterTest.java
b/src/test/java/org/apache/sling/commons/metrics/internal/LogReporterTest.java
index 7ae9ebb..4956f1e 100644
---
a/src/test/java/org/apache/sling/commons/metrics/internal/LogReporterTest.java
+++
b/src/test/java/org/apache/sling/commons/metrics/internal/LogReporterTest.java
@@ -1,21 +1,26 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.sling.commons.metrics.internal;
+import java.lang.annotation.Annotation;
+import java.util.concurrent.TimeUnit;
+
import com.codahale.metrics.MetricFilter;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Slf4jReporter;
@@ -28,12 +33,8 @@ import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.slf4j.Logger;
-
-import static org.mockito.Mockito.*;
import static org.junit.Assert.*;
-
-import java.lang.annotation.Annotation;
-import java.util.concurrent.TimeUnit;
+import static org.mockito.Mockito.*;
@RunWith(MockitoJUnitRunner.class)
public class LogReporterTest {
@@ -48,7 +49,8 @@ public class LogReporterTest {
MetricRegistry registry = new MetricRegistry();
ServiceReference<MetricRegistry> registryServiceReference =
mock(ServiceReference.class);
when(bundleContext.getService(registryServiceReference)).thenReturn(registry);
-
when(registryServiceReference.getProperty(MetricWebConsolePlugin.METRIC_REGISTRY_NAME)).thenReturn("oak");
+
when(registryServiceReference.getProperty(MetricWebConsolePlugin.METRIC_REGISTRY_NAME))
+ .thenReturn("oak");
LogReporter.Config config = createConfigWithRegistryName("oak");
reporterService.activate(config, bundleContext);
@@ -70,7 +72,8 @@ public class LogReporterTest {
MetricRegistry registry = new MetricRegistry();
ServiceReference<MetricRegistry> registryServiceReference =
mock(ServiceReference.class);
when(bundleContext.getService(registryServiceReference)).thenReturn(registry);
-
when(registryServiceReference.getProperty(MetricWebConsolePlugin.METRIC_REGISTRY_NAME)).thenReturn("other");
+
when(registryServiceReference.getProperty(MetricWebConsolePlugin.METRIC_REGISTRY_NAME))
+ .thenReturn("other");
LogReporter.Config config = createConfigWithRegistryName("oak");
reporterService.activate(config, bundleContext);
@@ -271,7 +274,8 @@ public class LogReporterTest {
};
}
- private LogReporter.Config createConfigWithLoggerNameAndLevel(final String
loggerName, final Slf4jReporter.LoggingLevel level) {
+ private LogReporter.Config createConfigWithLoggerNameAndLevel(
+ final String loggerName, final Slf4jReporter.LoggingLevel level) {
return new LogReporter.Config() {
@Override
public long period() {
diff --git
a/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java
b/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java
index c031e1d..68ec507 100644
---
a/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java
+++
b/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java
@@ -16,17 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.sling.commons.metrics.internal;
-import java.lang.management.ManagementFactory;
-import java.util.Collections;
-import java.util.Set;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.management.Query;
import javax.management.QueryExp;
+import java.lang.management.ManagementFactory;
+import java.util.Collections;
+import java.util.Set;
+
import com.codahale.metrics.JmxReporter;
import com.codahale.metrics.MetricRegistry;
import org.apache.sling.commons.metrics.Counter;
@@ -44,10 +44,10 @@ import org.junit.Test;
import org.osgi.framework.ServiceRegistration;
import static
org.apache.sling.commons.metrics.internal.BundleMetricsMapper.JMX_TYPE_METRICS;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
-import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -55,8 +55,6 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
-
-
public class MetricServiceTest {
@Rule
public final OsgiContext context = new OsgiContext();
@@ -64,12 +62,12 @@ public class MetricServiceTest {
private MetricsServiceImpl service = new MetricsServiceImpl();
@After
- public void deactivate(){
+ public void deactivate() {
MockOsgi.deactivate(service, context.bundleContext());
}
@Test
- public void defaultSetup() throws Exception{
+ public void defaultSetup() throws Exception {
activate();
assertNotNull(context.getService(MetricRegistry.class));
@@ -84,7 +82,7 @@ public class MetricServiceTest {
}
@Test
- public void meter() throws Exception{
+ public void meter() throws Exception {
activate();
Meter meter = service.meter("test");
@@ -95,7 +93,7 @@ public class MetricServiceTest {
}
@Test
- public void counter() throws Exception{
+ public void counter() throws Exception {
activate();
Counter counter = service.counter("test");
@@ -106,7 +104,7 @@ public class MetricServiceTest {
}
@Test
- public void timer() throws Exception{
+ public void timer() throws Exception {
activate();
Timer timer = service.timer("test");
@@ -117,7 +115,7 @@ public class MetricServiceTest {
}
@Test
- public void histogram() throws Exception{
+ public void histogram() throws Exception {
activate();
Histogram histo = service.histogram("test");
@@ -128,12 +126,12 @@ public class MetricServiceTest {
}
@Test
- public void gaugeRegistration () throws Exception{
+ public void gaugeRegistration() throws Exception {
activate();
- Gauge<Long> gauge = service.gauge("gauge",() -> 42L);
+ Gauge<Long> gauge = service.gauge("gauge", () -> 42L);
assertNotNull(gauge);
assertTrue(getRegistry().getGauges().containsKey("gauge"));
- assertEquals(new Long(42L),gauge.getValue());
+ assertEquals(new Long(42L), gauge.getValue());
// Just the name matters, not the supplier
Gauge<?> gauge2 = service.gauge("gauge", () -> 43L);
@@ -141,34 +139,34 @@ public class MetricServiceTest {
}
@Test(expected = IllegalArgumentException.class)
- public void sameNameDifferentTypeMetric() throws Exception{
+ public void sameNameDifferentTypeMetric() throws Exception {
activate();
service.histogram("test");
service.timer("test");
}
@Test
- public void jmxRegistration() throws Exception{
+ public void jmxRegistration() throws Exception {
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
activate();
Meter meter = service.meter("test");
assertNotNull(meter);
QueryExp q =
Query.isInstanceOf(Query.value(JmxReporter.JmxMeterMBean.class.getName()));
- Set<ObjectName> names = server.queryNames(new
ObjectName("org.apache.sling:name=*,type="+ JMX_TYPE_METRICS), q);
+ Set<ObjectName> names =
+ server.queryNames(new
ObjectName("org.apache.sling:name=*,type=" + JMX_TYPE_METRICS), q);
assertThat(names, is(not(empty())));
MockOsgi.deactivate(service, context.bundleContext());
names = server.queryNames(new ObjectName("org.apache.sling:name=*"),
q);
assertThat(names, is(empty()));
-
}
@Test
- public void gaugeRegistrationViaWhiteboard() throws Exception{
+ public void gaugeRegistrationViaWhiteboard() throws Exception {
activate();
- ServiceRegistration<Gauge> reg =
context.bundleContext().registerService(Gauge.class, new TestGauge(42),
- MapUtil.toDictionary(Gauge.NAME, "foo"));
+ ServiceRegistration<Gauge> reg = context.bundleContext()
+ .registerService(Gauge.class, new TestGauge(42),
MapUtil.toDictionary(Gauge.NAME, "foo"));
assertTrue(getRegistry().getGauges().containsKey("foo"));
assertEquals(42, getRegistry().getGauges().get("foo").getValue());
@@ -176,20 +174,18 @@ public class MetricServiceTest {
reg.unregister();
assertFalse(getRegistry().getGauges().containsKey("foo"));
}
-
-
+
@Test
public void unregisterMetric() {
activate();
- Gauge<Long> gauge = service.gauge("gauge",() -> 42L);
+ Gauge<Long> gauge = service.gauge("gauge", () -> 42L);
assertNotNull(gauge);
assertTrue(getRegistry().getGauges().containsKey("gauge"));
service.unregister("gauge");
assertFalse(getRegistry().getGauges().containsKey("gauge"));
}
-
- private MetricRegistry getRegistry(){
+ private MetricRegistry getRegistry() {
return context.getService(MetricRegistry.class);
}
@@ -200,7 +196,7 @@ public class MetricServiceTest {
private static class TestGauge implements Gauge {
int value;
- public TestGauge(int value){
+ public TestGauge(int value) {
this.value = value;
}
@@ -209,5 +205,4 @@ public class MetricServiceTest {
return value;
}
}
-
}
diff --git
a/src/test/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePluginTest.java
b/src/test/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePluginTest.java
index 16efdb6..c56af22 100644
---
a/src/test/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePluginTest.java
+++
b/src/test/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePluginTest.java
@@ -16,21 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.sling.commons.metrics.internal;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.greaterThanOrEqualTo;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-
-
+import javax.servlet.http.HttpServletRequest;
import java.io.PrintWriter;
import java.io.StringWriter;
@@ -39,8 +27,11 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-import javax.servlet.http.HttpServletRequest;
-
+import com.codahale.metrics.JvmAttributeGaugeSet;
+import com.codahale.metrics.MetricRegistry;
+import com.gargoylesoftware.htmlunit.WebClient;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlTable;
import org.apache.felix.inventory.Format;
import org.apache.felix.utils.json.JSONParser;
import org.apache.sling.testing.mock.osgi.MockOsgi;
@@ -50,11 +41,16 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
-import com.codahale.metrics.JvmAttributeGaugeSet;
-import com.codahale.metrics.MetricRegistry;
-import com.gargoylesoftware.htmlunit.WebClient;
-import com.gargoylesoftware.htmlunit.html.HtmlPage;
-import com.gargoylesoftware.htmlunit.html.HtmlTable;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.greaterThanOrEqualTo;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
@RunWith(MockitoJUnitRunner.class)
public class MetricWebConsolePluginTest {
@@ -79,7 +75,7 @@ public class MetricWebConsolePluginTest {
MetricRegistry consolidated = plugin.getConsolidatedRegistry();
- //Check name decoration
+ // Check name decoration
assertEquals(1, consolidated.getMetrics().size());
assertTrue(consolidated.getMeters().containsKey("foo:test1"));
@@ -87,13 +83,13 @@ public class MetricWebConsolePluginTest {
reg2.meter("test2");
context.registerService(MetricRegistry.class, reg2);
- //Metric Registry without name would not be decorated
+ // Metric Registry without name would not be decorated
consolidated = plugin.getConsolidatedRegistry();
assertEquals(2, consolidated.getMetrics().size());
assertTrue(consolidated.getMeters().containsKey("test2"));
- //Duplicate metric in other registry should not fail. Warning log
- //should be generated
+ // Duplicate metric in other registry should not fail. Warning log
+ // should be generated
MetricRegistry reg3 = new MetricRegistry();
reg3.meter("test2");
context.registerService(MetricRegistry.class, reg3);
@@ -127,7 +123,7 @@ public class MetricWebConsolePluginTest {
}
@Test
- public void inventory_json() throws Exception{
+ public void inventory_json() throws Exception {
MetricRegistry reg1 = new MetricRegistry();
reg1.meter("test1").mark(5);
context.registerService(MetricRegistry.class, reg1, regProps("foo"));
@@ -157,9 +153,10 @@ public class MetricWebConsolePluginTest {
plugin.doGet(mock(HttpServletRequest.class), context.response());
- try (WebClient client = new WebClient();) {
- HtmlPage page =
client.loadHtmlCodeIntoCurrentWindow(context.response().getOutputAsString());
-
+ try (WebClient client = new WebClient(); ) {
+ HtmlPage page =
+
client.loadHtmlCodeIntoCurrentWindow(context.response().getOutputAsString());
+
assertTable("data-meters", page);
assertTable("data-counters", page);
assertTable("data-timers", page);
@@ -172,9 +169,8 @@ public class MetricWebConsolePluginTest {
HtmlTable table = page.getHtmlElementById(name);
assertNotNull(table);
- //1 for header and 1 for actual metric row
+ // 1 for header and 1 for actual metric row
assertThat(table.getRowCount(), greaterThanOrEqualTo(2));
-
}
private void activatePlugin() {
@@ -183,7 +179,6 @@ public class MetricWebConsolePluginTest {
private static class CloseRecordingWriter extends PrintWriter {
-
public CloseRecordingWriter(Writer out) {
super(out);
}
diff --git
a/src/test/java/org/apache/sling/commons/metrics/internal/MetricWrapperTest.java
b/src/test/java/org/apache/sling/commons/metrics/internal/MetricWrapperTest.java
index 3e58123..a1bd17c 100644
---
a/src/test/java/org/apache/sling/commons/metrics/internal/MetricWrapperTest.java
+++
b/src/test/java/org/apache/sling/commons/metrics/internal/MetricWrapperTest.java
@@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.sling.commons.metrics.internal;
import java.util.concurrent.TimeUnit;
@@ -108,7 +107,7 @@ public class MetricWrapperTest {
}
@Test
- public void timerContext() throws Exception{
+ public void timerContext() throws Exception {
VirtualClock clock = new VirtualClock();
Timer time = new Timer(new ExponentiallyDecayingReservoir(), clock);
@@ -124,6 +123,7 @@ public class MetricWrapperTest {
private static class VirtualClock extends com.codahale.metrics.Clock {
long tick;
+
@Override
public long getTick() {
return tick;
diff --git
a/src/test/java/org/apache/sling/commons/metrics/test/MetricsServiceFactoryIT.java
b/src/test/java/org/apache/sling/commons/metrics/test/MetricsServiceFactoryIT.java
index 0e6bd55..cc4a0f5 100644
---
a/src/test/java/org/apache/sling/commons/metrics/test/MetricsServiceFactoryIT.java
+++
b/src/test/java/org/apache/sling/commons/metrics/test/MetricsServiceFactoryIT.java
@@ -28,6 +28,7 @@ import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
import org.ops4j.pax.exam.spi.reactors.PerClass;
+
import static org.apache.sling.testing.paxexam.SlingOptions.scr;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
@@ -42,14 +43,19 @@ public class MetricsServiceFactoryIT extends TestSupport {
@Configuration
public Option[] configuration() {
return options(
- baseConfiguration(),
- scr(),
- // Commons Metrics
- testBundle("bundle.filename"),
-
mavenBundle().groupId("io.dropwizard.metrics").artifactId("metrics-core").versionAsInProject(),
-
mavenBundle().groupId("org.apache.commons").artifactId("commons-lang3").versionAsInProject(),
- junitBundles()
- );
+ baseConfiguration(),
+ scr(),
+ // Commons Metrics
+ testBundle("bundle.filename"),
+ mavenBundle()
+ .groupId("io.dropwizard.metrics")
+ .artifactId("metrics-core")
+ .versionAsInProject(),
+ mavenBundle()
+ .groupId("org.apache.commons")
+ .artifactId("commons-lang3")
+ .versionAsInProject(),
+ junitBundles());
}
@Test
@@ -75,5 +81,4 @@ public class MetricsServiceFactoryIT extends TestSupport {
final MetricsService m =
MetricsServiceFactory.getMetricsService(getClass());
assertNotNull("Expecting a MetricsService", m);
}
-
}