aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/TrackerServer.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2012-12-09 12:07:09 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2012-12-09 12:07:09 +1300
commita5514d3497e2cfbcbecdff606af8b30f340c1b32 (patch)
tree07c7303e4ae99d39a94253cfafbd74b4a4bc29c3 /src/org/traccar/TrackerServer.java
parentd0b8756a27562917323fcf7f4476629752814e70 (diff)
downloadtrackermap-server-a5514d3497e2cfbcbecdff606af8b30f340c1b32.tar.gz
trackermap-server-a5514d3497e2cfbcbecdff606af8b30f340c1b32.tar.bz2
trackermap-server-a5514d3497e2cfbcbecdff606af8b30f340c1b32.zip
Added UDP support (fix #6)
Diffstat (limited to 'src/org/traccar/TrackerServer.java')
-rw-r--r--src/org/traccar/TrackerServer.java42
1 files changed, 26 insertions, 16 deletions
diff --git a/src/org/traccar/TrackerServer.java b/src/org/traccar/TrackerServer.java
index 56a9a2946..c24e6494b 100644
--- a/src/org/traccar/TrackerServer.java
+++ b/src/org/traccar/TrackerServer.java
@@ -17,9 +17,12 @@ package org.traccar;
import java.net.InetSocketAddress;
import java.nio.ByteOrder;
+import org.jboss.netty.bootstrap.Bootstrap;
+import org.jboss.netty.bootstrap.ConnectionlessBootstrap;
import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.buffer.HeapChannelBufferFactory;
import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.group.ChannelGroup;
import org.jboss.netty.channel.group.ChannelGroupFuture;
import org.jboss.netty.channel.group.DefaultChannelGroup;
@@ -27,21 +30,15 @@ import org.jboss.netty.channel.group.DefaultChannelGroup;
/**
* Tracker server
*/
-public class TrackerServer extends ServerBootstrap {
+public class TrackerServer /*extends ServerBootstrap*/ {
+
+ Bootstrap bootstrap;
- /**
- * Initialization
- */
- private void init(Integer port) {
-
- setPort(port);
+ public TrackerServer(Bootstrap bootstrap) {
+ this.bootstrap = bootstrap;
// Create channel factory
- setFactory(GlobalChannelFactory.getFactory());
- }
-
- public TrackerServer(Integer port) {
- init(port);
+ bootstrap.setFactory(GlobalChannelFactory.getFactory());
}
/**
@@ -53,7 +50,7 @@ public class TrackerServer extends ServerBootstrap {
return port;
}
- private void setPort(Integer port) {
+ public void setPort(Integer port) {
this.port = port;
}
@@ -74,7 +71,7 @@ public class TrackerServer extends ServerBootstrap {
* Set endianness
*/
void setEndianness(ByteOrder byteOrder) {
- setOption("child.bufferFactory", new HeapChannelBufferFactory(byteOrder));
+ bootstrap.setOption("child.bufferFactory", new HeapChannelBufferFactory(byteOrder));
}
/**
@@ -86,6 +83,10 @@ public class TrackerServer extends ServerBootstrap {
return allChannels;
}
+ public void setPipelineFactory(ChannelPipelineFactory pipelineFactory) {
+ bootstrap.setPipelineFactory(pipelineFactory);
+ }
+
/**
* Start server
*/
@@ -96,8 +97,17 @@ public class TrackerServer extends ServerBootstrap {
} else {
endpoint = new InetSocketAddress(address, port);
}
- Channel channel = bind(endpoint);
- getChannelGroup().add(channel);
+
+ Channel channel = null;
+ if (bootstrap instanceof ServerBootstrap) {
+ channel = ((ServerBootstrap) bootstrap).bind(endpoint);
+ } else if (bootstrap instanceof ConnectionlessBootstrap) {
+ channel = ((ConnectionlessBootstrap) bootstrap).bind(endpoint);
+ }
+
+ if (channel != null) {
+ getChannelGroup().add(channel);
+ }
}
/**