@@ -37,27 +37,27 @@ public ClusterInfo(final CouchbaseClient client) {
37
37
38
38
@ ManagedMetric (description = "Total RAM assigned" )
39
39
public long getTotalRAMAssigned () {
40
- return ( Long ) parseStorageTotals ().get ("ram" ).get ("total" );
40
+ return convertPotentialLong ( parseStorageTotals ().get ("ram" ).get ("total" ) );
41
41
}
42
42
43
43
@ ManagedMetric (description = "Total RAM used" )
44
44
public long getTotalRAMUsed () {
45
- return ( Long ) parseStorageTotals ().get ("ram" ).get ("used" );
45
+ return convertPotentialLong ( parseStorageTotals ().get ("ram" ).get ("used" ) );
46
46
}
47
47
48
48
@ ManagedMetric (description = "Total Disk Space assigned" )
49
49
public long getTotalDiskAssigned () {
50
- return ( Long ) parseStorageTotals ().get ("hdd" ).get ("total" );
50
+ return convertPotentialLong ( parseStorageTotals ().get ("hdd" ).get ("total" ) );
51
51
}
52
52
53
53
@ ManagedMetric (description = "Total Disk Space used" )
54
54
public long getTotalDiskUsed () {
55
- return ( Long ) parseStorageTotals ().get ("hdd" ).get ("used" );
55
+ return convertPotentialLong ( parseStorageTotals ().get ("hdd" ).get ("used" ) );
56
56
}
57
57
58
58
@ ManagedMetric (description = "Total Disk Space free" )
59
59
public long getTotalDiskFree () {
60
- return ( Long ) parseStorageTotals ().get ("hdd" ).get ("free" );
60
+ return convertPotentialLong ( parseStorageTotals ().get ("hdd" ).get ("free" ) );
61
61
}
62
62
63
63
@ ManagedAttribute (description = "Cluster is Balanced" )
@@ -75,6 +75,24 @@ public int getMaxBuckets() {
75
75
return (Integer ) fetchPoolInfo ().get ("maxBucketCount" );
76
76
}
77
77
78
+ /**
79
+ * Depending on the value size, either int or long can be passed in and get
80
+ * converted to long.
81
+ *
82
+ * @param value the value to convert.
83
+ *
84
+ * @return the converted value.
85
+ */
86
+ private long convertPotentialLong (Object value ) {
87
+ if (value instanceof Integer ) {
88
+ return new Long ((Integer ) value );
89
+ } else if (value instanceof Long ) {
90
+ return (Long ) value ;
91
+ } else {
92
+ throw new IllegalStateException ("Cannot convert value to long: " + value );
93
+ }
94
+ }
95
+
78
96
private HashMap <String , Object > fetchPoolInfo () {
79
97
return getTemplate ().getForObject ("http://"
80
98
+ randomAvailableHostname () + ":8091/pools/default" , HashMap .class );
0 commit comments