Skip to content

Commit 72050bc

Browse files
committed
more cleanups
1 parent 6e2c793 commit 72050bc

File tree

8 files changed

+37
-21
lines changed

8 files changed

+37
-21
lines changed

ibm-mq-metrics/src/main/java/io/opentelemetry/ibm/mq/config/ExcludeFilters.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
import java.util.HashSet;
1212
import java.util.Set;
1313

14-
/**
15-
* A jackson databind class used for config.
16-
*/
14+
/** A jackson databind class used for config. */
1715
public class ExcludeFilters {
1816

1917
private String type = "UNKNOWN";

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void accept(MetricsCollectorContext context) {
5151
request.addParameter(CMQC.MQCA_TOPIC_STRING, topicGenericName);
5252

5353
try {
54-
processPCFRequestAndPublishQMetrics(context, topicGenericName, request);
54+
processPcfRequestAndPublishQMetrics(context, topicGenericName, request);
5555
} catch (PCFException pcfe) {
5656
logger.error(
5757
"PCFException caught while collecting metric for Queue: {} for command MQCMD_INQUIRE_TOPIC_STATUS",
@@ -73,7 +73,7 @@ public void accept(MetricsCollectorContext context) {
7373
exitTime);
7474
}
7575

76-
private void processPCFRequestAndPublishQMetrics(
76+
private void processPcfRequestAndPublishQMetrics(
7777
MetricsCollectorContext context, String topicGenericName, PCFMessage request)
7878
throws IOException, MQDataException {
7979
logger.debug(

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55

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

8+
import com.google.errorprone.annotations.CanIgnoreReturnValue;
89
import com.ibm.mq.headers.pcf.PCFException;
910
import com.ibm.mq.headers.pcf.PCFMessage;
1011
import io.opentelemetry.ibm.mq.config.ExcludeFilters;
1112
import java.util.ArrayList;
1213
import java.util.Collection;
14+
import java.util.HashSet;
1315
import java.util.List;
16+
import java.util.Set;
1417
import org.slf4j.Logger;
1518
import org.slf4j.LoggerFactory;
1619

@@ -49,15 +52,16 @@ public List<PCFMessage> filter(List<PCFMessage> messages) throws PCFException {
4952

5053
static class MessageFilterBuilder {
5154

52-
private Collection<ExcludeFilters> filters;
53-
private String kind;
55+
private final String kind;
56+
private Set<ExcludeFilters> filters = new HashSet<>();
5457

5558
public MessageFilterBuilder(String kind) {
5659
this.kind = kind;
5760
}
5861

59-
public MessageFilterBuilder excluding(Collection<ExcludeFilters> filters) {
60-
this.filters = filters;
62+
@CanIgnoreReturnValue
63+
public MessageFilterBuilder excluding(Set<ExcludeFilters> filters) {
64+
this.filters = new HashSet<>(filters);
6165
return this;
6266
}
6367

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.List;
3131
import java.util.Map;
3232
import java.util.function.Function;
33+
import javax.annotation.Nullable;
3334
import org.slf4j.Logger;
3435
import org.slf4j.LoggerFactory;
3536

@@ -129,7 +130,7 @@ private static AllowedGauge createAllowedGauge(
129130
void processPcfRequestAndPublishQMetrics(
130131
MetricsCollectorContext context, PCFMessage request, String queueGenericName, int[] fields) {
131132
try {
132-
doProcessPCFRequestAndPublishQMetrics(context, request, queueGenericName, fields);
133+
doProcessPcfRequestAndPublishQMetrics(context, request, queueGenericName, fields);
133134
} catch (PCFException pcfe) {
134135
logger.error(
135136
"PCFException caught while collecting metric for Queue: {}", queueGenericName, pcfe);
@@ -150,7 +151,7 @@ void processPcfRequestAndPublishQMetrics(
150151
}
151152
}
152153

153-
private void doProcessPCFRequestAndPublishQMetrics(
154+
private void doProcessPcfRequestAndPublishQMetrics(
154155
MetricsCollectorContext context, PCFMessage request, String queueGenericName, int[] fields)
155156
throws IOException, MQDataException {
156157
logger.debug(
@@ -191,6 +192,7 @@ private void handleMessage(MetricsCollectorContext context, PCFMessage message,
191192
getMetrics(context, message, queueName, queueType, fields);
192193
}
193194

195+
@Nullable
194196
private String getQueueTypeFromName(PCFMessage message, String queueName) throws PCFException {
195197
if (message.getParameterValue(CMQC.MQIA_Q_TYPE) == null) {
196198
return sharedState.getType(queueName);
@@ -216,8 +218,9 @@ private static String maybeAppendUsage(PCFMessage message, String baseQueueType)
216218
return baseQueueType + "-normal";
217219
case CMQC.MQUS_TRANSMISSION:
218220
return baseQueueType + "-transmission";
221+
default:
222+
return baseQueueType;
219223
}
220-
return baseQueueType;
221224
}
222225

223226
private static String getBaseQueueType(PCFMessage message) throws PCFException {
@@ -232,9 +235,10 @@ private static String getBaseQueueType(PCFMessage message) throws PCFException {
232235
return "cluster";
233236
case MQQT_MODEL:
234237
return "model";
238+
default:
239+
logger.warn("Unknown type of queue {}", message.getIntParameterValue(CMQC.MQIA_Q_TYPE));
240+
return "unknown";
235241
}
236-
logger.warn("Unknown type of queue {}", message.getIntParameterValue(CMQC.MQIA_Q_TYPE));
237-
return "unknown";
238242
}
239243

240244
private void getMetrics(

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import io.opentelemetry.ibm.mq.metrics.Metrics;
2121
import java.io.IOException;
2222
import java.util.function.Consumer;
23+
import org.jetbrains.annotations.Nullable;
2324
import org.slf4j.Logger;
2425
import org.slf4j.LoggerFactory;
2526

@@ -36,6 +37,7 @@ public ReadConfigurationEventQueueCollector(Meter meter) {
3637
this.maxHandlesGauge = Metrics.createMqManagerMaxHandles(meter);
3738
}
3839

40+
@Nullable
3941
private PCFMessage findLastUpdate(
4042
MetricsCollectorContext context, long entryTime, String configurationQueueName)
4143
throws Exception {

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@
1010
import org.slf4j.LoggerFactory;
1111

1212
/** Utilities reading configuration and create domain objects */
13-
class Config {
13+
final class Config {
1414

1515
private static final Logger logger = LoggerFactory.getLogger(Config.class);
1616

17-
static void setUpSSLConnection(Map<String, ?> config) {
17+
private Config(){
18+
19+
}
20+
21+
static void setUpSslConnection(Map<String, ?> config) {
1822
getConfigValueAndSetSystemProperty(config, "keyStorePath", "javax.net.ssl.keyStore");
1923
getConfigValueAndSetSystemProperty(
2024
config, "keyStorePassword", "javax.net.ssl.keyStorePassword");

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,19 @@
1313
import io.opentelemetry.sdk.resources.Resource;
1414
import java.util.concurrent.Executors;
1515
import java.util.concurrent.ScheduledExecutorService;
16+
import java.util.concurrent.ScheduledFuture;
1617
import java.util.concurrent.TimeUnit;
1718
import org.jetbrains.annotations.VisibleForTesting;
1819
import org.slf4j.Logger;
1920
import org.slf4j.LoggerFactory;
2021

21-
public class Main {
22+
@SuppressWarnings("SystemOut")
23+
public final class Main {
2224

2325
private static final Logger logger = LoggerFactory.getLogger(Main.class);
2426

27+
private Main() {}
28+
2529
public static void main(String[] args) throws Exception {
2630
if (args.length == 0) {
2731
System.err.println("Usage: Main <config-file>");
@@ -52,12 +56,12 @@ public static void main(String[] args) throws Exception {
5256
});
5357

5458
Config.configureSecurity(config);
55-
Config.setUpSSLConnection(config.getSslConnection());
59+
Config.setUpSslConnection(config.getSslConnection());
5660

5761
run(config, service);
5862
}
5963

60-
public static void run(ConfigWrapper config, final ScheduledExecutorService service) {
64+
public static void run(ConfigWrapper config, ScheduledExecutorService service) {
6165

6266
AutoConfiguredOpenTelemetrySdk sdk =
6367
AutoConfiguredOpenTelemetrySdk.builder()
@@ -77,7 +81,7 @@ public static void run(
7781

7882
Runtime.getRuntime().addShutdownHook(new Thread(service::shutdown));
7983
WmqMonitor monitor = new WmqMonitor(config, service, meterProvider.get("websphere/mq"));
80-
service.scheduleAtFixedRate(
84+
ScheduledFuture<?> unused = service.scheduleAtFixedRate(
8185
monitor::run,
8286
config.getTaskInitialDelaySeconds(),
8387
config.getTaskDelaySeconds(),

ibm-mq-metrics/src/test/java/io/opentelemetry/ibm/mq/opentelemetry/ConfigTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void cacheSystemProperties() {
2828

2929
@Test
3030
void testSSLConnection() {
31-
Config.setUpSSLConnection(
31+
Config.setUpSslConnection(
3232
new HashMap<String, Object>() {
3333
{
3434
put("keyStorePath", "foo");

0 commit comments

Comments
 (0)