Search in sources :

Example 6 with ProtocolCodecFilter

use of org.apache.mina.filter.codec.ProtocolCodecFilter in project dubbo by alibaba.

the class MinaServer method doOpen.

@Override
protected void doOpen() throws Throwable {
    // set thread pool.
    acceptor = new SocketAcceptor(getUrl().getPositiveParameter(Constants.IO_THREADS_KEY, Constants.DEFAULT_IO_THREADS), Executors.newCachedThreadPool(new NamedThreadFactory("MinaServerWorker", true)));
    // config
    SocketAcceptorConfig cfg = (SocketAcceptorConfig) acceptor.getDefaultConfig();
    cfg.setThreadModel(ThreadModel.MANUAL);
    // set codec.
    acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MinaCodecAdapter(getCodec(), getUrl(), this)));
    acceptor.bind(getBindAddress(), new MinaHandler(getUrl(), this));
}
Also used : NamedThreadFactory(com.alibaba.dubbo.common.utils.NamedThreadFactory) SocketAcceptorConfig(org.apache.mina.transport.socket.nio.SocketAcceptorConfig) SocketAcceptor(org.apache.mina.transport.socket.nio.SocketAcceptor) ProtocolCodecFilter(org.apache.mina.filter.codec.ProtocolCodecFilter)

Example 7 with ProtocolCodecFilter

use of org.apache.mina.filter.codec.ProtocolCodecFilter in project opennms by OpenNMS.

the class FtpDetector method onInit.

/**
 * <p>onInit</p>
 */
@Override
protected void onInit() {
    // setup the correct codec for this Detector
    setProtocolCodecFilter(new ProtocolCodecFilter(new MultilineOrientedCodecFactory(StandardCharsets.UTF_8, getMultilineIndicator())));
    expectBanner(expectCodeRange(100, 600));
    send(request("quit"), expectCodeRange(100, 600));
}
Also used : MultilineOrientedCodecFactory(org.opennms.netmgt.provision.support.codec.MultilineOrientedCodecFactory) ProtocolCodecFilter(org.apache.mina.filter.codec.ProtocolCodecFilter)

Example 8 with ProtocolCodecFilter

use of org.apache.mina.filter.codec.ProtocolCodecFilter in project camel by apache.

the class Mina2ReverserServer method start.

public void start() throws Exception {
    acceptor = new NioSocketAcceptor();
    // Prepare the configuration
    ((NioSocketAcceptor) acceptor).setReuseAddress(true);
    Charset charset = Charset.forName("UTF-8");
    acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(charset)));
    acceptor.setHandler(new Mina2ReverseProtocolHandler());
    // Bind
    acceptor.bind(new InetSocketAddress(port));
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Charset(java.nio.charset.Charset) ProtocolCodecFilter(org.apache.mina.filter.codec.ProtocolCodecFilter) NioSocketAcceptor(org.apache.mina.transport.socket.nio.NioSocketAcceptor) TextLineCodecFactory(org.apache.mina.filter.codec.textline.TextLineCodecFactory)

Example 9 with ProtocolCodecFilter

use of org.apache.mina.filter.codec.ProtocolCodecFilter in project camel by apache.

the class ReverserServer method start.

public void start() throws Exception {
    acceptor = new SocketAcceptor();
    // Prepare the configuration
    SocketAcceptorConfig cfg = new SocketAcceptorConfig();
    cfg.setReuseAddress(true);
    Charset charset = Charset.forName("UTF-8");
    cfg.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(charset)));
    // Bind
    acceptor.bind(new InetSocketAddress(port), new ReverseProtocolHandler(), cfg);
}
Also used : SocketAcceptorConfig(org.apache.mina.transport.socket.nio.SocketAcceptorConfig) InetSocketAddress(java.net.InetSocketAddress) SocketAcceptor(org.apache.mina.transport.socket.nio.SocketAcceptor) Charset(java.nio.charset.Charset) ProtocolCodecFilter(org.apache.mina.filter.codec.ProtocolCodecFilter) TextLineCodecFactory(org.apache.mina.filter.codec.textline.TextLineCodecFactory)

Example 10 with ProtocolCodecFilter

use of org.apache.mina.filter.codec.ProtocolCodecFilter in project dubbo by alibaba.

the class MinaClient method doOpen.

@Override
protected void doOpen() throws Throwable {
    connectorKey = getUrl().toFullString();
    SocketConnector c = connectors.get(connectorKey);
    if (c != null) {
        connector = c;
    } else {
        // set thread pool.
        connector = new SocketConnector(Constants.DEFAULT_IO_THREADS, Executors.newCachedThreadPool(new NamedThreadFactory("MinaClientWorker", true)));
        // config
        SocketConnectorConfig cfg = (SocketConnectorConfig) connector.getDefaultConfig();
        cfg.setThreadModel(ThreadModel.MANUAL);
        cfg.getSessionConfig().setTcpNoDelay(true);
        cfg.getSessionConfig().setKeepAlive(true);
        int timeout = getTimeout();
        cfg.setConnectTimeout(timeout < 1000 ? 1 : timeout / 1000);
        // set codec.
        connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MinaCodecAdapter(getCodec(), getUrl(), this)));
        connectors.put(connectorKey, connector);
    }
}
Also used : NamedThreadFactory(com.alibaba.dubbo.common.utils.NamedThreadFactory) SocketConnectorConfig(org.apache.mina.transport.socket.nio.SocketConnectorConfig) ProtocolCodecFilter(org.apache.mina.filter.codec.ProtocolCodecFilter) SocketConnector(org.apache.mina.transport.socket.nio.SocketConnector)

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