aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2020-10-18 14:32:51 -0700
committerGitHub <noreply@github.com>2020-10-18 14:32:51 -0700
commit0d5dd20257ab5a4c77ff628b67e6d54931d8ae16 (patch)
tree9c5be8d286ef0f2244329d60385e9e8f1fef6fbd /src
parenta9f5599a1ae18279339a7ff17058d40b9ed4fab4 (diff)
parent3ad889413e4b13d2dd6a2aa6454964dd9427fb28 (diff)
downloadtrackermap-server-0d5dd20257ab5a4c77ff628b67e6d54931d8ae16.tar.gz
trackermap-server-0d5dd20257ab5a4c77ff628b67e6d54931d8ae16.tar.bz2
trackermap-server-0d5dd20257ab5a4c77ff628b67e6d54931d8ae16.zip
Merge pull request #4584 from kamaci/master
Anonymous types are replaced with lambda
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/api/AsyncSocketServlet.java18
-rw-r--r--src/main/java/org/traccar/database/ConnectionManager.java10
-rw-r--r--src/main/java/org/traccar/notificators/Notificator.java12
-rw-r--r--src/main/java/org/traccar/sms/smpp/SmppClient.java40
-rw-r--r--src/main/java/org/traccar/web/CsvBuilder.java19
-rw-r--r--src/test/java/org/traccar/protocol/TeltonikaProtocolDecoderTest.java7
-rw-r--r--src/test/java/org/traccar/protocol/UlbotechFrameDecoderTest.java2
-rw-r--r--src/test/java/org/traccar/web/WebServerTest.java9
8 files changed, 41 insertions, 76 deletions
diff --git a/src/main/java/org/traccar/api/AsyncSocketServlet.java b/src/main/java/org/traccar/api/AsyncSocketServlet.java
index 9318b6fc6..51fbfb478 100644
--- a/src/main/java/org/traccar/api/AsyncSocketServlet.java
+++ b/src/main/java/org/traccar/api/AsyncSocketServlet.java
@@ -15,9 +15,6 @@
*/
package org.traccar.api;
-import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
-import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
-import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
import org.traccar.Context;
@@ -30,15 +27,12 @@ public class AsyncSocketServlet extends WebSocketServlet {
@Override
public void configure(WebSocketServletFactory factory) {
factory.getPolicy().setIdleTimeout(Context.getConfig().getLong("web.timeout", ASYNC_TIMEOUT));
- factory.setCreator(new WebSocketCreator() {
- @Override
- public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp) {
- if (req.getSession() != null) {
- long userId = (Long) req.getSession().getAttribute(SessionResource.USER_ID_KEY);
- return new AsyncSocket(userId);
- } else {
- return null;
- }
+ factory.setCreator((req, resp) -> {
+ if (req.getSession() != null) {
+ long userId = (Long) req.getSession().getAttribute(SessionResource.USER_ID_KEY);
+ return new AsyncSocket(userId);
+ } else {
+ return null;
}
});
}
diff --git a/src/main/java/org/traccar/database/ConnectionManager.java b/src/main/java/org/traccar/database/ConnectionManager.java
index 4d43bc71b..9342fd3de 100644
--- a/src/main/java/org/traccar/database/ConnectionManager.java
+++ b/src/main/java/org/traccar/database/ConnectionManager.java
@@ -17,7 +17,6 @@ package org.traccar.database;
import io.netty.channel.Channel;
import io.netty.util.Timeout;
-import io.netty.util.TimerTask;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.traccar.Context;
@@ -122,12 +121,9 @@ public class ConnectionManager {
}
if (status.equals(Device.STATUS_ONLINE)) {
- timeouts.put(deviceId, GlobalTimer.getTimer().newTimeout(new TimerTask() {
- @Override
- public void run(Timeout timeout) {
- if (!timeout.isCancelled()) {
- updateDevice(deviceId, Device.STATUS_UNKNOWN, null);
- }
+ timeouts.put(deviceId, GlobalTimer.getTimer().newTimeout(timeout1 -> {
+ if (!timeout1.isCancelled()) {
+ updateDevice(deviceId, Device.STATUS_UNKNOWN, null);
}
}, deviceTimeout, TimeUnit.MILLISECONDS));
}
diff --git a/src/main/java/org/traccar/notificators/Notificator.java b/src/main/java/org/traccar/notificators/Notificator.java
index 5e40971c6..dd888bae9 100644
--- a/src/main/java/org/traccar/notificators/Notificator.java
+++ b/src/main/java/org/traccar/notificators/Notificator.java
@@ -27,13 +27,11 @@ public abstract class Notificator {
private static final Logger LOGGER = LoggerFactory.getLogger(Notificator.class);
public void sendAsync(final long userId, final Event event, final Position position) {
- new Thread(new Runnable() {
- public void run() {
- try {
- sendSync(userId, event, position);
- } catch (MessageException | InterruptedException error) {
- LOGGER.warn("Event send error", error);
- }
+ new Thread(() -> {
+ try {
+ sendSync(userId, event, position);
+ } catch (MessageException | InterruptedException error) {
+ LOGGER.warn("Event send error", error);
}
}).start();
}
diff --git a/src/main/java/org/traccar/sms/smpp/SmppClient.java b/src/main/java/org/traccar/sms/smpp/SmppClient.java
index 874253d36..6eb850b6a 100644
--- a/src/main/java/org/traccar/sms/smpp/SmppClient.java
+++ b/src/main/java/org/traccar/sms/smpp/SmppClient.java
@@ -20,7 +20,6 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
-import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
@@ -122,25 +121,19 @@ public class SmppClient implements SmsManager {
enquireLinkPeriod = Context.getConfig().getInteger("sms.smpp.enquireLinkPeriod", 60000);
enquireLinkTimeout = Context.getConfig().getInteger("sms.smpp.enquireLinkTimeout", 10000);
- enquireLinkExecutor = Executors.newScheduledThreadPool(1, new ThreadFactory() {
- @Override
- public Thread newThread(Runnable runnable) {
- Thread thread = new Thread(runnable);
- String name = sessionConfig.getName();
- thread.setName("EnquireLink-" + name);
- return thread;
- }
+ enquireLinkExecutor = Executors.newScheduledThreadPool(1, runnable -> {
+ Thread thread = new Thread(runnable);
+ String name = sessionConfig.getName();
+ thread.setName("EnquireLink-" + name);
+ return thread;
});
reconnectionDelay = Context.getConfig().getInteger("sms.smpp.reconnectionDelay", 10000);
- reconnectionExecutor = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
- @Override
- public Thread newThread(Runnable runnable) {
- Thread thread = new Thread(runnable);
- String name = sessionConfig.getName();
- thread.setName("Reconnection-" + name);
- return thread;
- }
+ reconnectionExecutor = Executors.newSingleThreadScheduledExecutor(runnable -> {
+ Thread thread = new Thread(runnable);
+ String name = sessionConfig.getName();
+ thread.setName("Reconnection-" + name);
+ return thread;
});
scheduleReconnect();
@@ -257,14 +250,11 @@ public class SmppClient implements SmsManager {
@Override
public void sendMessageAsync(final String destAddress, final String message, final boolean command) {
- executorService.execute(new Runnable() {
- @Override
- public void run() {
- try {
- sendMessageSync(destAddress, message, command);
- } catch (MessageException | InterruptedException | IllegalStateException error) {
- LOGGER.warn("SMS sending error", error);
- }
+ executorService.execute(() -> {
+ try {
+ sendMessageSync(destAddress, message, command);
+ } catch (MessageException | InterruptedException | IllegalStateException error) {
+ LOGGER.warn("SMS sending error", error);
}
});
}
diff --git a/src/main/java/org/traccar/web/CsvBuilder.java b/src/main/java/org/traccar/web/CsvBuilder.java
index 3fe7e408f..b962be072 100644
--- a/src/main/java/org/traccar/web/CsvBuilder.java
+++ b/src/main/java/org/traccar/web/CsvBuilder.java
@@ -21,7 +21,6 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Comparator;
import java.util.Date;
import java.util.Map;
import java.util.SortedSet;
@@ -45,23 +44,21 @@ public class CsvBuilder {
private void addLineEnding() {
builder.append(LINE_ENDING);
}
+
private void addSeparator() {
builder.append(SEPARATOR);
}
private SortedSet<Method> getSortedMethods(Object object) {
Method[] methodArray = object.getClass().getMethods();
- SortedSet<Method> methods = new TreeSet<>(new Comparator<Method>() {
- @Override
- public int compare(Method m1, Method m2) {
- if (m1.getName().equals("getAttributes") && !m1.getName().equals(m2.getName())) {
- return 1;
- }
- if (m2.getName().equals("getAttributes") && !m1.getName().equals(m2.getName())) {
- return -1;
- }
- return m1.getName().compareTo(m2.getName());
+ SortedSet<Method> methods = new TreeSet<>((m1, m2) -> {
+ if (m1.getName().equals("getAttributes") && !m1.getName().equals(m2.getName())) {
+ return 1;
+ }
+ if (m2.getName().equals("getAttributes") && !m1.getName().equals(m2.getName())) {
+ return -1;
}
+ return m1.getName().compareTo(m2.getName());
});
methods.addAll(Arrays.asList(methodArray));
return methods;
diff --git a/src/test/java/org/traccar/protocol/TeltonikaProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/TeltonikaProtocolDecoderTest.java
index 62c7f39f8..2f43733c4 100644
--- a/src/test/java/org/traccar/protocol/TeltonikaProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/TeltonikaProtocolDecoderTest.java
@@ -3,7 +3,6 @@ package org.traccar.protocol;
import org.junit.Ignore;
import org.junit.Test;
import org.traccar.ProtocolTest;
-import org.traccar.model.Position;
public class TeltonikaProtocolDecoderTest extends ProtocolTest {
@@ -74,16 +73,16 @@ public class TeltonikaProtocolDecoderTest extends ProtocolTest {
verifyPositions(decoder, binary(
"000000000000003508010000014f8e016420002141bbaf0f4e96a7fffa0000120000000602010047030242669c92000002c7000000009100000000000100002df3"));
-
+
verifyPositions(decoder, binary(
"00000000000000A7080400000113fc208dff000f14f650209cca80006f00d60400040004030101150316030001460000015d0000000113fc17610b000f14ffe0209cc580006e00c00500010004030101150316010001460000015e0000000113fc284945000f150f00209cd200009501080400000004030101150016030001460000015d0000000113fc267c5b000f150a50209cccc0009300680400000004030101150016030001460000015b00040000"));
-
+
verifyPositions(decoder, binary(
"000000000000014708060000013e5a60a4cb003fa7b780fc424518004200000a000000090501010200b300b400f000034268a746011818000001c700000000000000013e5dc8ba28003fa7c080fc4246040001000005000000090501010200b300b400f001034268b44600ef18000001c700000000000000013e5dc90455003fa7b640fc424388003a0000070000f0090501010200b300b400f000034268dc4600f718000001c70000001d000000013e5dc9d368003fa7b800fc4244300049000004000000090501010200b300b400f001034267de46010718000001c700000000000000013e5dca311d003fa7b680fc4243cc00420000070000f0090501010200b300b400f0000342685346010b18000001c700000000000000013e5dcfafe9003fa7b600fc4242f0003d000008000000090501010200b300b400f0000342685246011918000001c700000000000600000275"));
verifyPositions(decoder, binary(
"000000000000002c08010000013eff8d6f9800173295002111f400008100ae0b0000000401010003090016432980422f7200000100007a5d"));
-
+
verifyPositions(decoder, binary(
"00000000000000c7070441bf9db00fff425adbd741ca6e1e009e1205070001030b160000601a02015e02000314006615000a160067010500000ce441bf9d920fff425adbb141ca6fc900a2b218070001030b160000601a02015e02000314006615000a160067010500000cc641bf9d740fff425adbee41ca739200b6c91e070001030b1f0000601a02015f02000314006615000a160066010500000ca841bf9cfc0fff425adba041ca70c100b93813070001030b1f0000601a02015f02000314002315000a160025010500000c3004000000"));
diff --git a/src/test/java/org/traccar/protocol/UlbotechFrameDecoderTest.java b/src/test/java/org/traccar/protocol/UlbotechFrameDecoderTest.java
index 01d63bfa3..31e748f27 100644
--- a/src/test/java/org/traccar/protocol/UlbotechFrameDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/UlbotechFrameDecoderTest.java
@@ -3,8 +3,6 @@ package org.traccar.protocol;
import org.junit.Test;
import org.traccar.ProtocolTest;
-import static org.junit.Assert.assertEquals;
-
public class UlbotechFrameDecoderTest extends ProtocolTest {
@Test
diff --git a/src/test/java/org/traccar/web/WebServerTest.java b/src/test/java/org/traccar/web/WebServerTest.java
index 5a79fbac2..ba4124e44 100644
--- a/src/test/java/org/traccar/web/WebServerTest.java
+++ b/src/test/java/org/traccar/web/WebServerTest.java
@@ -6,8 +6,6 @@ import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
public class WebServerTest {
@@ -15,12 +13,7 @@ public class WebServerTest {
@Test
public void contextTest() throws NamingException {
DataSource mockDataSource = (DataSource) Proxy.newProxyInstance(getClass().getClassLoader(),
- new Class[] { DataSource.class }, new InvocationHandler() {
- @Override
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
- return null;
- }
- });
+ new Class[]{DataSource.class}, (proxy, method, args) -> null);
Context context = new InitialContext();
context.bind("java:/DefaultDS", mockDataSource);