use of org.apache.mina.transport.socket.nio.NioSocketConnector in project directory-ldap-api by apache.
the class LdapNetworkConnection method createConnector.
/**
* Create the connector
*/
private void createConnector() throws LdapException {
// Use only one thread inside the connector
connector = new NioSocketConnector(1);
if (connectionConfig != null) {
((SocketSessionConfig) connector.getSessionConfig()).setAll(connectionConfig);
} else {
((SocketSessionConfig) connector.getSessionConfig()).setReuseAddress(true);
}
// Add the codec to the chain
connector.getFilterChain().addLast("ldapCodec", ldapProtocolFilter);
// If we use SSL, we have to add the SslFilter to the chain
if (config.isUseSsl()) {
addSslFilter();
}
// Inject the protocolHandler
connector.setHandler(this);
}
use of org.apache.mina.transport.socket.nio.NioSocketConnector in project pancm_project by xuwujing.
the class MinaClient method main.
/**
* The entry point of application.
*
* @param args the input arguments
*/
/*
* 测试服务端与客户端程序!
a. 启动服务端,然后再启动客户端(客户端发送的消息是"why are you so diao ")
b. 服务端接收消息并处理成功;
*/
public static void main(String[] args) {
// 创建一个非阻塞的客户端程序
IoConnector connector = new NioSocketConnector();
// 设置链接超时时间
connector.setConnectTimeout(30000);
ProtocolCodecFilter pf = new ProtocolCodecFilter((new MyTextLineCodecFactory(Charset.forName("utf-8"), "\r\n")));
// 添加过滤器
connector.getFilterChain().addLast("codec", pf);
// 添加业务逻辑处理器类
connector.setHandler(new MinaClientHandler());
IoSession session = null;
try {
ConnectFuture future = connector.connect(new InetSocketAddress(HOST, // 创建连接
PORT));
// 等待连接创建完成
future.awaitUninterruptibly();
// 获得session
session = future.getSession();
String msg = "hello \r\n";
// 发送消息
session.write(msg);
logger.info("客户端与服务端建立连接成功...发送的消息为:" + msg);
} catch (Exception e) {
e.printStackTrace();
logger.error("客户端链接异常...", e);
}
// 等待连接断开
session.getCloseFuture().awaitUninterruptibly();
connector.dispose();
}
use of org.apache.mina.transport.socket.nio.NioSocketConnector in project pancm_project by xuwujing.
the class ClientTestServer method creatClient.
/**
* Creat client io connector.
*
* @return the io connector
*/
public IoConnector creatClient() {
IoConnector connector = new NioSocketConnector();
connector.setConnectTimeoutMillis(30000);
connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
connector.setHandler(new MinaClientHandler());
return connector;
}
use of org.apache.mina.transport.socket.nio.NioSocketConnector in project opennms by OpenNMS.
the class ConnectionFactoryConnectorPoolImpl method getSocketConnector.
private static final NioSocketConnector getSocketConnector(long timeout, IoHandler handler) {
NioSocketConnector connector = new NioSocketConnector();
connector.setHandler(handler);
connector.setConnectTimeoutMillis(timeout);
return connector;
}
use of org.apache.mina.transport.socket.nio.NioSocketConnector 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);
}
Aggregations