Search in sources :

Example 16 with ProtocolCodecFilter

use of org.apache.mina.filter.codec.ProtocolCodecFilter in project zm-mailbox by Zimbra.

the class NioServer method start.

/**
     * Starts the server. Binds the server port and starts the connection
     * handler. Optionally adds an SSLFilter if ssl is enabled.
     *
     * @throws IOException if an I/O error occured while starting the server
     */
@Override
public void start() {
    ServerConfig sc = getConfig();
    DefaultIoFilterChainBuilder fc = acceptor.getFilterChain();
    if (sc.isSslEnabled()) {
        fc.addFirst("ssl", newSSLFilter());
    }
    fc.addLast("executer", executorFilter);
    fc.addLast("logger", new NioLoggingFilter(this, false));
    fc.addLast("codec", new ProtocolCodecFilter(getProtocolCodecFactory()));
    for (IoFilter filter : FILTERS.get(getClass())) {
        // insert custom filters
        fc.addLast(filter.getClass().getName(), filter);
    }
    acceptor.getSessionConfig().setBothIdleTime(sc.getMaxIdleTime());
    acceptor.getSessionConfig().setWriteTimeout(sc.getWriteTimeout());
    acceptor.setHandler(new NioHandlerDispatcher(this));
    try {
        acceptor.bind();
    } catch (Throwable e) {
        Zimbra.halt(getName() + " failed to start", e);
    }
    getLog().info("Starting %s on %s", getName(), acceptor.getLocalAddress());
}
Also used : DefaultIoFilterChainBuilder(org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder) IoFilter(org.apache.mina.core.filterchain.IoFilter) ProtocolCodecFilter(org.apache.mina.filter.codec.ProtocolCodecFilter)

Aggregations

ProtocolCodecFilter (org.apache.mina.filter.codec.ProtocolCodecFilter)16 InetSocketAddress (java.net.InetSocketAddress)7 IOException (java.io.IOException)4 NioSocketAcceptor (org.apache.mina.transport.socket.nio.NioSocketAcceptor)4 TextLineCodecFactory (org.apache.mina.filter.codec.textline.TextLineCodecFactory)3 NamedThreadFactory (com.alibaba.dubbo.common.utils.NamedThreadFactory)2 Charset (java.nio.charset.Charset)2 DnsProtocolHandler (org.apache.directory.server.dns.protocol.DnsProtocolHandler)2 UdpTransport (org.apache.directory.server.protocol.shared.transport.UdpTransport)2 DefaultIoFilterChainBuilder (org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder)2 IoSession (org.apache.mina.core.session.IoSession)2 DatagramSessionConfig (org.apache.mina.transport.socket.DatagramSessionConfig)2 SocketAcceptor (org.apache.mina.transport.socket.nio.SocketAcceptor)2 SocketAcceptorConfig (org.apache.mina.transport.socket.nio.SocketAcceptorConfig)2 MultilineOrientedCodecFactory (org.opennms.netmgt.provision.support.codec.MultilineOrientedCodecFactory)2 ThreadFactory (java.util.concurrent.ThreadFactory)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 JMException (javax.management.JMException)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 DnsException (org.apache.directory.server.dns.DnsException)1