in core/src/main/java/org/apache/ftpserver/listener/nio/NioListener.java [95:177]
public synchronized void start(FtpServerContext context) {
if (!isStopped()) {
// listener already started, don't allow
throw new IllegalStateException("Listener already started");
}
try {
this.context = context;
acceptor = new NioSocketAcceptor(Runtime.getRuntime().availableProcessors());
if (getServerAddress() != null) {
address = new InetSocketAddress(getServerAddress(), getPort());
} else {
address = new InetSocketAddress(getPort());
}
acceptor.setReuseAddress(true);
acceptor.getSessionConfig().setReadBufferSize(2048);
acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, getIdleTimeout());
// Decrease the default receiver buffer size
acceptor.getSessionConfig().setReceiveBufferSize(512);
MdcInjectionFilter mdcFilter = new MdcInjectionFilter();
acceptor.getFilterChain().addLast("mdcFilter", mdcFilter);
SessionFilter sessionFilter = getSessionFilter();
if (sessionFilter != null) {
// add and IP filter to the filter chain.
acceptor.getFilterChain().addLast("sessionFilter", new MinaSessionFilter(sessionFilter));
}
acceptor.getFilterChain().addLast("threadPool", new ExecutorFilter(context.getThreadPoolExecutor()));
acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new FtpServerProtocolCodecFactory()));
acceptor.getFilterChain().addLast("mdcFilter2", mdcFilter);
acceptor.getFilterChain().addLast("logger", new FtpLoggingFilter());
if (isImplicitSsl()) {
SslConfiguration ssl_conf = getSslConfiguration();
SslFilter ssl_filter;
try {
ssl_filter = new SslFilter(ssl_conf.getSSLContext());
} catch (GeneralSecurityException e) {
throw new FtpServerConfigurationException("SSL could not be initialized, check configuration");
}
if (ssl_conf.getClientAuth() == ClientAuth.NEED) {
ssl_filter.setNeedClientAuth(true);
} else if (ssl_conf.getClientAuth() == ClientAuth.WANT) {
ssl_filter.setWantClientAuth(true);
}
if (ssl_conf.getEnabledProtocols() != null) {
ssl_filter.setEnabledProtocols(ssl_conf.getEnabledProtocols());
}
if (ssl_conf.getEnabledCipherSuites() != null) {
ssl_filter.setEnabledCipherSuites(ssl_conf.getEnabledCipherSuites());
}
acceptor.getFilterChain().addFirst("sslFilter", ssl_filter);
}
handler.init(context, this);
acceptor.setHandler(new FtpHandlerAdapter(context, handler));
try {
acceptor.bind(address);
} catch (IOException e) {
throw new FtpServerConfigurationException("Failed to bind to address " + address + ", check configuration", e);
}
updatePort();
} catch (RuntimeException e) {
// clean up if we fail to start
stop();
throw e;
}
}