Search in sources :

Example 6 with ExecutorFilter

use of org.apache.mina.filter.executor.ExecutorFilter in project camel by apache.

the class MinaComponent method createSocketEndpoint.

protected MinaEndpoint createSocketEndpoint(String uri, MinaConfiguration configuration) {
    boolean minaLogger = configuration.isMinaLogger();
    long timeout = configuration.getTimeout();
    boolean sync = configuration.isSync();
    List<IoFilter> filters = configuration.getFilters();
    final int processorCount = Runtime.getRuntime().availableProcessors() + 1;
    ExecutorService acceptorPool = getCamelContext().getExecutorServiceManager().newCachedThreadPool(this, "MinaSocketAcceptor");
    ExecutorService connectorPool = getCamelContext().getExecutorServiceManager().newCachedThreadPool(this, "MinaSocketConnector");
    ExecutorService workerPool = getCamelContext().getExecutorServiceManager().newCachedThreadPool(this, "MinaThreadPool");
    IoAcceptor acceptor = new SocketAcceptor(processorCount, acceptorPool);
    IoConnector connector = new SocketConnector(processorCount, connectorPool);
    SocketAddress address = new InetSocketAddress(configuration.getHost(), configuration.getPort());
    // connector config
    SocketConnectorConfig connectorConfig = new SocketConnectorConfig();
    // must use manual thread model according to Mina documentation
    connectorConfig.setThreadModel(ThreadModel.MANUAL);
    configureCodecFactory("MinaProducer", connectorConfig, configuration);
    connectorConfig.getFilterChain().addLast("threadPool", new ExecutorFilter(workerPool));
    if (minaLogger) {
        connectorConfig.getFilterChain().addLast("logger", new LoggingFilter());
    }
    appendIoFiltersToChain(filters, connectorConfig.getFilterChain());
    // set connect timeout to mina in seconds
    connectorConfig.setConnectTimeout((int) (timeout / 1000));
    // acceptor connectorConfig
    SocketAcceptorConfig acceptorConfig = new SocketAcceptorConfig();
    // must use manual thread model according to Mina documentation
    acceptorConfig.setThreadModel(ThreadModel.MANUAL);
    configureCodecFactory("MinaConsumer", acceptorConfig, configuration);
    acceptorConfig.setReuseAddress(true);
    acceptorConfig.setDisconnectOnUnbind(true);
    acceptorConfig.getFilterChain().addLast("threadPool", new ExecutorFilter(workerPool));
    if (minaLogger) {
        acceptorConfig.getFilterChain().addLast("logger", new LoggingFilter());
    }
    appendIoFiltersToChain(filters, acceptorConfig.getFilterChain());
    MinaEndpoint endpoint = new MinaEndpoint(uri, this);
    endpoint.setAddress(address);
    endpoint.setAcceptor(acceptor);
    endpoint.setAcceptorConfig(acceptorConfig);
    endpoint.setConnector(connector);
    endpoint.setConnectorConfig(connectorConfig);
    endpoint.setConfiguration(configuration);
    // enlist threads pools in use on endpoint
    endpoint.addThreadPool(acceptorPool);
    endpoint.addThreadPool(connectorPool);
    endpoint.addThreadPool(workerPool);
    // set sync or async mode after endpoint is created
    if (sync) {
        endpoint.setExchangePattern(ExchangePattern.InOut);
    } else {
        endpoint.setExchangePattern(ExchangePattern.InOnly);
    }
    return endpoint;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ExecutorFilter(org.apache.mina.filter.executor.ExecutorFilter) LoggingFilter(org.apache.mina.filter.LoggingFilter) IoFilter(org.apache.mina.common.IoFilter) Endpoint(org.apache.camel.Endpoint) SocketAcceptorConfig(org.apache.mina.transport.socket.nio.SocketAcceptorConfig) IoAcceptor(org.apache.mina.common.IoAcceptor) ExecutorService(java.util.concurrent.ExecutorService) SocketAcceptor(org.apache.mina.transport.socket.nio.SocketAcceptor) SocketConnectorConfig(org.apache.mina.transport.socket.nio.SocketConnectorConfig) IoConnector(org.apache.mina.common.IoConnector) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) SocketConnector(org.apache.mina.transport.socket.nio.SocketConnector)

Example 7 with ExecutorFilter

use of org.apache.mina.filter.executor.ExecutorFilter in project camel by apache.

the class Mina2Consumer method setupSocketProtocol.

protected void setupSocketProtocol(String uri, Mina2Configuration configuration) throws Exception {
    LOG.debug("createSocketEndpoint");
    boolean minaLogger = configuration.isMinaLogger();
    List<IoFilter> filters = configuration.getFilters();
    address = new InetSocketAddress(configuration.getHost(), configuration.getPort());
    final int processorCount = Runtime.getRuntime().availableProcessors() + 1;
    acceptor = new NioSocketAcceptor(processorCount);
    // acceptor connectorConfig
    configureCodecFactory("Mina2Consumer", acceptor, configuration);
    ((NioSocketAcceptor) acceptor).setReuseAddress(true);
    acceptor.setCloseOnDeactivation(true);
    if (configuration.isOrderedThreadPoolExecutor()) {
        workerPool = new OrderedThreadPoolExecutor(configuration.getMaximumPoolSize());
    } else {
        workerPool = new UnorderedThreadPoolExecutor(configuration.getMaximumPoolSize());
    }
    acceptor.getFilterChain().addLast("threadPool", new ExecutorFilter(workerPool));
    if (minaLogger) {
        acceptor.getFilterChain().addLast("logger", new LoggingFilter());
    }
    appendIoFiltersToChain(filters, acceptor.getFilterChain());
    if (configuration.getSslContextParameters() != null) {
        SslFilter filter = new SslFilter(configuration.getSslContextParameters().createSSLContext(getEndpoint().getCamelContext()), configuration.isAutoStartTls());
        filter.setUseClientMode(false);
        acceptor.getFilterChain().addFirst("sslFilter", filter);
    }
}
Also used : SslFilter(org.apache.mina.filter.ssl.SslFilter) 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) NioSocketAcceptor(org.apache.mina.transport.socket.nio.NioSocketAcceptor)

Example 8 with ExecutorFilter

use of org.apache.mina.filter.executor.ExecutorFilter in project camel by apache.

the class Mina2Consumer method setupClientSocketProtocol.

protected void setupClientSocketProtocol(String uri, Mina2Configuration configuration) 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);
    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("Mina2Consumer", connector, configuration);
    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 9 with ExecutorFilter

use of org.apache.mina.filter.executor.ExecutorFilter 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 10 with ExecutorFilter

use of org.apache.mina.filter.executor.ExecutorFilter 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)

Aggregations

ExecutorFilter (org.apache.mina.filter.executor.ExecutorFilter)11 InetSocketAddress (java.net.InetSocketAddress)9 SslFilter (org.apache.mina.filter.ssl.SslFilter)6 IoFilter (org.apache.mina.core.filterchain.IoFilter)5 OrderedThreadPoolExecutor (org.apache.mina.filter.executor.OrderedThreadPoolExecutor)5 UnorderedThreadPoolExecutor (org.apache.mina.filter.executor.UnorderedThreadPoolExecutor)5 LoggingFilter (org.apache.mina.filter.logging.LoggingFilter)5 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)3 IOException (java.io.IOException)2 SocketAddress (java.net.SocketAddress)2 KeyManagementException (java.security.KeyManagementException)2 KeyStoreException (java.security.KeyStoreException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 UnrecoverableKeyException (java.security.UnrecoverableKeyException)2 ExecutorService (java.util.concurrent.ExecutorService)2 IoAcceptor (org.apache.mina.common.IoAcceptor)2 IoConnector (org.apache.mina.common.IoConnector)2 IoFilter (org.apache.mina.common.IoFilter)2 DefaultIoFilterChainBuilder (org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder)2 LoggingFilter (org.apache.mina.filter.LoggingFilter)2