aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar
diff options
context:
space:
mode:
authorkamaci <furkankamaci@gmail.com>2020-10-19 00:01:12 +0300
committerkamaci <furkankamaci@gmail.com>2020-10-19 00:01:12 +0300
commit3cd7831692b1725713e297372a0181e5ae614eb9 (patch)
tree46725cd3575e53ff9ff40b44236b34a323f804ac /src/main/java/org/traccar
parent98c2e3da5ea0670360078a3f278ddef7d9e39953 (diff)
downloadtraccar-server-3cd7831692b1725713e297372a0181e5ae614eb9.tar.gz
traccar-server-3cd7831692b1725713e297372a0181e5ae614eb9.tar.bz2
traccar-server-3cd7831692b1725713e297372a0181e5ae614eb9.zip
Anonymous types are replaced with lambda.
Diffstat (limited to 'src/main/java/org/traccar')
-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.java63
-rw-r--r--src/main/java/org/traccar/web/CsvBuilder.java31
5 files changed, 54 insertions, 80 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..5e157d0de 100644
--- a/src/main/java/org/traccar/sms/smpp/SmppClient.java
+++ b/src/main/java/org/traccar/sms/smpp/SmppClient.java
@@ -16,19 +16,6 @@
*/
package org.traccar.sms.smpp;
-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;
-import org.slf4j.LoggerFactory;
-import org.traccar.Context;
-import org.traccar.notification.MessageException;
-import org.traccar.sms.SmsManager;
-
import com.cloudhopper.commons.charset.CharsetUtil;
import com.cloudhopper.smpp.SmppBindType;
import com.cloudhopper.smpp.SmppConstants;
@@ -44,6 +31,17 @@ import com.cloudhopper.smpp.type.RecoverablePduException;
import com.cloudhopper.smpp.type.SmppChannelException;
import com.cloudhopper.smpp.type.SmppTimeoutException;
import com.cloudhopper.smpp.type.UnrecoverablePduException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.traccar.Context;
+import org.traccar.notification.MessageException;
+import org.traccar.sms.SmsManager;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
public class SmppClient implements SmsManager {
@@ -122,25 +120,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 +249,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..2efe2adde 100644
--- a/src/main/java/org/traccar/web/CsvBuilder.java
+++ b/src/main/java/org/traccar/web/CsvBuilder.java
@@ -16,23 +16,22 @@
*/
package org.traccar.web;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.traccar.Context;
+import org.traccar.helper.DateUtil;
+
import java.beans.Introspector;
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;
import java.util.TreeSet;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.traccar.Context;
-import org.traccar.helper.DateUtil;
-
public class CsvBuilder {
private static final Logger LOGGER = LoggerFactory.getLogger(CsvBuilder.class);
@@ -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;