From ac3232c6db6fefa8239bb33956d991a9c8728cd6 Mon Sep 17 00:00:00 2001 From: Andrew Azores Date: Tue, 26 Mar 2024 12:10:14 -0400 Subject: [PATCH] fix(serialization): no-args constructors and non-final fields for Jackson (#363) --- .../io/cryostat/core/net/MBeanMetrics.java | 13 ++++--- .../io/cryostat/core/net/MemoryMetrics.java | 16 +++++---- .../cryostat/core/net/MemoryUtilization.java | 10 +++--- .../core/net/OperatingSystemMetrics.java | 28 ++++++++------- .../io/cryostat/core/net/RuntimeMetrics.java | 34 ++++++++++--------- .../io/cryostat/core/net/ThreadMetrics.java | 30 ++++++++-------- .../SerializableEventTypeInfo.java | 2 ++ .../SerializableOptionDescriptor.java | 2 ++ .../SerializableRecordingDescriptor.java | 2 ++ 9 files changed, 78 insertions(+), 59 deletions(-) diff --git a/src/main/java/io/cryostat/core/net/MBeanMetrics.java b/src/main/java/io/cryostat/core/net/MBeanMetrics.java index 114f3dcf..290087c2 100644 --- a/src/main/java/io/cryostat/core/net/MBeanMetrics.java +++ b/src/main/java/io/cryostat/core/net/MBeanMetrics.java @@ -16,11 +16,14 @@ package io.cryostat.core.net; public class MBeanMetrics { - private final RuntimeMetrics runtime; - private final MemoryMetrics memory; - private final ThreadMetrics thread; - private final OperatingSystemMetrics os; - private final String jvmId; + + private RuntimeMetrics runtime; + private MemoryMetrics memory; + private ThreadMetrics thread; + private OperatingSystemMetrics os; + private String jvmId; + + public MBeanMetrics() {} public MBeanMetrics( RuntimeMetrics runtimeDetails, diff --git a/src/main/java/io/cryostat/core/net/MemoryMetrics.java b/src/main/java/io/cryostat/core/net/MemoryMetrics.java index ce3d5f47..95a13c4d 100644 --- a/src/main/java/io/cryostat/core/net/MemoryMetrics.java +++ b/src/main/java/io/cryostat/core/net/MemoryMetrics.java @@ -21,13 +21,15 @@ import org.apache.commons.lang3.builder.ToStringBuilder; public class MemoryMetrics { - private final MemoryUtilization heapMemoryUsage; - private final MemoryUtilization nonHeapMemoryUsage; - private final long objectPendingFinalizationCount; - private final long freeHeapMemory; - private final long freeNonHeapMemory; - private final double heapMemoryUsagePercent; - private final boolean verbose; + private MemoryUtilization heapMemoryUsage; + private MemoryUtilization nonHeapMemoryUsage; + private long objectPendingFinalizationCount; + private long freeHeapMemory; + private long freeNonHeapMemory; + private double heapMemoryUsagePercent; + private boolean verbose; + + public MemoryMetrics() {} public MemoryMetrics(Map attributes) { this.heapMemoryUsage = diff --git a/src/main/java/io/cryostat/core/net/MemoryUtilization.java b/src/main/java/io/cryostat/core/net/MemoryUtilization.java index 841333d4..dc781585 100644 --- a/src/main/java/io/cryostat/core/net/MemoryUtilization.java +++ b/src/main/java/io/cryostat/core/net/MemoryUtilization.java @@ -19,10 +19,12 @@ public class MemoryUtilization { - private final long init; - private final long used; - private final long committed; - private final long max; + private long init; + private long used; + private long committed; + private long max; + + public MemoryUtilization() {} public MemoryUtilization(long init, long used, long committed, long max) { this.init = init; diff --git a/src/main/java/io/cryostat/core/net/OperatingSystemMetrics.java b/src/main/java/io/cryostat/core/net/OperatingSystemMetrics.java index 8ebfcd11..7b978210 100644 --- a/src/main/java/io/cryostat/core/net/OperatingSystemMetrics.java +++ b/src/main/java/io/cryostat/core/net/OperatingSystemMetrics.java @@ -21,19 +21,21 @@ import org.apache.commons.lang3.builder.ToStringBuilder; public class OperatingSystemMetrics { - private final String arch; - private final int availableProcessors; - private final String name; - private final double systemLoadAverage; - private final String version; - private final long committedVirtualMemorySize; - private final long freePhysicalMemorySize; - private final long freeSwapSpaceSize; - private final double processCpuLoad; - private final long processCpuTime; - private final double systemCpuLoad; - private final long totalPhysicalMemorySize; - private final long totalSwapSpaceSize; + private String arch; + private int availableProcessors; + private String name; + private double systemLoadAverage; + private String version; + private long committedVirtualMemorySize; + private long freePhysicalMemorySize; + private long freeSwapSpaceSize; + private double processCpuLoad; + private long processCpuTime; + private double systemCpuLoad; + private long totalPhysicalMemorySize; + private long totalSwapSpaceSize; + + public OperatingSystemMetrics() {} public OperatingSystemMetrics(Map attributes) { this.arch = (String) attributes.getOrDefault("Arch", StringUtils.EMPTY); diff --git a/src/main/java/io/cryostat/core/net/RuntimeMetrics.java b/src/main/java/io/cryostat/core/net/RuntimeMetrics.java index a68f1bb9..dc0c0f94 100644 --- a/src/main/java/io/cryostat/core/net/RuntimeMetrics.java +++ b/src/main/java/io/cryostat/core/net/RuntimeMetrics.java @@ -26,22 +26,24 @@ import org.apache.commons.lang3.builder.ToStringBuilder; public class RuntimeMetrics { - private final String bootClassPath; - private final String classPath; - private final String[] inputArguments; - private final String libraryPath; - private final String managementSpecVersion; - private final String name; - private final String specName; - private final String specVendor; - private final String specVersion; - private final Map systemProperties; - private final long startTime; - private final long uptime; - private final String vmName; - private final String vmVendor; - private final String vmVersion; - private final boolean bootClassPathSupported; + private String bootClassPath; + private String classPath; + private String[] inputArguments; + private String libraryPath; + private String managementSpecVersion; + private String name; + private String specName; + private String specVendor; + private String specVersion; + private Map systemProperties; + private long startTime; + private long uptime; + private String vmName; + private String vmVendor; + private String vmVersion; + private boolean bootClassPathSupported; + + public RuntimeMetrics() {} public RuntimeMetrics(Map attributes) { this.bootClassPath = (String) attributes.getOrDefault("BootClassPath", StringUtils.EMPTY); diff --git a/src/main/java/io/cryostat/core/net/ThreadMetrics.java b/src/main/java/io/cryostat/core/net/ThreadMetrics.java index daaaa364..42ff6d41 100644 --- a/src/main/java/io/cryostat/core/net/ThreadMetrics.java +++ b/src/main/java/io/cryostat/core/net/ThreadMetrics.java @@ -21,20 +21,22 @@ import org.apache.commons.lang3.builder.ToStringBuilder; public class ThreadMetrics { - private final long[] allThreadIds; - private final long currentThreadCpuTime; - private final long currentThreadUserTime; - private final int daemonThreadCount; - private final int peakThreadCount; - private final int threadCount; - private final long totalStartedThreadCount; - private final boolean currentThreadCpuTimeSupported; - private final boolean objectMonitorUsageSupported; - private final boolean synchronizerUsageSupported; - private final boolean threadContentionMonitoringEnabled; - private final boolean threadContentionMonitoringSupported; - private final boolean threadCpuTimeEnabled; - private final boolean threadCpuTimeSupported; + private long[] allThreadIds; + private long currentThreadCpuTime; + private long currentThreadUserTime; + private int daemonThreadCount; + private int peakThreadCount; + private int threadCount; + private long totalStartedThreadCount; + private boolean currentThreadCpuTimeSupported; + private boolean objectMonitorUsageSupported; + private boolean synchronizerUsageSupported; + private boolean threadContentionMonitoringEnabled; + private boolean threadContentionMonitoringSupported; + private boolean threadCpuTimeEnabled; + private boolean threadCpuTimeSupported; + + public ThreadMetrics() {} public ThreadMetrics(Map attributes) { this.allThreadIds = (long[]) attributes.getOrDefault("AllThreadIds", new long[0]); diff --git a/src/main/java/io/cryostat/core/serialization/SerializableEventTypeInfo.java b/src/main/java/io/cryostat/core/serialization/SerializableEventTypeInfo.java index d51980b2..514bd279 100644 --- a/src/main/java/io/cryostat/core/serialization/SerializableEventTypeInfo.java +++ b/src/main/java/io/cryostat/core/serialization/SerializableEventTypeInfo.java @@ -34,6 +34,8 @@ public class SerializableEventTypeInfo { private String[] category; private Map options; + public SerializableEventTypeInfo() {} + public SerializableEventTypeInfo(IEventTypeInfo orig) { this.name = orig.getName(); this.typeId = orig.getEventTypeID().getFullKey(); diff --git a/src/main/java/io/cryostat/core/serialization/SerializableOptionDescriptor.java b/src/main/java/io/cryostat/core/serialization/SerializableOptionDescriptor.java index 3e4405e4..3bd9df36 100644 --- a/src/main/java/io/cryostat/core/serialization/SerializableOptionDescriptor.java +++ b/src/main/java/io/cryostat/core/serialization/SerializableOptionDescriptor.java @@ -27,6 +27,8 @@ public class SerializableOptionDescriptor { private String description; private String defaultValue; + public SerializableOptionDescriptor() {} + public SerializableOptionDescriptor(IOptionDescriptor orig) { this.name = orig.getName(); this.description = orig.getDescription(); diff --git a/src/main/java/io/cryostat/core/serialization/SerializableRecordingDescriptor.java b/src/main/java/io/cryostat/core/serialization/SerializableRecordingDescriptor.java index 1d89819a..fa50930d 100644 --- a/src/main/java/io/cryostat/core/serialization/SerializableRecordingDescriptor.java +++ b/src/main/java/io/cryostat/core/serialization/SerializableRecordingDescriptor.java @@ -42,6 +42,8 @@ public class SerializableRecordingDescriptor { protected long maxSize; protected long maxAge; + public SerializableRecordingDescriptor() {} + public SerializableRecordingDescriptor( long id, String name,