aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/MainModule.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-05-30 13:12:37 -0700
committerAnton Tananaev <anton@traccar.org>2022-05-30 13:12:37 -0700
commitce661ec77a957b70c15509c6801e6f34b32ad11d (patch)
tree1fd501abc09e1eeceb3bf411b5d2612b27cc35ad /src/main/java/org/traccar/MainModule.java
parent154ff3b2175e67b3fac531cb9c5c5c68880f5e12 (diff)
downloadtrackermap-server-ce661ec77a957b70c15509c6801e6f34b32ad11d.tar.gz
trackermap-server-ce661ec77a957b70c15509c6801e6f34b32ad11d.tar.bz2
trackermap-server-ce661ec77a957b70c15509c6801e6f34b32ad11d.zip
Improve dependency injection
Diffstat (limited to 'src/main/java/org/traccar/MainModule.java')
-rw-r--r--src/main/java/org/traccar/MainModule.java213
1 files changed, 12 insertions, 201 deletions
diff --git a/src/main/java/org/traccar/MainModule.java b/src/main/java/org/traccar/MainModule.java
index 79cfcc0a8..60b5854fd 100644
--- a/src/main/java/org/traccar/MainModule.java
+++ b/src/main/java/org/traccar/MainModule.java
@@ -18,7 +18,10 @@ package org.traccar;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
+import com.google.inject.Scopes;
import com.google.inject.Singleton;
+import io.netty.util.HashedWheelTimer;
+import io.netty.util.Timer;
import org.traccar.config.Config;
import org.traccar.config.Keys;
import org.traccar.database.AttributesManager;
@@ -43,51 +46,35 @@ import org.traccar.geocoder.GoogleGeocoder;
import org.traccar.geocoder.HereGeocoder;
import org.traccar.geocoder.MapQuestGeocoder;
import org.traccar.geocoder.MapTilerGeocoder;
+import org.traccar.geocoder.MapboxGeocoder;
import org.traccar.geocoder.MapmyIndiaGeocoder;
import org.traccar.geocoder.NominatimGeocoder;
import org.traccar.geocoder.OpenCageGeocoder;
import org.traccar.geocoder.PositionStackGeocoder;
import org.traccar.geocoder.TomTomGeocoder;
-import org.traccar.geocoder.MapboxGeocoder;
import org.traccar.geolocation.GeolocationProvider;
import org.traccar.geolocation.GoogleGeolocationProvider;
import org.traccar.geolocation.MozillaGeolocationProvider;
import org.traccar.geolocation.OpenCellIdGeolocationProvider;
import org.traccar.geolocation.UnwiredGeolocationProvider;
-import org.traccar.handler.ComputedAttributesHandler;
-import org.traccar.handler.CopyAttributesHandler;
-import org.traccar.handler.DefaultDataHandler;
-import org.traccar.handler.DistanceHandler;
-import org.traccar.handler.EngineHoursHandler;
-import org.traccar.handler.FilterHandler;
import org.traccar.handler.GeocoderHandler;
import org.traccar.handler.GeolocationHandler;
-import org.traccar.handler.HemisphereHandler;
-import org.traccar.handler.MotionHandler;
-import org.traccar.handler.RemoteAddressHandler;
import org.traccar.handler.SpeedLimitHandler;
-import org.traccar.handler.TimeHandler;
-import org.traccar.handler.events.AlertEventHandler;
-import org.traccar.handler.events.BehaviorEventHandler;
-import org.traccar.handler.events.CommandResultEventHandler;
-import org.traccar.handler.events.DriverEventHandler;
-import org.traccar.handler.events.FuelDropEventHandler;
-import org.traccar.handler.events.GeofenceEventHandler;
-import org.traccar.handler.events.IgnitionEventHandler;
-import org.traccar.handler.events.MaintenanceEventHandler;
-import org.traccar.handler.events.MotionEventHandler;
-import org.traccar.handler.events.OverspeedEventHandler;
import org.traccar.reports.model.TripsConfig;
-
-import javax.annotation.Nullable;
-import javax.ws.rs.client.Client;
-import io.netty.util.Timer;
import org.traccar.speedlimit.OverpassSpeedLimitProvider;
import org.traccar.speedlimit.SpeedLimitProvider;
import org.traccar.storage.Storage;
+import javax.annotation.Nullable;
+import javax.ws.rs.client.Client;
+
public class MainModule extends AbstractModule {
+ @Override
+ protected void configure() {
+ bind(Timer.class).to(HashedWheelTimer.class).in(Scopes.SINGLETON);
+ }
+
@Provides
public static ObjectMapper provideObjectMapper() {
return Context.getObjectMapper();
@@ -155,13 +142,6 @@ public class MainModule extends AbstractModule {
@Singleton
@Provides
- public static StatisticsManager provideStatisticsManager(
- Config config, DataManager dataManager, Client client, ObjectMapper objectMapper) {
- return new StatisticsManager(config, dataManager, client, objectMapper);
- }
-
- @Singleton
- @Provides
public static Geocoder provideGeocoder(Config config) {
if (config.getBoolean(Keys.GEOCODER_ENABLE)) {
String type = config.getString(Keys.GEOCODER_TYPE, "google");
@@ -249,50 +229,6 @@ public class MainModule extends AbstractModule {
return null;
}
- @Singleton
- @Provides
- public static DistanceHandler provideDistanceHandler(Config config, IdentityManager identityManager) {
- return new DistanceHandler(config, identityManager);
- }
-
- @Singleton
- @Provides
- public static FilterHandler provideFilterHandler(Config config) {
- if (config.getBoolean(Keys.FILTER_ENABLE)) {
- return new FilterHandler(config);
- }
- return null;
- }
-
- @Singleton
- @Provides
- public static HemisphereHandler provideHemisphereHandler(Config config) {
- if (config.hasKey(Keys.LOCATION_LATITUDE_HEMISPHERE) || config.hasKey(Keys.LOCATION_LONGITUDE_HEMISPHERE)) {
- return new HemisphereHandler(config);
- }
- return null;
- }
-
- @Singleton
- @Provides
- public static RemoteAddressHandler provideRemoteAddressHandler(Config config) {
- if (config.getBoolean(Keys.PROCESSING_REMOTE_ADDRESS_ENABLE)) {
- return new RemoteAddressHandler();
- }
- return null;
- }
-
- @Singleton
- @Provides
- public static WebDataHandler provideWebDataHandler(
- Config config, IdentityManager identityManager, ObjectMapper objectMapper, Client client) {
- if (config.hasKey(Keys.FORWARD_URL)) {
- return new WebDataHandler(config, identityManager, objectMapper, client);
- }
- return null;
- }
-
- @Singleton
@Provides
public static GeolocationHandler provideGeolocationHandler(
Config config, @Nullable GeolocationProvider geolocationProvider, StatisticsManager statisticsManager) {
@@ -302,7 +238,6 @@ public class MainModule extends AbstractModule {
return null;
}
- @Singleton
@Provides
public static GeocoderHandler provideGeocoderHandler(
Config config, @Nullable Geocoder geocoder, IdentityManager identityManager) {
@@ -312,7 +247,6 @@ public class MainModule extends AbstractModule {
return null;
}
- @Singleton
@Provides
public static SpeedLimitHandler provideSpeedLimitHandler(@Nullable SpeedLimitProvider speedLimitProvider) {
if (speedLimitProvider != null) {
@@ -321,127 +255,4 @@ public class MainModule extends AbstractModule {
return null;
}
- @Singleton
- @Provides
- public static MotionHandler provideMotionHandler(TripsConfig tripsConfig) {
- return new MotionHandler(tripsConfig.getSpeedThreshold());
- }
-
- @Singleton
- @Provides
- public static EngineHoursHandler provideEngineHoursHandler(Config config, IdentityManager identityManager) {
- if (config.getBoolean(Keys.PROCESSING_ENGINE_HOURS_ENABLE)) {
- return new EngineHoursHandler(identityManager);
- }
- return null;
- }
-
- @Singleton
- @Provides
- public static CopyAttributesHandler provideCopyAttributesHandler(Config config, IdentityManager identityManager) {
- if (config.getBoolean(Keys.PROCESSING_COPY_ATTRIBUTES_ENABLE)) {
- return new CopyAttributesHandler(identityManager);
- }
- return null;
- }
-
- @Singleton
- @Provides
- public static ComputedAttributesHandler provideComputedAttributesHandler(
- Config config, IdentityManager identityManager, AttributesManager attributesManager) {
- if (config.getBoolean(Keys.PROCESSING_COMPUTED_ATTRIBUTES_ENABLE)) {
- return new ComputedAttributesHandler(config, identityManager, attributesManager);
- }
- return null;
- }
-
- @Singleton
- @Provides
- public static TimeHandler provideTimeHandler(Config config) {
- if (config.hasKey(Keys.TIME_OVERRIDE)) {
- return new TimeHandler(config);
- }
- return null;
- }
-
- @Singleton
- @Provides
- public static DefaultDataHandler provideDefaultDataHandler(@Nullable DataManager dataManager) {
- if (dataManager != null) {
- return new DefaultDataHandler(dataManager);
- }
- return null;
- }
-
- @Singleton
- @Provides
- public static CommandResultEventHandler provideCommandResultEventHandler() {
- return new CommandResultEventHandler();
- }
-
- @Singleton
- @Provides
- public static OverspeedEventHandler provideOverspeedEventHandler(
- Config config, DeviceManager deviceManager, GeofenceManager geofenceManager) {
- return new OverspeedEventHandler(config, deviceManager, geofenceManager);
- }
-
- @Singleton
- @Provides
- public static BehaviorEventHandler provideBehaviorEventHandler(Config config, IdentityManager identityManager) {
- return new BehaviorEventHandler(config, identityManager);
- }
-
- @Singleton
- @Provides
- public static FuelDropEventHandler provideFuelDropEventHandler(IdentityManager identityManager) {
- return new FuelDropEventHandler(identityManager);
- }
-
- @Singleton
- @Provides
- public static MotionEventHandler provideMotionEventHandler(
- IdentityManager identityManager, DeviceManager deviceManager, TripsConfig tripsConfig) {
- return new MotionEventHandler(identityManager, deviceManager, tripsConfig);
- }
-
- @Singleton
- @Provides
- public static GeofenceEventHandler provideGeofenceEventHandler(
- IdentityManager identityManager, GeofenceManager geofenceManager, CalendarManager calendarManager,
- ConnectionManager connectionManager) {
- return new GeofenceEventHandler(identityManager, geofenceManager, calendarManager, connectionManager);
- }
-
- @Singleton
- @Provides
- public static AlertEventHandler provideAlertEventHandler(Config config, IdentityManager identityManager) {
- return new AlertEventHandler(config, identityManager);
- }
-
- @Singleton
- @Provides
- public static IgnitionEventHandler provideIgnitionEventHandler(IdentityManager identityManager) {
- return new IgnitionEventHandler(identityManager);
- }
-
- @Singleton
- @Provides
- public static MaintenanceEventHandler provideMaintenanceEventHandler(
- IdentityManager identityManager, MaintenancesManager maintenancesManager) {
- return new MaintenanceEventHandler(identityManager, maintenancesManager);
- }
-
- @Singleton
- @Provides
- public static DriverEventHandler provideDriverEventHandler(IdentityManager identityManager) {
- return new DriverEventHandler(identityManager);
- }
-
- @Singleton
- @Provides
- public static Timer provideTimer() {
- return GlobalTimer.getTimer();
- }
-
}