Skip to content

Commit 136b3ed

Browse files
committed
spotbug corrections
1 parent 9b965e2 commit 136b3ed

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
id "jacoco"
44
id "maven-publish"
55
id "signing"
6-
id "com.github.spotbugs" version "5.0.0"
6+
id "com.github.spotbugs" version "6.4.8"
77
id "org.sonarqube" version "2.7.1"
88
}
99

@@ -177,6 +177,7 @@ signing {
177177
}
178178

179179
spotbugsMain {
180+
excludeFilter = file("spotbugs-exclude.xml")
180181
reports {
181182
xml.required.set(true)
182183
html.required.set(true)

spotbugs-exclude.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<FindBugsFilter>
3+
<Match>
4+
<Bug code="EI,EI2" />
5+
</Match>
6+
<Match>
7+
<Class name="ch.loway.oss.ari4java.tools.http.NettyHttpClient" />
8+
<Or>
9+
<Method name="setAutoReconnect" />
10+
<Method name="setMaxReconnectCount" />
11+
</Or>
12+
<Bug code="AT" />
13+
</Match>
14+
</FindBugsFilter>

src/main/java/ch/loway/oss/ari4java/ARI.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ public class ARI {
3030
private HttpClient httpClient;
3131
private WsClient wsClient;
3232
private ActionEvents liveActionEvent = null;
33-
private AriSubscriber subscriptions = new AriSubscriber();
33+
private final AriSubscriber subscriptions = new AriSubscriber();
3434
private final CopyOnWriteArrayList<BaseAriAction> liveActionList = new CopyOnWriteArrayList<>();
35-
private static Logger logger = LoggerFactory.getLogger(ARI.class);
35+
private static final Logger logger = LoggerFactory.getLogger(ARI.class);
36+
private static final SecureRandom random = new SecureRandom();
3637

3738
/**
3839
* Sets the client
@@ -469,7 +470,6 @@ public static void sleep(long ms) {
469470
public static String getUID() {
470471
StringBuilder sb = new StringBuilder(20);
471472
sb.append("a4j");
472-
SecureRandom random = new SecureRandom();
473473
for (int n = 0; n < 15; n++) {
474474
if ((n % 5) == 0) {
475475
sb.append(".");

src/main/java/ch/loway/oss/ari4java/tools/http/HTTPLogger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import java.util.Arrays;
1010
import java.util.Map;
1111

12-
public class HTTPLogger {
12+
public final class HTTPLogger {
1313

1414
private HTTPLogger() {
1515
throw new IllegalStateException("Utility class");

src/main/java/ch/loway/oss/ari4java/tools/http/NettyHttpClient.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.net.URISyntaxException;
3636
import java.util.List;
3737
import java.util.concurrent.TimeUnit;
38+
import java.util.concurrent.atomic.AtomicInteger;
3839

3940
/**
4041
* HTTP and WebSocket client implementation based on netty.io.
@@ -71,7 +72,7 @@ public class NettyHttpClient implements HttpClient, WsClient {
7172
private String wsEventsUrl;
7273
private List<HttpParam> wsEventsParamQuery;
7374
private WsClientConnection wsClientConnection;
74-
private int reconnectCount = 0;
75+
private final AtomicInteger reconnectCount = new AtomicInteger(0);
7576
private int maxReconnectCount = 10; // -1 = infinite reconnect attempts
7677
private ChannelFuture wsChannelFuture;
7778
private ScheduledFuture<?> wsPingTimer = null;
@@ -481,7 +482,7 @@ public void operationComplete(ChannelFuture future) throws Exception {
481482
logger.debug("WS connected...");
482483
// start a ping and reset reconnect counter
483484
startPing();
484-
reconnectCount = 0;
485+
reconnectCount.set(0);
485486
if (!group.isShuttingDown()) {
486487
group.execute(callback::onChReadyToWrite);
487488
}
@@ -612,7 +613,7 @@ public void reconnectWs(Throwable cause) {
612613
wsPingTimer = null;
613614
}
614615

615-
if (!autoReconnect || (maxReconnectCount > -1 && reconnectCount >= maxReconnectCount)) {
616+
if (!autoReconnect || (maxReconnectCount > -1 && reconnectCount.get() >= maxReconnectCount)) {
616617
logger.warn("Cannot connect: {} - executing failure callback", cause.getMessage());
617618
if (!group.isShuttingDown()) {
618619
group.execute(() -> wsCallback.onFailure(cause));
@@ -624,9 +625,9 @@ public void reconnectWs(Throwable cause) {
624625
if (!group.isShuttingDown()) {
625626
// schedule reconnect after a 2,5,10 seconds
626627
long[] timeouts = {2L, 5L, 10L};
627-
long timeout = reconnectCount >= timeouts.length ? timeouts[timeouts.length - 1] : timeouts[reconnectCount];
628-
reconnectCount++;
629-
logger.error("WS Connect Error: {}, reconnecting in {} seconds... try: {}", cause.getMessage(), timeout, reconnectCount);
628+
long timeout = reconnectCount.get() >= timeouts.length ? timeouts[timeouts.length - 1] : timeouts[reconnectCount.get()];
629+
reconnectCount.incrementAndGet();
630+
logger.error("WS Connect Error: {}, reconnecting in {} seconds... try: {}", cause.getMessage(), timeout, reconnectCount.get());
630631
shutDownGroup.schedule(() -> {
631632
try {
632633
// 1st close up

0 commit comments

Comments
 (0)