Skip to content

Commit 6e2c793

Browse files
committed
continue cleanups
1 parent ed92537 commit 6e2c793

File tree

9 files changed

+25
-26
lines changed

9 files changed

+25
-26
lines changed

ibm-mq-metrics/src/main/java/io/opentelemetry/ibm/mq/WmqMonitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public void run(QueueManager queueManager) {
9696
try {
9797
ibmQueueManager = WmqUtil.connectToQueueManager(queueManager);
9898
heartBeatMetricValue = 1;
99-
agent = WmqUtil.initPCFMessageAgent(queueManager, ibmQueueManager);
99+
agent = WmqUtil.initPcfMessageAgent(queueManager, ibmQueueManager);
100100
extractAndReportMetrics(ibmQueueManager, queueManager, agent);
101101
} catch (RuntimeException e) {
102102
logger.error(

ibm-mq-metrics/src/main/java/io/opentelemetry/ibm/mq/metricscollector/InquireQCmdCollector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void accept(MetricsCollectorContext context) {
5757
request.addParameter(CMQC.MQIA_Q_TYPE, CMQC.MQQT_ALL);
5858
request.addParameter(CMQCFC.MQIACF_Q_ATTRS, ATTRIBUTES);
5959

60-
queueBuddy.processPCFRequestAndPublishQMetrics(
60+
queueBuddy.processPcfRequestAndPublishQMetrics(
6161
context, request, queueGenericName, ATTRIBUTES);
6262
}
6363
long exitTime = System.currentTimeMillis() - entryTime;

ibm-mq-metrics/src/main/java/io/opentelemetry/ibm/mq/metricscollector/InquireQStatusCmdCollector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void accept(MetricsCollectorContext context) {
6363
PCFMessage request = new PCFMessage(CMQCFC.MQCMD_INQUIRE_Q_STATUS);
6464
request.addParameter(CMQC.MQCA_Q_NAME, queueGenericName);
6565
request.addParameter(CMQCFC.MQIACF_Q_STATUS_ATTRS, ATTRIBUTES);
66-
queueBuddy.processPCFRequestAndPublishQMetrics(
66+
queueBuddy.processPcfRequestAndPublishQMetrics(
6767
context, request, queueGenericName, ATTRIBUTES);
6868
}
6969
long exitTime = System.currentTimeMillis() - entryTime;

ibm-mq-metrics/src/main/java/io/opentelemetry/ibm/mq/metricscollector/InquireQueueManagerCmdCollector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void accept(MetricsCollectorContext context) {
6767
}
6868
} catch (Exception e) {
6969
logger.error("Error collecting QueueManagerCmd metrics", e);
70-
throw new RuntimeException(e);
70+
throw new IllegalStateException(e);
7171
} finally {
7272
long exitTime = System.currentTimeMillis() - entryTime;
7373
logger.debug("Time taken to publish metrics for queuemanager is {} milliseconds", exitTime);

ibm-mq-metrics/src/main/java/io/opentelemetry/ibm/mq/metricscollector/QueueCollectionBuddy.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55

66
package io.opentelemetry.ibm.mq.metricscollector;
77

8-
import static com.ibm.mq.constants.CMQC.*;
8+
import static com.ibm.mq.constants.CMQC.MQQT_ALIAS;
9+
import static com.ibm.mq.constants.CMQC.MQQT_CLUSTER;
10+
import static com.ibm.mq.constants.CMQC.MQQT_LOCAL;
11+
import static com.ibm.mq.constants.CMQC.MQQT_MODEL;
12+
import static com.ibm.mq.constants.CMQC.MQQT_REMOTE;
913

1014
import com.ibm.mq.constants.CMQC;
1115
import com.ibm.mq.constants.CMQCFC;
@@ -35,19 +39,18 @@
3539
*/
3640
final class QueueCollectionBuddy {
3741
private static final Logger logger = LoggerFactory.getLogger(QueueCollectionBuddy.class);
38-
private Map<Integer, AllowedGauge> gauges;
42+
private final Map<Integer, AllowedGauge> gauges = new HashMap<>();
3943

4044
private final QueueCollectorSharedState sharedState;
4145
private final LongGauge onqtimeShort;
4246
private final LongGauge onqtimeLong;
4347

4448
@FunctionalInterface
4549
private interface AllowedGauge {
46-
4750
void set(MetricsCollectorContext context, Integer value, Attributes attributes);
4851
}
4952

50-
private AllowedGauge createAllowedGauge(
53+
private static AllowedGauge createAllowedGauge(
5154
LongGauge gauge, Function<MetricsConfig, Boolean> allowed) {
5255
return (context, val, attributes) -> {
5356
if (allowed.apply(context.getMetricsConfig())) {
@@ -58,7 +61,6 @@ private AllowedGauge createAllowedGauge(
5861

5962
QueueCollectionBuddy(Meter meter, QueueCollectorSharedState sharedState) {
6063
this.sharedState = sharedState;
61-
this.gauges = new HashMap<>();
6264
gauges.put(
6365
CMQC.MQIA_CURRENT_Q_DEPTH,
6466
createAllowedGauge(
@@ -118,17 +120,13 @@ private AllowedGauge createAllowedGauge(
118120

119121
this.onqtimeShort = Metrics.createMqOnqtime1(meter);
120122
this.onqtimeLong = Metrics.createMqOnqtime2(meter);
121-
122-
initialize(meter);
123123
}
124124

125-
private void initialize(Meter meter) {}
126-
127125
/**
128126
* Sends a PCFMessage request, reads the response, and generates metrics from the response. It
129127
* handles all exceptions.
130128
*/
131-
void processPCFRequestAndPublishQMetrics(
129+
void processPcfRequestAndPublishQMetrics(
132130
MetricsCollectorContext context, PCFMessage request, String queueGenericName, int[] fields) {
133131
try {
134132
doProcessPCFRequestAndPublishQMetrics(context, request, queueGenericName, fields);

ibm-mq-metrics/src/main/java/io/opentelemetry/ibm/mq/metricscollector/QueueManagerMetricsCollector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public void accept(MetricsCollectorContext context) {
102102
}
103103
} catch (Exception e) {
104104
logger.error(e.getMessage());
105-
throw new RuntimeException(e);
105+
throw new IllegalStateException(e);
106106
} finally {
107107
long exitTime = System.currentTimeMillis() - entryTime;
108108
logger.debug("Time taken to publish metrics for queuemanager is {} milliseconds", exitTime);

ibm-mq-metrics/src/main/java/io/opentelemetry/ibm/mq/metricscollector/ResetQStatsCmdCollector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void accept(MetricsCollectorContext context) {
4444
// https://www.ibm.com/support/knowledgecenter/SSFKSJ_8.0.0/com.ibm.mq.ref.adm.doc/q088310_.htm
4545
PCFMessage request = new PCFMessage(CMQCFC.MQCMD_RESET_Q_STATS);
4646
request.addParameter(CMQC.MQCA_Q_NAME, queueGenericName);
47-
queueBuddy.processPCFRequestAndPublishQMetrics(
47+
queueBuddy.processPcfRequestAndPublishQMetrics(
4848
context, request, queueGenericName, ATTRIBUTES);
4949
}
5050
long exitTime = System.currentTimeMillis() - entryTime;

ibm-mq-metrics/src/main/java/io/opentelemetry/ibm/mq/util/WmqUtil.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import io.opentelemetry.ibm.mq.WmqContext;
1313
import io.opentelemetry.ibm.mq.config.QueueManager;
1414
import java.util.Hashtable;
15+
import javax.annotation.Nullable;
1516
import org.slf4j.Logger;
1617
import org.slf4j.LoggerFactory;
1718

@@ -21,7 +22,7 @@ public class WmqUtil {
2122

2223
private WmqUtil() {}
2324

24-
public static PCFMessageAgent initPCFMessageAgent(
25+
public static PCFMessageAgent initPcfMessageAgent(
2526
QueueManager queueManager, MQQueueManager ibmQueueManager) {
2627
try {
2728
PCFMessageAgent agent;
@@ -50,7 +51,7 @@ && isNotNullOrEmpty(queueManager.getReplyQueuePrefix())) {
5051
return agent;
5152
} catch (MQDataException mqe) {
5253
logger.error(mqe.getMessage(), mqe);
53-
throw new RuntimeException(mqe);
54+
throw new IllegalStateException(mqe);
5455
}
5556
}
5657

@@ -67,11 +68,11 @@ public static MQQueueManager connectToQueueManager(QueueManager queueManager) {
6768
return ibmQueueManager;
6869
} catch (MQException mqe) {
6970
logger.error(mqe.getMessage(), mqe);
70-
throw new RuntimeException(mqe.getMessage());
71+
throw new IllegalStateException(mqe.getMessage());
7172
}
7273
}
7374

74-
private static boolean isNotNullOrEmpty(String str) {
75+
private static boolean isNotNullOrEmpty(@Nullable String str) {
7576
return str != null && !str.isEmpty();
7677
}
7778
}

ibm-mq-metrics/src/test/java/io/opentelemetry/ibm/mq/metricscollector/QueueCollectionBuddyTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void setup() throws Exception {
5353
}
5454

5555
@Test
56-
void testProcessPCFRequestAndPublishQMetricsForInquireQStatusCmd() throws Exception {
56+
void testProcessPcfRequestAndPublishQMetricsForInquireQStatusCmd() throws Exception {
5757
QueueCollectorSharedState sharedState = new QueueCollectorSharedState();
5858
sharedState.putQueueType("AMQ.5AF1608820C7D76E", "local-transmission");
5959
sharedState.putQueueType("DEV.DEAD.LETTER.QUEUE", "local-transmission");
@@ -62,7 +62,7 @@ void testProcessPCFRequestAndPublishQMetricsForInquireQStatusCmd() throws Except
6262
when(pcfMessageAgent.send(request)).thenReturn(createPCFResponseForInquireQStatusCmd());
6363

6464
classUnderTest = new QueueCollectionBuddy(meter, sharedState);
65-
classUnderTest.processPCFRequestAndPublishQMetrics(
65+
classUnderTest.processPcfRequestAndPublishQMetrics(
6666
collectorContext, request, "*", InquireQStatusCmdCollector.ATTRIBUTES);
6767

6868
Map<String, Map<String, Long>> expectedValues =
@@ -107,11 +107,11 @@ void testProcessPCFRequestAndPublishQMetricsForInquireQStatusCmd() throws Except
107107
}
108108

109109
@Test
110-
void testProcessPCFRequestAndPublishQMetricsForInquireQCmd() throws Exception {
110+
void testProcessPcfRequestAndPublishQMetricsForInquireQCmd() throws Exception {
111111
PCFMessage request = createPCFRequestForInquireQCmd();
112112
when(pcfMessageAgent.send(request)).thenReturn(createPCFResponseForInquireQCmd());
113113
classUnderTest = new QueueCollectionBuddy(meter, new QueueCollectorSharedState());
114-
classUnderTest.processPCFRequestAndPublishQMetrics(
114+
classUnderTest.processPcfRequestAndPublishQMetrics(
115115
collectorContext, request, "*", InquireQCmdCollector.ATTRIBUTES);
116116

117117
Map<String, Map<String, Long>> expectedValues =
@@ -154,15 +154,15 @@ void testProcessPCFRequestAndPublishQMetricsForInquireQCmd() throws Exception {
154154
}
155155

156156
@Test
157-
void testProcessPCFRequestAndPublishQMetricsForResetQStatsCmd() throws Exception {
157+
void testProcessPcfRequestAndPublishQMetricsForResetQStatsCmd() throws Exception {
158158
QueueCollectorSharedState sharedState = new QueueCollectorSharedState();
159159
sharedState.putQueueType("AMQ.5AF1608820C7D76E", "local-transmission");
160160
sharedState.putQueueType("DEV.DEAD.LETTER.QUEUE", "local-transmission");
161161
sharedState.putQueueType("DEV.QUEUE.1", "local-transmission");
162162
PCFMessage request = createPCFRequestForResetQStatsCmd();
163163
when(pcfMessageAgent.send(request)).thenReturn(createPCFResponseForResetQStatsCmd());
164164
classUnderTest = new QueueCollectionBuddy(meter, sharedState);
165-
classUnderTest.processPCFRequestAndPublishQMetrics(
165+
classUnderTest.processPcfRequestAndPublishQMetrics(
166166
collectorContext, request, "*", ResetQStatsCmdCollector.ATTRIBUTES);
167167

168168
for (MetricData metric : otelTesting.getMetrics()) {

0 commit comments

Comments
 (0)