From eaf1f1eb9c394fbc0dc82d4d2cb04f5d001fbfa4 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 21 Aug 2015 21:06:05 +1200 Subject: Share async http client instance --- src/org/traccar/BasePipelineFactory.java | 5 +---- src/org/traccar/Context.java | 7 +++++++ src/org/traccar/WebDataHandler.java | 4 +--- 3 files changed, 9 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java index 216e48709..0dc0bbb47 100644 --- a/src/org/traccar/BasePipelineFactory.java +++ b/src/org/traccar/BasePipelineFactory.java @@ -34,7 +34,7 @@ import org.traccar.helper.Log; public abstract class BasePipelineFactory implements ChannelPipelineFactory { private final TrackerServer server; - private int resetDelay; + private final int resetDelay; private FilterHandler filterHandler; private DistanceHandler distanceHandler; @@ -54,9 +54,6 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory { } } - /** - * Logging using global logger - */ protected class StandardLoggingHandler extends LoggingHandler { @Override diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java index d50a0c626..f818368d0 100644 --- a/src/org/traccar/Context.java +++ b/src/org/traccar/Context.java @@ -15,6 +15,7 @@ */ package org.traccar; +import com.ning.http.client.AsyncHttpClient; import org.traccar.database.ConnectionManager; import org.traccar.database.DataManager; import org.traccar.database.IdentityManager; @@ -81,6 +82,12 @@ public class Context { public static ServerManager getServerManager() { return serverManager; } + + private static final AsyncHttpClient asyncHttpClient = new AsyncHttpClient(); + + public static AsyncHttpClient getAsyncHttpClient() { + return asyncHttpClient; + } public static void init(String[] arguments) throws Exception { diff --git a/src/org/traccar/WebDataHandler.java b/src/org/traccar/WebDataHandler.java index 5e3626022..e2916d9bc 100644 --- a/src/org/traccar/WebDataHandler.java +++ b/src/org/traccar/WebDataHandler.java @@ -15,7 +15,6 @@ */ package org.traccar; -import com.ning.http.client.AsyncHttpClient; import java.util.Calendar; import java.util.Formatter; import java.util.Locale; @@ -70,8 +69,7 @@ public class WebDataHandler extends BaseDataHandler { replace("{longitude}", String.valueOf(position.getLongitude())). replace("{gprmc}", formatSentence(position)); - AsyncHttpClient asyncHttpClient = new AsyncHttpClient(); - asyncHttpClient.prepareGet(request).execute(); + Context.getAsyncHttpClient().prepareGet(request).execute(); return position; } -- cgit v1.2.3