Replace metrics.CloseableMetric with a more generic utils.Closeable
authorMichael Vorburger <vorburger@redhat.com>
Mon, 8 Jan 2018 22:52:52 +0000 (23:52 +0100)
committerAnil Belur <abelur@linuxfoundation.org>
Thu, 7 Oct 2021 05:19:57 +0000 (15:19 +1000)
as suggested by Tom in I76ce2e1600e8f99eb735aac4c29c423cc01c59ee review.

Change-Id: Iba7bda3f51594764c21ba8d4dd7dc69f824f5125
Signed-off-by: Michael Vorburger <vorburger@redhat.com>
metrics/api/src/main/java/org/opendaylight/infrautils/metrics/CloseableMetric.java [deleted file]
metrics/api/src/main/java/org/opendaylight/infrautils/metrics/Counter.java
metrics/api/src/main/java/org/opendaylight/infrautils/metrics/Meter.java
metrics/api/src/main/java/org/opendaylight/infrautils/metrics/Timer.java
metrics/impl/src/main/java/org/opendaylight/infrautils/metrics/internal/MetricProviderImpl.java

diff --git a/metrics/api/src/main/java/org/opendaylight/infrautils/metrics/CloseableMetric.java b/metrics/api/src/main/java/org/opendaylight/infrautils/metrics/CloseableMetric.java
deleted file mode 100644 (file)
index 7fe6d78..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (c) 2017 Red Hat, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.infrautils.metrics;
-
-/**
- * Metric which can be {@link #close()}'d.
- *
- * <p>OSGi bundles using metrics must close() them when unloading the bundle
- * (typically e.g. via Blueprint {@literal @}PreDstroy), or if they are dynamic
- * metrics (e.g. for devices) when they are no longer needed.
- *
- * <p>Metrics that are closed can no longer be used, and will throw an IllegalStateException if they are.
- *
- * @author Michael Vorburger.ch
- */
-public interface CloseableMetric {
-
-    void close();
-
-}
index 4e0326794f7339c264788c8edb6dfe6497124020..d4a1b797a27f55f4a01f3f212bc852364d90c914 100644 (file)
@@ -7,13 +7,15 @@
  */
 package org.opendaylight.infrautils.metrics;
 
+import org.opendaylight.infrautils.utils.UncheckedCloseable;
+
 /**
  * Counter metric, which is a simple incrementing and decrementing number.
  *
  * <p>Note that if you find you only use its <tt>increase()</tt> and never <tt>decrease()</tt>
  * methods, then you probably want to use {@link Meter} with <tt>mark()</tt> instead of this.
  */
-public interface Counter extends CloseableMetric {
+public interface Counter extends UncheckedCloseable {
 
     default void increment() {
         increment(1);
index d920f19371762682d3fb6e9e94cef397970e2344..37d3df353b102adb5888cb6332feebd6b18394a5 100644 (file)
@@ -7,13 +7,15 @@
  */
 package org.opendaylight.infrautils.metrics;
 
+import org.opendaylight.infrautils.utils.UncheckedCloseable;
+
 /**
  * Meter metric, which measures throughput.
  *
  * <p>Note that this with <tt>mark()</tt> measures the rate at which a set of events occur;
  * whereas {@link Counter} is for things which will <tt>increase()</tt> - and can also <tt>decrease()</tt>.
  */
-public interface Meter extends CloseableMetric {
+public interface Meter extends UncheckedCloseable {
 
     /**
      * Mark the occurrence of an event.
index ed4d0827d7c734d065e22c67aac926981f2925ec..7a74a1f91d4165b7aa43641e3d0633d731ffd8d5 100644 (file)
@@ -7,13 +7,14 @@
  */
 package org.opendaylight.infrautils.metrics;
 
+import org.opendaylight.infrautils.utils.UncheckedCloseable;
 import org.opendaylight.infrautils.utils.function.CheckedCallable;
 import org.opendaylight.infrautils.utils.function.CheckedRunnable;
 
 /**
  * A timer metric which aggregates timing durations.
  */
-public interface Timer extends CloseableMetric {
+public interface Timer extends UncheckedCloseable {
 
     /**
      * Times and records the duration of event which returns a value.
index 75a2c1861fafe8bce500ce263ae203490ef12a7a..7e1beae76af5eb057051ba3ecb83fe8fa32c3369 100644 (file)
@@ -28,8 +28,8 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.lang.management.ManagementFactory;
 import javax.annotation.PreDestroy;
 import javax.inject.Singleton;
-import org.opendaylight.infrautils.metrics.CloseableMetric;
 import org.opendaylight.infrautils.metrics.MetricProvider;
+import org.opendaylight.infrautils.utils.UncheckedCloseable;
 import org.opendaylight.infrautils.utils.function.CheckedCallable;
 import org.opendaylight.infrautils.utils.function.CheckedRunnable;
 import org.ops4j.pax.cdi.api.OsgiServiceProvider;
@@ -248,7 +248,7 @@ public class MetricProviderImpl implements MetricProvider {
         }
     }
 
-    private abstract class CloseableMetricImpl implements CloseableMetric {
+    private abstract class CloseableMetricImpl implements UncheckedCloseable {
         private volatile boolean isClosed = false;
         private final String id;