forked from traccar/traccar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'traccar:master' into master
- Loading branch information
Showing
156 changed files
with
1,296 additions
and
639 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2022 Anton Tananaev ([email protected]) | ||
* Copyright 2022 - 2024 Anton Tananaev ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -30,7 +30,6 @@ | |
import java.net.NetworkInterface; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
|
||
public class MulticastBroadcastService extends BaseBroadcastService { | ||
|
||
|
@@ -44,10 +43,12 @@ public class MulticastBroadcastService extends BaseBroadcastService { | |
|
||
private DatagramSocket publisherSocket; | ||
|
||
private final ExecutorService service = Executors.newSingleThreadExecutor(); | ||
private final ExecutorService executorService; | ||
private final byte[] receiverBuffer = new byte[4096]; | ||
|
||
public MulticastBroadcastService(Config config, ObjectMapper objectMapper) throws IOException { | ||
public MulticastBroadcastService( | ||
Config config, ExecutorService executorService, ObjectMapper objectMapper) throws IOException { | ||
this.executorService = executorService; | ||
this.objectMapper = objectMapper; | ||
port = config.getInteger(Keys.BROADCAST_PORT); | ||
String interfaceName = config.getString(Keys.BROADCAST_INTERFACE); | ||
|
@@ -78,12 +79,11 @@ protected void sendMessage(BroadcastMessage message) { | |
|
||
@Override | ||
public void start() throws IOException { | ||
service.submit(receiver); | ||
executorService.submit(receiver); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
service.shutdown(); | ||
} | ||
|
||
private final Runnable receiver = new Runnable() { | ||
|
@@ -93,7 +93,7 @@ public void run() { | |
socket.setNetworkInterface(networkInterface); | ||
socket.joinGroup(group, networkInterface); | ||
publisherSocket = socket; | ||
while (!service.isShutdown()) { | ||
while (!executorService.isShutdown()) { | ||
DatagramPacket packet = new DatagramPacket(receiverBuffer, receiverBuffer.length); | ||
socket.receive(packet); | ||
if (networkInterface.inetAddresses().noneMatch(a -> a.equals(packet.getAddress()))) { | ||
|
Oops, something went wrong.