Search in sources :

Example 1 with IoConnector

use of org.apache.mina.common.IoConnector in project camel by apache.

the class MinaComponent method createVmEndpoint.

// Implementation methods
//-------------------------------------------------------------------------
protected MinaEndpoint createVmEndpoint(String uri, MinaConfiguration configuration) {
    boolean minaLogger = configuration.isMinaLogger();
    boolean sync = configuration.isSync();
    List<IoFilter> filters = configuration.getFilters();
    IoAcceptor acceptor = new VmPipeAcceptor();
    SocketAddress address = new VmPipeAddress(configuration.getPort());
    IoConnector connector = new VmPipeConnector();
    // connector config
    configureCodecFactory("MinaProducer", connector.getDefaultConfig(), configuration);
    if (minaLogger) {
        connector.getFilterChain().addLast("logger", new LoggingFilter());
    }
    appendIoFiltersToChain(filters, connector.getFilterChain());
    // acceptor connectorConfig
    configureCodecFactory("MinaConsumer", acceptor.getDefaultConfig(), configuration);
    if (minaLogger) {
        acceptor.getFilterChain().addLast("logger", new LoggingFilter());
    }
    appendIoFiltersToChain(filters, acceptor.getFilterChain());
    MinaEndpoint endpoint = new MinaEndpoint(uri, this);
    endpoint.setAddress(address);
    endpoint.setAcceptor(acceptor);
    endpoint.setConnector(connector);
    endpoint.setConfiguration(configuration);
    // set sync or async mode after endpoint is created
    if (sync) {
        endpoint.setExchangePattern(ExchangePattern.InOut);
    } else {
        endpoint.setExchangePattern(ExchangePattern.InOnly);
    }
    return endpoint;
}
Also used : VmPipeAcceptor(org.apache.mina.transport.vmpipe.VmPipeAcceptor) IoAcceptor(org.apache.mina.common.IoAcceptor) LoggingFilter(org.apache.mina.filter.LoggingFilter) IoFilter(org.apache.mina.common.IoFilter) VmPipeAddress(org.apache.mina.transport.vmpipe.VmPipeAddress) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) IoConnector(org.apache.mina.common.IoConnector) VmPipeConnector(org.apache.mina.transport.vmpipe.VmPipeConnector)

Example 2 with IoConnector

use of org.apache.mina.common.IoConnector in project camel by apache.

the class MinaComponent method createDatagramEndpoint.

protected MinaEndpoint createDatagramEndpoint(String uri, MinaConfiguration configuration) {
    boolean minaLogger = configuration.isMinaLogger();
    long timeout = configuration.getTimeout();
    boolean transferExchange = configuration.isTransferExchange();
    boolean sync = configuration.isSync();
    List<IoFilter> filters = configuration.getFilters();
    ExecutorService acceptorPool = getCamelContext().getExecutorServiceManager().newCachedThreadPool(this, "MinaDatagramAcceptor");
    ExecutorService connectorPool = getCamelContext().getExecutorServiceManager().newCachedThreadPool(this, "MinaDatagramConnector");
    ExecutorService workerPool = getCamelContext().getExecutorServiceManager().newCachedThreadPool(this, "MinaThreadPool");
    IoAcceptor acceptor = new DatagramAcceptor(acceptorPool);
    IoConnector connector = new DatagramConnector(connectorPool);
    SocketAddress address = new InetSocketAddress(configuration.getHost(), configuration.getPort());
    if (transferExchange) {
        throw new IllegalArgumentException("transferExchange=true is not supported for datagram protocol");
    }
    DatagramConnectorConfig connectorConfig = new DatagramConnectorConfig();
    // must use manual thread model according to Mina documentation
    connectorConfig.setThreadModel(ThreadModel.MANUAL);
    configureDataGramCodecFactory("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));
    DatagramAcceptorConfig acceptorConfig = new DatagramAcceptorConfig();
    // must use manual thread model according to Mina documentation
    acceptorConfig.setThreadModel(ThreadModel.MANUAL);
    configureDataGramCodecFactory("MinaConsumer", acceptorConfig, configuration);
    acceptorConfig.setDisconnectOnUnbind(true);
    // reuse address is default true for datagram
    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) DatagramConnector(org.apache.mina.transport.socket.nio.DatagramConnector) DatagramConnectorConfig(org.apache.mina.transport.socket.nio.DatagramConnectorConfig) DatagramAcceptorConfig(org.apache.mina.transport.socket.nio.DatagramAcceptorConfig) DatagramAcceptor(org.apache.mina.transport.socket.nio.DatagramAcceptor) IoAcceptor(org.apache.mina.common.IoAcceptor) ExecutorService(java.util.concurrent.ExecutorService) IoConnector(org.apache.mina.common.IoConnector) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress)

Example 3 with IoConnector

use of org.apache.mina.common.IoConnector 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)

Aggregations

InetSocketAddress (java.net.InetSocketAddress)3 SocketAddress (java.net.SocketAddress)3 IoAcceptor (org.apache.mina.common.IoAcceptor)3 IoConnector (org.apache.mina.common.IoConnector)3 IoFilter (org.apache.mina.common.IoFilter)3 LoggingFilter (org.apache.mina.filter.LoggingFilter)3 ExecutorService (java.util.concurrent.ExecutorService)2 ExecutorFilter (org.apache.mina.filter.executor.ExecutorFilter)2 Endpoint (org.apache.camel.Endpoint)1 DatagramAcceptor (org.apache.mina.transport.socket.nio.DatagramAcceptor)1 DatagramAcceptorConfig (org.apache.mina.transport.socket.nio.DatagramAcceptorConfig)1 DatagramConnector (org.apache.mina.transport.socket.nio.DatagramConnector)1 DatagramConnectorConfig (org.apache.mina.transport.socket.nio.DatagramConnectorConfig)1 SocketAcceptor (org.apache.mina.transport.socket.nio.SocketAcceptor)1 SocketAcceptorConfig (org.apache.mina.transport.socket.nio.SocketAcceptorConfig)1 SocketConnector (org.apache.mina.transport.socket.nio.SocketConnector)1 SocketConnectorConfig (org.apache.mina.transport.socket.nio.SocketConnectorConfig)1 VmPipeAcceptor (org.apache.mina.transport.vmpipe.VmPipeAcceptor)1 VmPipeAddress (org.apache.mina.transport.vmpipe.VmPipeAddress)1 VmPipeConnector (org.apache.mina.transport.vmpipe.VmPipeConnector)1