Search in sources :

Example 6 with IoFilter

use of org.apache.mina.core.filterchain.IoFilter in project camel by apache.

the class Mina2Producer method setupSocketProtocol.

protected void setupSocketProtocol(String uri) throws Exception {
    boolean minaLogger = configuration.isMinaLogger();
    long timeout = configuration.getTimeout();
    List<IoFilter> filters = configuration.getFilters();
    address = new InetSocketAddress(configuration.getHost(), configuration.getPort());
    final int processorCount = Runtime.getRuntime().availableProcessors() + 1;
    connector = new NioSocketConnector(processorCount);
    // connector config
    connectorConfig = connector.getSessionConfig();
    if (configuration.isOrderedThreadPoolExecutor()) {
        workerPool = new OrderedThreadPoolExecutor(configuration.getMaximumPoolSize());
    } else {
        workerPool = new UnorderedThreadPoolExecutor(configuration.getMaximumPoolSize());
    }
    connector.getFilterChain().addLast("threadPool", new ExecutorFilter(workerPool));
    if (minaLogger) {
        connector.getFilterChain().addLast("logger", new LoggingFilter());
    }
    appendIoFiltersToChain(filters, connector.getFilterChain());
    if (configuration.getSslContextParameters() != null) {
        SslFilter filter = new SslFilter(configuration.getSslContextParameters().createSSLContext(getEndpoint().getCamelContext()), configuration.isAutoStartTls());
        filter.setUseClientMode(true);
        connector.getFilterChain().addFirst("sslFilter", filter);
    }
    configureCodecFactory("Mina2Producer", connector);
    connector.setConnectTimeoutMillis(timeout);
}
Also used : SslFilter(org.apache.mina.filter.ssl.SslFilter) NioSocketConnector(org.apache.mina.transport.socket.nio.NioSocketConnector) UnorderedThreadPoolExecutor(org.apache.mina.filter.executor.UnorderedThreadPoolExecutor) OrderedThreadPoolExecutor(org.apache.mina.filter.executor.OrderedThreadPoolExecutor) InetSocketAddress(java.net.InetSocketAddress) ExecutorFilter(org.apache.mina.filter.executor.ExecutorFilter) LoggingFilter(org.apache.mina.filter.logging.LoggingFilter) IoFilter(org.apache.mina.core.filterchain.IoFilter)

Example 7 with IoFilter

use of org.apache.mina.core.filterchain.IoFilter in project camel by apache.

the class Mina2Producer method setupVmProtocol.

// Implementation methods
//-------------------------------------------------------------------------
protected void setupVmProtocol(String uri) {
    boolean minaLogger = configuration.isMinaLogger();
    List<IoFilter> filters = configuration.getFilters();
    address = new VmPipeAddress(configuration.getPort());
    connector = new VmPipeConnector();
    // connector config
    if (minaLogger) {
        connector.getFilterChain().addLast("logger", new LoggingFilter());
    }
    appendIoFiltersToChain(filters, connector.getFilterChain());
    if (configuration.getSslContextParameters() != null) {
        LOG.warn("Using vm protocol" + ", but an SSLContextParameters instance was provided.  SSLContextParameters is only supported on the TCP protocol.");
    }
    configureCodecFactory("Mina2Producer", connector);
}
Also used : LoggingFilter(org.apache.mina.filter.logging.LoggingFilter) IoFilter(org.apache.mina.core.filterchain.IoFilter) VmPipeAddress(org.apache.mina.transport.vmpipe.VmPipeAddress) VmPipeConnector(org.apache.mina.transport.vmpipe.VmPipeConnector)

Example 8 with IoFilter

use of org.apache.mina.core.filterchain.IoFilter in project camel by apache.

the class Mina2Producer method setupDatagramProtocol.

protected void setupDatagramProtocol(String uri) {
    boolean minaLogger = configuration.isMinaLogger();
    boolean transferExchange = configuration.isTransferExchange();
    List<IoFilter> filters = configuration.getFilters();
    if (transferExchange) {
        throw new IllegalArgumentException("transferExchange=true is not supported for datagram protocol");
    }
    address = new InetSocketAddress(configuration.getHost(), configuration.getPort());
    final int processorCount = Runtime.getRuntime().availableProcessors() + 1;
    connector = new NioDatagramConnector(processorCount);
    if (configuration.isOrderedThreadPoolExecutor()) {
        workerPool = new OrderedThreadPoolExecutor(configuration.getMaximumPoolSize());
    } else {
        workerPool = new UnorderedThreadPoolExecutor(configuration.getMaximumPoolSize());
    }
    connectorConfig = connector.getSessionConfig();
    connector.getFilterChain().addLast("threadPool", new ExecutorFilter(workerPool));
    if (minaLogger) {
        connector.getFilterChain().addLast("logger", new LoggingFilter());
    }
    appendIoFiltersToChain(filters, connector.getFilterChain());
    if (configuration.getSslContextParameters() != null) {
        LOG.warn("Using datagram protocol, " + configuration.getProtocol() + ", but an SSLContextParameters instance was provided.  SSLContextParameters is only supported on the TCP protocol.");
    }
    configureDataGramCodecFactory("Mina2Producer", connector, configuration);
    // set connect timeout to mina in seconds
    connector.setConnectTimeoutMillis(timeout);
}
Also used : NioDatagramConnector(org.apache.mina.transport.socket.nio.NioDatagramConnector) UnorderedThreadPoolExecutor(org.apache.mina.filter.executor.UnorderedThreadPoolExecutor) OrderedThreadPoolExecutor(org.apache.mina.filter.executor.OrderedThreadPoolExecutor) InetSocketAddress(java.net.InetSocketAddress) ExecutorFilter(org.apache.mina.filter.executor.ExecutorFilter) LoggingFilter(org.apache.mina.filter.logging.LoggingFilter) IoFilter(org.apache.mina.core.filterchain.IoFilter)

Example 9 with IoFilter

use of org.apache.mina.core.filterchain.IoFilter 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

IoFilter (org.apache.mina.core.filterchain.IoFilter)9 LoggingFilter (org.apache.mina.filter.logging.LoggingFilter)7 InetSocketAddress (java.net.InetSocketAddress)5 ExecutorFilter (org.apache.mina.filter.executor.ExecutorFilter)5 OrderedThreadPoolExecutor (org.apache.mina.filter.executor.OrderedThreadPoolExecutor)5 UnorderedThreadPoolExecutor (org.apache.mina.filter.executor.UnorderedThreadPoolExecutor)5 SslFilter (org.apache.mina.filter.ssl.SslFilter)3 NioSocketConnector (org.apache.mina.transport.socket.nio.NioSocketConnector)2 VmPipeAddress (org.apache.mina.transport.vmpipe.VmPipeAddress)2 ArrayList (java.util.ArrayList)1 JndiContext (org.apache.camel.util.jndi.JndiContext)1 DefaultIoFilterChainBuilder (org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder)1 ProtocolCodecFilter (org.apache.mina.filter.codec.ProtocolCodecFilter)1 NioDatagramAcceptor (org.apache.mina.transport.socket.nio.NioDatagramAcceptor)1 NioDatagramConnector (org.apache.mina.transport.socket.nio.NioDatagramConnector)1 NioSocketAcceptor (org.apache.mina.transport.socket.nio.NioSocketAcceptor)1 VmPipeAcceptor (org.apache.mina.transport.vmpipe.VmPipeAcceptor)1 VmPipeConnector (org.apache.mina.transport.vmpipe.VmPipeConnector)1