From 8bef0ac26d7b9f4cca78f9fbc11f0e014fb03600 Mon Sep 17 00:00:00 2001 From: Pierre Mauduit Date: Mon, 30 Jan 2017 17:56:35 +0100 Subject: [PATCH] Java bindings - Adding Atomic* support AtomicIntegers are used to address some concurrency problems in Java, and this is advised by some metrics libraries like Netflix's servo: https://github.com/Netflix/servo/wiki#jmx Unfortunately, the GenericJMXConfValue.java class is not able to get the values from such types, hence this PR. I scanned the Java doc for the Java package: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/package-summary.html I think I have not forgotten any types. Tests: tested at runtime --- .../java/org/collectd/java/GenericJMXConfValue.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bindings/java/org/collectd/java/GenericJMXConfValue.java b/bindings/java/org/collectd/java/GenericJMXConfValue.java index 63b76282..6d3d688e 100644 --- a/bindings/java/org/collectd/java/GenericJMXConfValue.java +++ b/bindings/java/org/collectd/java/GenericJMXConfValue.java @@ -30,6 +30,8 @@ import java.util.Arrays; import java.util.List; import java.util.Collection; import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicLong; import java.util.Iterator; import java.util.ArrayList; @@ -128,6 +130,14 @@ class GenericJMXConfValue { return (BigInteger.ZERO.add ((BigInteger) obj)); } + else if (obj instanceof AtomicInteger) + { + return (new Integer(((AtomicInteger) obj).get())); + } + else if (obj instanceof AtomicLong) + { + return (new Long(((AtomicLong) obj).get())); + } return (null); } /* }}} Number genericObjectToNumber */ -- 2.30.2