aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/handler
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2024-07-06 17:46:17 -0700
committerAnton Tananaev <anton@traccar.org>2024-07-06 17:46:17 -0700
commitb8390005722dd1cdb24d762797ef3f98ebc37755 (patch)
treecaabf1a7541aebc4e81565e95ee78e2d8afe3d75 /src/main/java/org/traccar/handler
parent75e3c6a6bbb028b2f99b06faac66d5b53cf59900 (diff)
downloadtrackermap-server-b8390005722dd1cdb24d762797ef3f98ebc37755.tar.gz
trackermap-server-b8390005722dd1cdb24d762797ef3f98ebc37755.tar.bz2
trackermap-server-b8390005722dd1cdb24d762797ef3f98ebc37755.zip
Update instanceof expressions
Diffstat (limited to 'src/main/java/org/traccar/handler')
-rw-r--r--src/main/java/org/traccar/handler/network/AcknowledgementHandler.java6
-rw-r--r--src/main/java/org/traccar/handler/network/NetworkMessageHandler.java6
-rw-r--r--src/main/java/org/traccar/handler/network/RemoteAddressHandler.java3
-rw-r--r--src/main/java/org/traccar/handler/network/StandardLoggingHandler.java6
4 files changed, 7 insertions, 14 deletions
diff --git a/src/main/java/org/traccar/handler/network/AcknowledgementHandler.java b/src/main/java/org/traccar/handler/network/AcknowledgementHandler.java
index e87f5d34c..7ba625e00 100644
--- a/src/main/java/org/traccar/handler/network/AcknowledgementHandler.java
+++ b/src/main/java/org/traccar/handler/network/AcknowledgementHandler.java
@@ -92,12 +92,10 @@ public class AcknowledgementHandler extends ChannelOutboundHandlerAdapter {
if (queue == null) {
queue = new LinkedList<>();
}
- } else if (msg instanceof EventDecoded) {
- EventDecoded event = (EventDecoded) msg;
+ } else if (msg instanceof EventDecoded event) {
LOGGER.debug("Event decoded {}", event.getObjects().size());
waiting.addAll(event.getObjects());
- } else if (msg instanceof EventHandled) {
- EventHandled event = (EventHandled) msg;
+ } else if (msg instanceof EventHandled event) {
LOGGER.debug("Event handled");
waiting.remove(event.getObject());
}
diff --git a/src/main/java/org/traccar/handler/network/NetworkMessageHandler.java b/src/main/java/org/traccar/handler/network/NetworkMessageHandler.java
index c2fb9016a..f151c91a9 100644
--- a/src/main/java/org/traccar/handler/network/NetworkMessageHandler.java
+++ b/src/main/java/org/traccar/handler/network/NetworkMessageHandler.java
@@ -32,16 +32,14 @@ public class NetworkMessageHandler extends ChannelDuplexHandler {
if (ctx.channel() instanceof DatagramChannel) {
DatagramPacket packet = (DatagramPacket) msg;
ctx.fireChannelRead(new NetworkMessage(packet.content(), packet.sender()));
- } else if (msg instanceof ByteBuf) {
- ByteBuf buffer = (ByteBuf) msg;
+ } else if (msg instanceof ByteBuf buffer) {
ctx.fireChannelRead(new NetworkMessage(buffer, ctx.channel().remoteAddress()));
}
}
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
- if (msg instanceof NetworkMessage) {
- NetworkMessage message = (NetworkMessage) msg;
+ if (msg instanceof NetworkMessage message) {
if (ctx.channel() instanceof DatagramChannel) {
InetSocketAddress recipient = (InetSocketAddress) message.getRemoteAddress();
InetSocketAddress sender = (InetSocketAddress) ctx.channel().localAddress();
diff --git a/src/main/java/org/traccar/handler/network/RemoteAddressHandler.java b/src/main/java/org/traccar/handler/network/RemoteAddressHandler.java
index c52bb2be1..9d5504ce1 100644
--- a/src/main/java/org/traccar/handler/network/RemoteAddressHandler.java
+++ b/src/main/java/org/traccar/handler/network/RemoteAddressHandler.java
@@ -44,8 +44,7 @@ public class RemoteAddressHandler extends ChannelInboundHandlerAdapter {
InetSocketAddress remoteAddress = (InetSocketAddress) ctx.channel().remoteAddress();
String hostAddress = remoteAddress != null ? remoteAddress.getAddress().getHostAddress() : null;
- if (msg instanceof Position) {
- Position position = (Position) msg;
+ if (msg instanceof Position position) {
position.set(Position.KEY_IP, hostAddress);
}
}
diff --git a/src/main/java/org/traccar/handler/network/StandardLoggingHandler.java b/src/main/java/org/traccar/handler/network/StandardLoggingHandler.java
index f6ee08756..8e63cae4d 100644
--- a/src/main/java/org/traccar/handler/network/StandardLoggingHandler.java
+++ b/src/main/java/org/traccar/handler/network/StandardLoggingHandler.java
@@ -72,12 +72,10 @@ public class StandardLoggingHandler extends ChannelDuplexHandler {
}
private LogRecord createLogRecord(ChannelHandlerContext ctx, Object msg) {
- if (msg instanceof NetworkMessage) {
- NetworkMessage networkMessage = (NetworkMessage) msg;
- if (networkMessage.getMessage() instanceof ByteBuf) {
+ if (msg instanceof NetworkMessage networkMessage) {
+ if (networkMessage.getMessage() instanceof ByteBuf data) {
LogRecord record = new LogRecord(ctx.channel().localAddress(), networkMessage.getRemoteAddress());
record.setProtocol(protocol);
- ByteBuf data = (ByteBuf) networkMessage.getMessage();
if (decodeTextData && BufferUtil.isPrintable(data, data.readableBytes())) {
record.setData(data.getCharSequence(
data.readerIndex(), data.readableBytes(), StandardCharsets.US_ASCII).toString()