diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2020-12-13 15:51:33 -0800 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2020-12-13 15:51:33 -0800 |
commit | bc3b09e48efb9a58d9aef111d4316dcd9c0a7038 (patch) | |
tree | 18179346c5838bae1fdabb4007f309aa598c7600 /src | |
parent | d4f9561b978ea0410acc7a80a42137e13f06c846 (diff) | |
download | trackermap-server-bc3b09e48efb9a58d9aef111d4316dcd9c0a7038.tar.gz trackermap-server-bc3b09e48efb9a58d9aef111d4316dcd9c0a7038.tar.bz2 trackermap-server-bc3b09e48efb9a58d9aef111d4316dcd9c0a7038.zip |
Improve forwarding logging
Diffstat (limited to 'src')
4 files changed, 30 insertions, 33 deletions
diff --git a/src/main/java/org/traccar/Context.java b/src/main/java/org/traccar/Context.java index af7e03837..2b031cfd3 100644 --- a/src/main/java/org/traccar/Context.java +++ b/src/main/java/org/traccar/Context.java @@ -40,7 +40,6 @@ import org.traccar.database.MaintenancesManager; import org.traccar.database.MediaManager; import org.traccar.database.NotificationManager; import org.traccar.database.PermissionsManager; -import org.traccar.schedule.ScheduleManager; import org.traccar.database.UsersManager; import org.traccar.geocoder.Geocoder; import org.traccar.helper.Log; @@ -57,9 +56,9 @@ import org.traccar.model.Maintenance; import org.traccar.model.Notification; import org.traccar.model.User; import org.traccar.notification.EventForwarder; -import org.traccar.notification.JsonTypeEventForwarder; import org.traccar.notification.NotificatorManager; import org.traccar.reports.model.TripsConfig; +import org.traccar.schedule.ScheduleManager; import org.traccar.sms.SmsManager; import org.traccar.sms.smpp.SmppClient; import org.traccar.web.WebServer; @@ -342,7 +341,7 @@ public final class Context { scheduleManager = new ScheduleManager(); if (config.getBoolean("event.forward.enable")) { - eventForwarder = new JsonTypeEventForwarder(); + eventForwarder = new EventForwarder(); } attributesManager = new AttributesManager(dataManager); diff --git a/src/main/java/org/traccar/WebDataHandler.java b/src/main/java/org/traccar/WebDataHandler.java index a7ea0b2a5..678096d34 100644 --- a/src/main/java/org/traccar/WebDataHandler.java +++ b/src/main/java/org/traccar/WebDataHandler.java @@ -221,6 +221,7 @@ public class WebDataHandler extends BaseDataHandler { } private void send() { + LOGGER.debug("Position forwarding initiated"); if (json) { try { Entity<String> entity = Entity.entity(objectMapper.writeValueAsString(payload), mediaType); @@ -233,7 +234,7 @@ public class WebDataHandler extends BaseDataHandler { } } - private void retry() { + private void retry(Throwable throwable) { boolean scheduled = false; try { if (retryEnabled && deliveryPending.get() <= retryLimit && retries < retryCount) { @@ -242,27 +243,28 @@ public class WebDataHandler extends BaseDataHandler { } } finally { int pending = scheduled ? deliveryPending.get() : deliveryPending.decrementAndGet(); - LOGGER.warn("Position forwarding failed: " + pending + " pending"); + LOGGER.warn("Position forwarding failed: " + pending + " pending", throwable); } } private void schedule() { Main.getInjector().getInstance(Timer.class).newTimeout( - this, retryDelay * (int) Math.pow(2, retries++), TimeUnit.MILLISECONDS); + this, retryDelay * (long) Math.pow(2, retries++), TimeUnit.MILLISECONDS); } @Override public void completed(Response response) { if (response.getStatusInfo().getFamily() == Response.Status.Family.SUCCESSFUL) { deliveryPending.decrementAndGet(); + LOGGER.debug("Position forwarding succeeded"); } else { - retry(); + retry(new RuntimeException("Status code 2xx expected")); } } @Override public void failed(Throwable throwable) { - retry(); + retry(throwable); } @Override diff --git a/src/main/java/org/traccar/notification/EventForwarder.java b/src/main/java/org/traccar/notification/EventForwarder.java index c0010ebbd..966bff31d 100644 --- a/src/main/java/org/traccar/notification/EventForwarder.java +++ b/src/main/java/org/traccar/notification/EventForwarder.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 - 2019 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 2020 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ */ package org.traccar.notification; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.Context; import org.traccar.model.Device; import org.traccar.model.Event; @@ -22,13 +24,16 @@ import org.traccar.model.Geofence; import org.traccar.model.Maintenance; import org.traccar.model.Position; -import javax.ws.rs.client.AsyncInvoker; +import javax.ws.rs.client.Entity; import javax.ws.rs.client.Invocation; +import javax.ws.rs.client.InvocationCallback; import java.util.HashMap; import java.util.Map; import java.util.Set; -public abstract class EventForwarder { +public class EventForwarder { + + private static final Logger LOGGER = LoggerFactory.getLogger(EventForwarder.class); private final String url; private final String header; @@ -56,7 +61,19 @@ public abstract class EventForwarder { } } - executeRequest(event, position, users, requestBuilder.async()); + LOGGER.debug("Event forwarding initiated"); + requestBuilder.async().post( + Entity.json(preparePayload(event, position, users)), new InvocationCallback<Object>() { + @Override + public void completed(Object o) { + LOGGER.debug("Event forwarding succeeded"); + } + + @Override + public void failed(Throwable throwable) { + LOGGER.warn("Event forwarding failed", throwable); + } + }); } protected Map<String, Object> preparePayload(Event event, Position position, Set<Long> users) { @@ -85,7 +102,4 @@ public abstract class EventForwarder { return data; } - protected abstract void executeRequest( - Event event, Position position, Set<Long> users, AsyncInvoker invoker); - } diff --git a/src/main/java/org/traccar/notification/JsonTypeEventForwarder.java b/src/main/java/org/traccar/notification/JsonTypeEventForwarder.java deleted file mode 100644 index 55d926fc8..000000000 --- a/src/main/java/org/traccar/notification/JsonTypeEventForwarder.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.traccar.notification; - -import java.util.Set; - -import org.traccar.model.Event; -import org.traccar.model.Position; - -import javax.ws.rs.client.AsyncInvoker; -import javax.ws.rs.client.Entity; - -public class JsonTypeEventForwarder extends EventForwarder { - - @Override - protected void executeRequest(Event event, Position position, Set<Long> users, AsyncInvoker invoker) { - invoker.post(Entity.json(preparePayload(event, position, users))); - } - -} |