diff options
Diffstat (limited to 'src/org/traccar/TrackerServer.java')
-rw-r--r-- | src/org/traccar/TrackerServer.java | 125 |
1 files changed, 55 insertions, 70 deletions
diff --git a/src/org/traccar/TrackerServer.java b/src/org/traccar/TrackerServer.java index f4830d778..da889d0a3 100644 --- a/src/org/traccar/TrackerServer.java +++ b/src/org/traccar/TrackerServer.java @@ -16,7 +16,6 @@ package org.traccar; import java.net.InetSocketAddress; -import java.util.Iterator; import java.util.concurrent.Executors; import org.jboss.netty.bootstrap.ServerBootstrap; import org.jboss.netty.channel.Channel; @@ -30,74 +29,60 @@ import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; */ public class TrackerServer extends ServerBootstrap { - /** - * Initialization - */ - private void init(Integer port, Integer threadPoolSize) { - - setPort(port); - - // Create channel factory - setFactory(new NioServerSocketChannelFactory( - Executors.newCachedThreadPool(), - Executors.newCachedThreadPool())); - } - - public TrackerServer(Integer port) { - init(port, 1); - } - - /** - * Server port - */ - private Integer port; - - public Integer getPort() { - return port; - } - - private void setPort(Integer newPort) { - port = newPort; - } - - /** - * Opened channels - */ - private ChannelGroup allChannels = new DefaultChannelGroup(); - - public ChannelGroup getChannelGroup() { - return allChannels; - } - - public void mandaMSG() { - - /* for (Iterator it = this.getChannelGroup().iterator(); it.hasNext();) { - Channel chanel = (Channel) it.next(); - System.out.println(chanel.getRemoteAddress()); - if(chanel.getRemoteAddress() !=null) - this.getChannelGroup().write("OI AMIGO", chanel.getRemoteAddress()); - - } -*/ - // System.out.println(type.getPort()); - - } - - /** - * Start server - */ - public void start() { - Channel channel = bind(new InetSocketAddress(getPort())); - getChannelGroup().add(channel); - } - - /** - * Stop server - */ - public void stop() { - ChannelGroupFuture future = getChannelGroup().close(); - future.awaitUninterruptibly(); - getFactory().releaseExternalResources(); - } + /** + * Initialization + */ + private void init(Integer port, Integer threadPoolSize) { + + setPort(port); + + // Create channel factory + setFactory(new NioServerSocketChannelFactory( + Executors.newCachedThreadPool(), + Executors.newCachedThreadPool())); + } + + public TrackerServer(Integer port) { + init(port, 1); + } + + /** + * Server port + */ + private Integer port; + + public Integer getPort() { + return port; + } + + private void setPort(Integer newPort) { + port = newPort; + } + + /** + * Opened channels + */ + private ChannelGroup allChannels = new DefaultChannelGroup(); + + public ChannelGroup getChannelGroup() { + return allChannels; + } + + /** + * Start server + */ + public void start() { + Channel channel = bind(new InetSocketAddress(getPort())); + getChannelGroup().add(channel); + } + + /** + * Stop server + */ + public void stop() { + ChannelGroupFuture future = getChannelGroup().close(); + future.awaitUninterruptibly(); + getFactory().releaseExternalResources(); + } } |