Skip to content

Commit

Permalink
Merge branch 'traccar:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
petgnss authored Sep 2, 2024
2 parents 77ccbf6 + c1d6ef7 commit efaa58a
Show file tree
Hide file tree
Showing 156 changed files with 1,296 additions and 639 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ jobs:
working-directory: ./setup
run: |
wget -q http://files.jrsoftware.org/is/5/isetup-5.5.6.exe
wget -q https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.2+13/OpenJDK21U-jdk_x64_windows_hotspot_21.0.2_13.zip
wget -q https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.2+13/OpenJDK21U-jdk_x64_linux_hotspot_21.0.2_13.tar.gz
wget -q https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.2+13/OpenJDK21U-jdk_aarch64_linux_hotspot_21.0.2_13.tar.gz
wget -q https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.4+7/OpenJDK21U-jdk_x64_windows_hotspot_21.0.4_7.zip
wget -q https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.4+7/OpenJDK21U-jdk_x64_linux_hotspot_21.0.4_7.tar.gz
wget -q https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.4+7/OpenJDK21U-jdk_aarch64_linux_hotspot_21.0.4_7.tar.gz
./package.sh ${{ github.event.inputs.version }}
- name: Upload installers to GitHub Releases
Expand Down
32 changes: 16 additions & 16 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ ext {
guiceVersion = "7.0.0"
jettyVersion = "11.0.21"
jerseyVersion = "3.1.7"
jacksonVersion = "2.17.1" // same version as jersey-media-json-jackson dependency
protobufVersion = "4.27.0"
jxlsVersion = "2.14.0" // version 3 requires java 17
junitVersion = "5.10.2"
jacksonVersion = "2.17.2" // same version as jersey-media-json-jackson dependency
protobufVersion = "4.27.2"
jxlsVersion = "2.14.0" // version 3 has breaking changes
junitVersion = "5.10.3"
}

protobuf {
Expand All @@ -47,14 +47,14 @@ protobuf {
}

dependencies {
implementation "commons-codec:commons-codec:1.17.0"
implementation "com.h2database:h2:2.2.224"
implementation "com.mysql:mysql-connector-j:8.4.0"
implementation "org.mariadb.jdbc:mariadb-java-client:3.4.0"
implementation "commons-codec:commons-codec:1.17.1"
implementation "com.h2database:h2:2.3.230"
implementation "com.mysql:mysql-connector-j:9.0.0"
implementation "org.mariadb.jdbc:mariadb-java-client:3.4.1"
implementation "org.postgresql:postgresql:42.7.3"
implementation "com.microsoft.sqlserver:mssql-jdbc:12.6.2.jre11"
implementation "com.microsoft.sqlserver:mssql-jdbc:12.6.3.jre11"
implementation "com.zaxxer:HikariCP:5.1.0"
implementation "io.netty:netty-all:4.1.110.Final"
implementation "io.netty:netty-all:4.1.112.Final"
implementation "org.slf4j:slf4j-jdk14:2.0.13"
implementation "com.google.inject:guice:$guiceVersion"
implementation "com.google.inject.extensions:guice-servlet:$guiceVersion"
Expand All @@ -74,24 +74,24 @@ dependencies {
implementation "com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:$jacksonVersion"
implementation "com.fasterxml.jackson.datatype:jackson-datatype-jakarta-jsonp:$jacksonVersion"
implementation "org.liquibase:liquibase-core:4.23.2" // upgrade has issues
implementation "org.apache.commons:commons-jexl3:3.3"
implementation "org.apache.commons:commons-jexl3:3.4.0"
implementation "org.jxls:jxls:$jxlsVersion"
implementation "org.jxls:jxls-poi:$jxlsVersion"
implementation "org.apache.velocity:velocity-engine-core:2.3"
implementation "org.apache.velocity.tools:velocity-tools-generic:3.1"
implementation "org.apache.commons:commons-collections4:4.4"
implementation "org.mnode.ical4j:ical4j:3.2.18"
implementation "org.mnode.ical4j:ical4j:4.0.2"
implementation "org.locationtech.spatial4j:spatial4j:0.8"
implementation "org.locationtech.jts:jts-core:1.19.0"
implementation "net.java.dev.jna:jna-platform:5.14.0"
implementation "com.github.jnr:jnr-posix:3.1.19"
implementation "com.google.protobuf:protobuf-java:$protobufVersion"
implementation "com.amazonaws:aws-java-sdk-sns:1.12.733"
implementation "org.apache.kafka:kafka-clients:3.7.0"
implementation "com.amazonaws:aws-java-sdk-sns:1.12.765"
implementation "org.apache.kafka:kafka-clients:3.8.0"
implementation "com.hivemq:hivemq-mqtt-client:1.3.3"
implementation "redis.clients:jedis:5.1.3"
implementation "com.google.firebase:firebase-admin:9.3.0"
implementation "com.nimbusds:oauth2-oidc-sdk:11.12"
implementation "com.nimbusds:oauth2-oidc-sdk:11.13"
implementation "com.rabbitmq:amqp-client:5.21.0"
implementation "com.warrenstrange:googleauth:1.5.0"
implementation "com.google.openlocationcode:openlocationcode:1.0.4"
Expand All @@ -114,7 +114,7 @@ jar {
manifest {
attributes(
"Main-Class": "org.traccar.Main",
"Implementation-Version": "6.2",
"Implementation-Version": "6.4",
"Class-Path": configurations.runtimeClasspath.files.collect { "lib/$it.name" }.join(" "))
}
}
2 changes: 1 addition & 1 deletion setup/traccar.iss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[Setup]
AppName=Traccar
AppVersion=6.2
AppVersion=6.4
DefaultDirName={pf}\Traccar
OutputBaseFilename=traccar-setup
ArchitecturesInstallIn64BitMode=x64
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/traccar/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.ExecutorService;

public final class Main {

Expand Down Expand Up @@ -140,6 +141,7 @@ public static void run(String configFile) {
throw new RuntimeException(e);
}
}
injector.getInstance(ExecutorService.class).shutdown();
}));
} catch (Exception e) {
Throwable unwrapped;
Expand Down
21 changes: 16 additions & 5 deletions src/main/java/org/traccar/MainModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.traccar.forward.PositionForwarderRedis;
import org.traccar.forward.PositionForwarderUrl;
import org.traccar.forward.PositionForwarderMqtt;
import org.traccar.forward.PositionForwarderWialon;
import org.traccar.geocoder.AddressFormat;
import org.traccar.geocoder.BanGeocoder;
import org.traccar.geocoder.BingMapsGeocoder;
Expand Down Expand Up @@ -104,6 +105,8 @@
import java.net.URISyntaxException;
import java.net.http.HttpClient;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class MainModule extends AbstractModule {

Expand All @@ -120,6 +123,12 @@ protected void configure() {
bind(Timer.class).to(HashedWheelTimer.class).in(Scopes.SINGLETON);
}

@Singleton
@Provides
public static ExecutorService provideExecutorService() {
return Executors.newCachedThreadPool();
}

@Singleton
@Provides
public static Storage provideStorage(Injector injector, Config config) {
Expand Down Expand Up @@ -226,7 +235,7 @@ public static Geocoder provideGeocoder(Config config, Client client, StatisticsM
case "maptiler" -> new MapTilerGeocoder(client, key, cacheSize, addressFormat);
case "geoapify" -> new GeoapifyGeocoder(client, key, language, cacheSize, addressFormat);
case "geocodejson" -> new GeocodeJsonGeocoder(client, url, key, language, cacheSize, addressFormat);
default -> new GoogleGeocoder(client, key, language, cacheSize, addressFormat);
default -> new GoogleGeocoder(client, url, key, language, cacheSize, addressFormat);
};
geocoder.setStatisticsManager(statisticsManager);
return geocoder;
Expand Down Expand Up @@ -325,11 +334,11 @@ public static TimeHandler provideTimeHandler(Config config) {
@Singleton
@Provides
public static BroadcastService provideBroadcastService(
Config config, ObjectMapper objectMapper) throws IOException {
Config config, ExecutorService executorService, ObjectMapper objectMapper) throws IOException {
if (config.hasKey(Keys.BROADCAST_TYPE)) {
return switch (config.getString(Keys.BROADCAST_TYPE)) {
case "multicast" -> new MulticastBroadcastService(config, objectMapper);
case "redis" -> new RedisBroadcastService(config, objectMapper);
case "multicast" -> new MulticastBroadcastService(config, executorService, objectMapper);
case "redis" -> new RedisBroadcastService(config, executorService, objectMapper);
default -> new NullBroadcastService();
};
}
Expand All @@ -353,14 +362,16 @@ public static EventForwarder provideEventForwarder(Config config, Client client,

@Singleton
@Provides
public static PositionForwarder providePositionForwarder(Config config, Client client, ObjectMapper objectMapper) {
public static PositionForwarder providePositionForwarder(
Config config, Client client, ExecutorService executorService, ObjectMapper objectMapper) {
if (config.hasKey(Keys.FORWARD_URL)) {
return switch (config.getString(Keys.FORWARD_TYPE)) {
case "json" -> new PositionForwarderJson(config, client, objectMapper);
case "amqp" -> new PositionForwarderAmqp(config, objectMapper);
case "kafka" -> new PositionForwarderKafka(config, objectMapper);
case "mqtt" -> new PositionForwarderMqtt(config, objectMapper);
case "redis" -> new PositionForwarderRedis(config, objectMapper);
case "wialon" -> new PositionForwarderWialon(config, executorService, "1.0");
default -> new PositionForwarderUrl(config, client, objectMapper);
};
}
Expand Down
28 changes: 22 additions & 6 deletions src/main/java/org/traccar/ProcessingHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import io.netty.channel.ChannelInboundHandlerAdapter;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.traccar.config.Config;
import org.traccar.database.BufferingManager;
import org.traccar.database.NotificationManager;
Expand All @@ -29,6 +31,7 @@
import org.traccar.handler.CopyAttributesHandler;
import org.traccar.handler.DatabaseHandler;
import org.traccar.handler.DistanceHandler;
import org.traccar.handler.DriverHandler;
import org.traccar.handler.EngineHoursHandler;
import org.traccar.handler.FilterHandler;
import org.traccar.handler.GeocoderHandler;
Expand All @@ -41,7 +44,7 @@
import org.traccar.handler.PostProcessHandler;
import org.traccar.handler.SpeedLimitHandler;
import org.traccar.handler.TimeHandler;
import org.traccar.handler.events.AlertEventHandler;
import org.traccar.handler.events.AlarmEventHandler;
import org.traccar.handler.events.BaseEventHandler;
import org.traccar.handler.events.BehaviorEventHandler;
import org.traccar.handler.events.CommandResultEventHandler;
Expand All @@ -56,20 +59,23 @@
import org.traccar.handler.network.AcknowledgementHandler;
import org.traccar.helper.PositionLogger;
import org.traccar.model.Position;
import org.traccar.session.cache.CacheManager;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Queue;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Singleton
@ChannelHandler.Sharable
public class ProcessingHandler extends ChannelInboundHandlerAdapter implements BufferingManager.Callback {

private static final Logger LOGGER = LoggerFactory.getLogger(ProcessingHandler.class);

private final CacheManager cacheManager;
private final NotificationManager notificationManager;
private final PositionLogger positionLogger;
private final BufferingManager bufferingManager;
Expand All @@ -85,7 +91,9 @@ private synchronized Queue<Position> getQueue(long deviceId) {

@Inject
public ProcessingHandler(
Injector injector, Config config, NotificationManager notificationManager, PositionLogger positionLogger) {
Injector injector, Config config,
CacheManager cacheManager, NotificationManager notificationManager, PositionLogger positionLogger) {
this.cacheManager = cacheManager;
this.notificationManager = notificationManager;
this.positionLogger = positionLogger;
bufferingManager = new BufferingManager(config, this);
Expand All @@ -103,12 +111,13 @@ public ProcessingHandler(
MotionHandler.class,
ComputedAttributesHandler.class,
EngineHoursHandler.class,
DriverHandler.class,
CopyAttributesHandler.class,
PositionForwardingHandler.class,
DatabaseHandler.class)
.map((clazz) -> (BasePositionHandler) injector.getInstance(clazz))
.filter(Objects::nonNull)
.collect(Collectors.toUnmodifiableList());
.toList();

eventHandlers = Stream.of(
MediaEventHandler.class,
Expand All @@ -118,13 +127,13 @@ public ProcessingHandler(
FuelEventHandler.class,
MotionEventHandler.class,
GeofenceEventHandler.class,
AlertEventHandler.class,
AlarmEventHandler.class,
IgnitionEventHandler.class,
MaintenanceEventHandler.class,
DriverEventHandler.class)
.map((clazz) -> (BaseEventHandler) injector.getInstance(clazz))
.filter(Objects::nonNull)
.collect(Collectors.toUnmodifiableList());
.toList();

postProcessHandler = injector.getInstance(PostProcessHandler.class);
}
Expand All @@ -147,6 +156,11 @@ public void onReleased(ChannelHandlerContext context, Position position) {
queue.offer(position);
}
if (!queued) {
try {
cacheManager.addDevice(position.getDeviceId(), position.getDeviceId());
} catch (Exception e) {
throw new RuntimeException(e);
}
processPositionHandlers(context, position);
}
}
Expand Down Expand Up @@ -197,6 +211,8 @@ private void processNextPosition(ChannelHandlerContext ctx, long deviceId) {
}
if (nextPosition != null) {
processPositionHandlers(ctx, nextPosition);
} else {
cacheManager.removeDevice(deviceId, deviceId);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/traccar/api/resource/DeviceResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,13 @@ public Response updateAccumulators(DeviceAccumulators entity) throws Exception {
new Columns.Include("positionId"),
new Condition.Equals("id", device.getId())));

var key = new Object();
try {
cacheManager.addDevice(position.getDeviceId());
cacheManager.addDevice(position.getDeviceId(), key);
cacheManager.updatePosition(position);
connectionManager.updatePosition(true, position);
} finally {
cacheManager.removeDevice(position.getDeviceId());
cacheManager.removeDevice(position.getDeviceId(), key);
}
} else {
throw new IllegalArgumentException();
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/org/traccar/api/resource/UserResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.traccar.config.Keys;
import org.traccar.helper.LogAction;
import org.traccar.helper.model.UserUtil;
import org.traccar.model.Device;
import org.traccar.model.ManagedUser;
import org.traccar.model.Permission;
import org.traccar.model.User;
Expand Down Expand Up @@ -61,12 +62,18 @@ public UserResource() {
}

@GET
public Collection<User> get(@QueryParam("userId") long userId) throws StorageException {
public Collection<User> get(
@QueryParam("userId") long userId, @QueryParam("deviceId") long deviceId) throws StorageException {
if (userId > 0) {
permissionsService.checkUser(getUserId(), userId);
return storage.getObjects(baseClass, new Request(
new Columns.All(),
new Condition.Permission(User.class, userId, ManagedUser.class).excludeGroups()));
} else if (deviceId > 0) {
permissionsService.checkAdmin(getUserId());
return storage.getObjects(baseClass, new Request(
new Columns.All(),
new Condition.Permission(User.class, Device.class, deviceId).excludeGroups()));
} else if (permissionsService.notAdmin(getUserId())) {
return storage.getObjects(baseClass, new Request(
new Columns.All(),
Expand Down
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.
Expand Down Expand Up @@ -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 {

Expand All @@ -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);
Expand Down Expand Up @@ -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() {
Expand All @@ -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()))) {
Expand Down
Loading

0 comments on commit efaa58a

Please sign in to comment.