use of org.apache.mina.transport.socket.nio.NioSocketConnector 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);
}
use of org.apache.mina.transport.socket.nio.NioSocketConnector in project opennms by OpenNMS.
the class ConnectionFactoryNewConnectorImpl method getSocketConnector.
private static final NioSocketConnector getSocketConnector(long timeout, IoHandler handler) {
// Create a new NioSocketConnector
// NioSocketConnector connector = new NioSocketConnector(m_executor, m_processor);
// To address bug NMS-6412, I'm changing this to use the default constructor so that the
// Executor pool and IoProcessor pools are created and destroyed for every connector.
// This slows things down but might be an acceptable tradeoff for more reliable detection.
//
// @see http://issues.opennms.org/browse/NMS-6412
//
NioSocketConnector connector = new NioSocketConnector(Runtime.getRuntime().availableProcessors());
// Enable SO_REUSEADDR on the socket so that TIMED_WAIT connections that are bound on the
// same port do not block new outgoing connections. If the connections are blocked, then
// the following exception will be thrown under heavy load:
//
// Caused by: java.net.SocketException: Invalid argument
// at sun.nio.ch.Net.connect(Native Method)
// at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:500)
// at org.apache.mina.transport.socket.nio.NioSocketConnector.connect(NioSocketConnector.java:188)
// ...
//
// @see http://issues.opennms.org/browse/NMS-5469
//
connector.getSessionConfig().setReuseAddress(true);
// Setting SO_LINGER will prevent TIME_WAIT sockets altogether because TCP connections will be
// forcefully terminated with RST packets. However, this doesn't seem to be necessary to maintain
// performance of the outgoing connections. As long as SO_REUSEADDR is set, the operating system
// and Java appear to recycle the ports effectively although some will remain in TIME_WAIT state.
//
// @see http://issues.opennms.org/browse/NMS-5469
//
// connector.getSessionConfig().setSoLinger(0);
connector.setHandler(handler);
connector.setConnectTimeoutMillis(timeout);
return connector;
}
Aggregations