Author: norman Date: Mon Mar 28 11:48:33 2011 New Revision: 1086197 URL: http://svn.apache.org/viewvc?rev=1086197&view=rev Log: Allow to bind to more then one socketaddress. Part of JAMES-1214
Modified: james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/AbstractAsyncServer.java james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/SMTPServerMBean.java Modified: james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/AbstractAsyncServer.java URL: http://svn.apache.org/viewvc/james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/AbstractAsyncServer.java?rev=1086197&r1=1086196&r2=1086197&view=diff ============================================================================== --- james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/AbstractAsyncServer.java (original) +++ james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/AbstractAsyncServer.java Mon Mar 28 11:48:33 2011 @@ -19,11 +19,13 @@ package org.apache.james.protocols.impl; import java.net.InetSocketAddress; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import java.util.concurrent.Executor; import java.util.concurrent.Executors; import org.jboss.netty.bootstrap.ServerBootstrap; -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.DefaultChannelGroup; @@ -39,39 +41,20 @@ public abstract class AbstractAsyncServe public static final int DEFAULT_IO_WORKER_COUNT = Runtime.getRuntime().availableProcessors() * 2; private int backlog = 250; - private int port; - private int timeout = 120; private ServerBootstrap bootstrap; private boolean started; - - private String ip; private ChannelGroup channels = new DefaultChannelGroup(); private int ioWorker = DEFAULT_IO_WORKER_COUNT; - /** - * Set the ip on which the Server should listen on - * - * @param ip - */ - public synchronized void setIP(String ip) { - if (started) throw new IllegalStateException("Can only be set when the server is not running"); - this.ip = ip; - } - + private List<InetSocketAddress> addresses = new ArrayList<InetSocketAddress>(); - /** - * Set the port on which the Server should listen on - * - * @param ip - */ - public synchronized void setPort(int port) { - if (started) throw new IllegalStateException("Can only be set when the server is not running"); - this.port = port; + public synchronized void setListenAddresses(List<InetSocketAddress> addresses) { + this.addresses = Collections.unmodifiableList(addresses); } /** @@ -102,7 +85,7 @@ public abstract class AbstractAsyncServe public synchronized void bind() throws Exception { if (started) throw new IllegalStateException("Server running already"); - if (port < 1) throw new RuntimeException("Please specify a port to which the server should get bound!"); + if (addresses.isEmpty()) throw new RuntimeException("Please specify at least on socketaddress to which the server should get bound!"); bootstrap = new ServerBootstrap(createSocketChannelFactory()); ChannelPipelineFactory factory = createPipelineFactory(channels); @@ -110,14 +93,10 @@ public abstract class AbstractAsyncServe // Configure the pipeline factory. bootstrap.setPipelineFactory(factory); configureBootstrap(bootstrap); - Channel serverChannel; - if (getIP() == null) { - serverChannel = bootstrap.bind(new InetSocketAddress(port)); - } else { - serverChannel = bootstrap.bind(new InetSocketAddress(ip, port)); + + for (int i = 0; i < addresses.size();i++) { + channels.add(bootstrap.bind(addresses.get(i))); } - - channels.add(serverChannel); started = true; } @@ -155,20 +134,10 @@ public abstract class AbstractAsyncServe * * @return ip */ - public synchronized String getIP() { - return ip; + public synchronized List<InetSocketAddress> getListenAddresses() { + return addresses; } - /** - * Return the port this server will listen on - * - * @return port - */ - public synchronized int getPort() { - return port; - } - - /** * Create ChannelPipelineFactory to use by this Server implementation Modified: james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/SMTPServerMBean.java URL: http://svn.apache.org/viewvc/james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/SMTPServerMBean.java?rev=1086197&r1=1086196&r2=1086197&view=diff ============================================================================== --- james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/SMTPServerMBean.java (original) +++ james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/SMTPServerMBean.java Mon Mar 28 11:48:33 2011 @@ -32,20 +32,6 @@ public interface SMTPServerMBean { * @return boolean The enabled flag */ boolean isEnabled(); - - /** - * Returns the port that the service is bound to - * - * @return int The port number - */ - int getPort(); - - /** - * Returns the address if the network interface the socket is bound to - * - * @return String The network interface name - */ - String getNetworkInterface(); /** * Returns the server socket type, plain or SSL --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org