diff options
-rw-r--r-- | src/org/traccar/GlobalChannelFactory.java | 35 | ||||
-rw-r--r-- | src/org/traccar/TrackerServer.java | 7 |
2 files changed, 28 insertions, 14 deletions
diff --git a/src/org/traccar/GlobalChannelFactory.java b/src/org/traccar/GlobalChannelFactory.java index 489207e39..7d2f3cbb6 100644 --- a/src/org/traccar/GlobalChannelFactory.java +++ b/src/org/traccar/GlobalChannelFactory.java @@ -17,29 +17,38 @@ package org.traccar; import java.util.concurrent.Executors; import org.jboss.netty.channel.ChannelFactory; +import org.jboss.netty.channel.socket.DatagramChannelFactory; +import org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory; import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; -/** - * Channel factory - */ public class GlobalChannelFactory { - private static ChannelFactory instance = null; + private static ChannelFactory channelFactory = null; + private static DatagramChannelFactory datagramChannelFactory = null; - private GlobalChannelFactory() { - } - public static void release() { - if (instance != null) { - instance.releaseExternalResources(); + if (channelFactory != null) { + channelFactory.releaseExternalResources(); + } + if (datagramChannelFactory != null) { + datagramChannelFactory.releaseExternalResources(); } - instance = null; + channelFactory = null; + datagramChannelFactory = null; } public static ChannelFactory getFactory() { - if(instance == null) { - instance = new NioServerSocketChannelFactory(); + if (channelFactory == null) { + channelFactory = new NioServerSocketChannelFactory(); } - return instance; + return channelFactory; } + + public static DatagramChannelFactory getDatagramFactory() { + if (datagramChannelFactory == null) { + datagramChannelFactory = new NioDatagramChannelFactory(); + } + return datagramChannelFactory; + } + } diff --git a/src/org/traccar/TrackerServer.java b/src/org/traccar/TrackerServer.java index 1d7185fe6..1b3677836 100644 --- a/src/org/traccar/TrackerServer.java +++ b/src/org/traccar/TrackerServer.java @@ -46,7 +46,12 @@ public abstract class TrackerServer { this.bootstrap = bootstrap; this.protocol = protocol; - bootstrap.setFactory(GlobalChannelFactory.getFactory()); + // Set appropriate channel factory + if (bootstrap instanceof ServerBootstrap) { + bootstrap.setFactory(GlobalChannelFactory.getFactory()); + } else if (bootstrap instanceof ConnectionlessBootstrap) { + bootstrap.setFactory(GlobalChannelFactory.getDatagramFactory()); + } address = serverManager.getProperties().getProperty(protocol + ".address"); String portProperty = serverManager.getProperties().getProperty(protocol + ".port"); |