@@ -20,38 +20,38 @@ final class GoogleCloudStorageOperationsStats {
2020
2121 private static final int OPERATION_PURPOSE_NUM = OperationPurpose .values ().length ;
2222 private static final int OPERATION_NUM = Operation .values ().length ;
23- private final LongAdder [] [] counters ;
23+ private final OperationCounters [] counters ;
2424 private final String [] counterNames ;
2525 private final String bucketName ;
2626
2727 GoogleCloudStorageOperationsStats (String bucketName ) {
2828 this .bucketName = bucketName ;
29- counters = new LongAdder [OPERATION_PURPOSE_NUM * OPERATION_NUM ][ 2 ];
29+ counters = new OperationCounters [OPERATION_PURPOSE_NUM * OPERATION_NUM ];
3030 counterNames = new String [counters .length ];
3131 for (int counterIndex = 0 ; counterIndex < counters .length ; counterIndex ++) {
3232 counterNames [counterIndex ] = counterName (counterIndex );
33- counters [counterIndex ] = new LongAdder [] { new LongAdder (), new LongAdder () } ;
33+ counters [counterIndex ] = new OperationCounters ( new LongAdder (), new LongAdder ()) ;
3434 }
3535 }
3636
37- private LongAdder [] operationCounters (OperationPurpose purpose , Operation operation ) {
37+ private static String counterName (int counterIndex ) {
38+ int purposeOrd = counterIndex / OPERATION_NUM ;
39+ String purpose = OperationPurpose .values ()[purposeOrd ].name ();
40+ int operationOrd = counterIndex - (purposeOrd * OPERATION_NUM );
41+ String operation = Operation .values ()[operationOrd ].name ();
42+ return purpose + "_" + operation ;
43+ }
44+
45+ private OperationCounters operationCounters (OperationPurpose purpose , Operation operation ) {
3846 return counters [purpose .ordinal () * OPERATION_NUM + operation .ordinal ()];
3947 }
4048
4149 void trackOperation (OperationPurpose purpose , Operation operation ) {
42- operationCounters (purpose , operation )[ 0 ] .add (1 );
50+ operationCounters (purpose , operation ). operations .add (1 );
4351 }
4452
4553 void trackRequest (OperationPurpose purpose , Operation operation ) {
46- operationCounters (purpose , operation )[1 ].add (1 );
47- }
48-
49- private static String counterName (int counterIndex ) {
50- int purposeOrd = counterIndex / OPERATION_NUM ;
51- String purpose = OperationPurpose .values ()[purposeOrd ].name ();
52- int operationOrd = counterIndex - (purposeOrd * OPERATION_NUM );
53- String operation = Operation .values ()[operationOrd ].name ();
54- return purpose + "_" + operation ;
54+ operationCounters (purpose , operation ).requests .add (1 );
5555 }
5656
5757 String bucketName () {
@@ -62,8 +62,8 @@ Map<String, BlobStoreActionStats> toMap() {
6262 var results = new HashMap <String , BlobStoreActionStats >(counterNames .length );
6363 for (var counterIndex = 0 ; counterIndex < counterNames .length ; counterIndex ++) {
6464 var stats = counters [counterIndex ];
65- var operations = stats [ 0 ] .sum ();
66- var requests = stats [ 1 ] .sum ();
65+ var operations = stats . operations .sum ();
66+ var requests = stats . requests .sum ();
6767 results .put (counterNames [counterIndex ], new BlobStoreActionStats (operations , requests ));
6868 }
6969 return results ;
@@ -81,4 +81,6 @@ public enum Operation {
8181 this .name = name ;
8282 }
8383 }
84+
85+ record OperationCounters (LongAdder operations , LongAdder requests ) {}
8486}
0 commit comments