aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/TrackerServer.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2013-01-13 18:19:27 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2013-01-13 18:19:27 +1300
commitcf72e8022b9fc27135aea8939e4aa508744dcfbb (patch)
treeaf52fb16731e66f2bbf6432aa348024a36804779 /src/org/traccar/TrackerServer.java
parent36c030fa027402b18e2f77027d407b04a867b4fc (diff)
downloadtrackermap-server-cf72e8022b9fc27135aea8939e4aa508744dcfbb.tar.gz
trackermap-server-cf72e8022b9fc27135aea8939e4aa508744dcfbb.tar.bz2
trackermap-server-cf72e8022b9fc27135aea8939e4aa508744dcfbb.zip
Reduced ServerManager size
Diffstat (limited to 'src/org/traccar/TrackerServer.java')
-rw-r--r--src/org/traccar/TrackerServer.java39
1 files changed, 30 insertions, 9 deletions
diff --git a/src/org/traccar/TrackerServer.java b/src/org/traccar/TrackerServer.java
index c24e6494b..36c0ce70e 100644
--- a/src/org/traccar/TrackerServer.java
+++ b/src/org/traccar/TrackerServer.java
@@ -22,6 +22,7 @@ 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.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.group.ChannelGroup;
import org.jboss.netty.channel.group.ChannelGroupFuture;
@@ -30,17 +31,37 @@ import org.jboss.netty.channel.group.DefaultChannelGroup;
/**
* Tracker server
*/
-public class TrackerServer /*extends ServerBootstrap*/ {
-
- Bootstrap bootstrap;
+public abstract class TrackerServer {
- public TrackerServer(Bootstrap bootstrap) {
+ private ServerManager serverManager;
+ private Bootstrap bootstrap;
+ private String protocol;
+
+ public String getProtocol() {
+ return protocol;
+ }
+
+ public TrackerServer(ServerManager serverManager, Bootstrap bootstrap, String protocol) {
+ this.serverManager = serverManager;
this.bootstrap = bootstrap;
+ this.protocol = protocol;
- // Create channel factory
bootstrap.setFactory(GlobalChannelFactory.getFactory());
+
+ address = serverManager.getProperties().getProperty(protocol + ".address");
+ String portProperty = serverManager.getProperties().getProperty(protocol + ".port");
+ port = (portProperty != null) ? Integer.valueOf(portProperty) : 5000;
+
+ bootstrap.setPipelineFactory(new GenericPipelineFactory(serverManager, this, protocol) {
+ @Override
+ protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ TrackerServer.this.addSpecificHandlers(pipeline);
+ }
+ });
}
+ protected abstract void addSpecificHandlers(ChannelPipeline pipeline);
+
/**
* Server port
*/
@@ -82,11 +103,11 @@ public class TrackerServer /*extends ServerBootstrap*/ {
public ChannelGroup getChannelGroup() {
return allChannels;
}
-
+
public void setPipelineFactory(ChannelPipelineFactory pipelineFactory) {
bootstrap.setPipelineFactory(pipelineFactory);
}
-
+
/**
* Start server
*/
@@ -97,7 +118,7 @@ public class TrackerServer /*extends ServerBootstrap*/ {
} else {
endpoint = new InetSocketAddress(address, port);
}
-
+
Channel channel = null;
if (bootstrap instanceof ServerBootstrap) {
channel = ((ServerBootstrap) bootstrap).bind(endpoint);
@@ -109,7 +130,7 @@ public class TrackerServer /*extends ServerBootstrap*/ {
getChannelGroup().add(channel);
}
}
-
+
/**
* Stop server
*/