本文整理汇总了Java中org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder类的典型用法代码示例。如果您正苦于以下问题:Java DefaultIoFilterChainBuilder类的具体用法?Java DefaultIoFilterChainBuilder怎么用?Java DefaultIoFilterChainBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultIoFilterChainBuilder类属于org.apache.mina.core.filterchain包,在下文中一共展示了DefaultIoFilterChainBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder; //导入依赖的package包/类
/**
* start Mina serversocket
* @throws Exception
*/
public void start() throws Exception {
IoBuffer.setUseDirectBuffer(false);
IoBuffer.setAllocator(new SimpleBufferAllocator());
acceptor = new NioSocketAcceptor(pool);
acceptor.setReuseAddress(true);
acceptor.getSessionConfig().setAll(getSessionConfig());
int serverPort = GateServerConfig.serverPort;
logger.info("socket server start at port:{},正在监听客户端的连接...", serverPort);
DefaultIoFilterChainBuilder filterChain = acceptor.getFilterChain();
filterChain.addLast("codec", new ProtocolCodecFilter(MessageCodecFactory.getInstance()));
acceptor.setHandler( new ServerSocketIoHandler() );//指定业务逻辑处理器
acceptor.setDefaultLocalAddress(new InetSocketAddress(serverPort) );//设置端口号
acceptor.bind();//启动监听
}
示例2: init
import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder; //导入依赖的package包/类
public static IoFilterChainBuilder init( LdapServer server ) throws LdapException
{
SSLContext sslCtx;
try
{
sslCtx = server.getSSLContext();
}
catch ( Exception e )
{
throw new LdapException( I18n.err( I18n.ERR_683 ), e );
}
DefaultIoFilterChainBuilder chain = new DefaultIoFilterChainBuilder();
SslFilter sslFilter = new SslFilter( sslCtx );
List<String> cipherSuites = server.getEnabledCipherSuites();
if( ( cipherSuites != null ) && !cipherSuites.isEmpty() )
{
sslFilter.setEnabledCipherSuites( cipherSuites.toArray( new String[cipherSuites.size()] ) );
}
sslFilter.setWantClientAuth( true );
chain.addLast( "sslFilter", sslFilter );
return chain;
}
示例3: init
import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder; //导入依赖的package包/类
private void init(Config config) {
connector = new NioDatagramConnector();
connector.setHandler(new MinaClientHandler());
DefaultIoFilterChainBuilder chain = connector.getFilterChain();
if (connector.getFilterChain().get(LOGGER) == null) {
chain.addLast(LOGGER, new LoggingFilter());
}
if (connector.getFilterChain().get(CODEC) == null) {
ProtocolCodecFactory codecFactory = config.codec == null ?
MinaUtil.getTextLineCodecFactory() : (ProtocolCodecFactory) config.codec;
chain.addLast(CODEC, new ProtocolCodecFilter(codecFactory));
}
connector.getSessionConfig().setReadBufferSize(config.bufferSize);
connector.getSessionConfig().setIdleTime(IdleStatus.WRITER_IDLE, 10);
connector.getSessionConfig().setBroadcast(true);
KeepAliveFilter keepAliveFilter = MinaUtil.initClientKeepAlive(config, this);
if (keepAliveFilter != null) {
connector.getFilterChain().addLast(HEARTBEAT, keepAliveFilter);
}
}
示例4: init
import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder; //导入依赖的package包/类
private void init(Config config) {
address = new InetSocketAddress(config.sourcePort);
acceptor = new NioDatagramAcceptor();
acceptor.setHandler(new MinaServerHandler());
DefaultIoFilterChainBuilder chain = acceptor.getFilterChain();
if (acceptor.getFilterChain().get(LOGGER) == null) {
chain.addLast(LOGGER, new LoggingFilter());
}
if (acceptor.getFilterChain().get(CODEC) == null) {
ProtocolCodecFactory codecFactory = config.codec == null ?
MinaUtil.getTextLineCodecFactory() : (ProtocolCodecFactory) config.codec;
chain.addLast(CODEC, new ProtocolCodecFilter(codecFactory));
}
DatagramSessionConfig dcfg = acceptor.getSessionConfig();
dcfg.setReuseAddress(true);
dcfg.setReadBufferSize(config.bufferSize);
dcfg.setIdleTime(IdleStatus.WRITER_IDLE, 10);
dcfg.setBroadcast(true);
KeepAliveFilter keepAliveFilter = MinaUtil.initServerKeepAlive(config, this);
if (keepAliveFilter != null) {
acceptor.getFilterChain().addLast(HEARTBEAT, keepAliveFilter);
}
}
示例5: startServer
import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder; //导入依赖的package包/类
/**
* �������
* @param args
* @throws IOException
*/
public void startServer() {
server = new NioSocketAcceptor();
//�������ݹ�����
DefaultIoFilterChainBuilder filterChain = server.getFilterChain();
filterChain.addLast("myChin", new ProtocolCodecFilter(
new ObjectSerializationCodecFactory()));
//filterChain.addLast("textCode",new ProtocolCodecFilter(
// new TextLineCodecFactory(Charset.forName("UTF-8"))));
serverIOHandler = new ServerIOHandler(severFrame);
server.setHandler(serverIOHandler);
//�����������˿� --- ����������
try {
server.bind(new InetSocketAddress(port));
} catch (IOException e) {
Tools.show(severFrame, "�˿��Ѿ�ռ�ã��뻻���˿ڣ�");
}
}
示例6: main
import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder; //导入依赖的package包/类
public static void main(String[] args) {
int port = U.getInt("cleaner.server.port");
int idleTime = U.getInt("cleaner.server.time");
NioSocketAcceptor clientAcceptor = new NioSocketAcceptor();
clientAcceptor.setReuseAddress(true);
DefaultIoFilterChainBuilder chain = clientAcceptor.getFilterChain();
SocketSessionConfig config = clientAcceptor.getSessionConfig();
config.setIdleTime(IdleStatus.READER_IDLE, idleTime);// 读空闲 10秒
config.setReuseAddress(true);
config.setReadBufferSize(4096);// 默认2048
config.setKeepAlive(true);
config.setTcpNoDelay(true);// 开启nagle算法
// 编解码
chain.addLast("coder", new ProtocolCodecFilter(new TextLineCodecFactory(U.UTF8)));
clientAcceptor.setHandler(new CleanerHandler());
try {
clientAcceptor.bind(new InetSocketAddress(port));
log.info("心跳模块启动..");
} catch (IOException e) {
log.error("心跳模块启动失败", e);
}
}
示例7: initialize
import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder; //导入依赖的package包/类
public void initialize() {
idleTime = U.getInt("chat.server.idleTime");
System.out.println(idleTime);
clientAcceptor = new NioSocketAcceptor();
clientAcceptor.setReuseAddress(true);
DefaultIoFilterChainBuilder chain = clientAcceptor.getFilterChain();
SocketSessionConfig config = clientAcceptor.getSessionConfig();
config.setReuseAddress(true);
config.setIdleTime(IdleStatus.READER_IDLE, idleTime);// 读空闲 20秒
config.setReadBufferSize(4096);// 默认2048
config.setKeepAlive(true);
config.setTcpNoDelay(true);// 禁用/开启nagle算法
// 编解码
chain.addLast("coder", new ProtocolCodecFilter(new MessageCodecFactory()));
// 日志
chain.addLast("logger", new LoggingFilter());
// 业务逻辑处理线程池
chain.addLast("threadPool", new ExecutorFilter());
}
示例8: startListner
import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder; //导入依赖的package包/类
public void startListner(IoHandler iohandler,int listenPort) throws Exception{
acceptor = new NioSocketAcceptor();
acceptor.setBacklog(100);
acceptor.setReuseAddress(true);
acceptor.setHandler(iohandler);
DefaultIoFilterChainBuilder chain = acceptor.getFilterChain();
IoFilter protocol = new ProtocolCodecFilter(new GameProtocolcodecFactory());
chain.addLast("codec", protocol);
threadpool = new OrderedThreadPoolExecutor(500);
threadpool.setThreadFactory(new ServerThreadFactory("OrderedThreadPool"));
chain.addLast("threadPool", new ExecutorFilter(threadpool));
int recsize = 5120;
int sendsize = 40480;
int timeout = 10;
SocketSessionConfig sc = acceptor.getSessionConfig();
sc.setReuseAddress(true);// 设置每一个非主监听连接的端口可以重用
sc.setReceiveBufferSize(recsize);// 设置输入缓冲区的大小
sc.setSendBufferSize(sendsize);// 设置输出缓冲区的大小
sc.setTcpNoDelay(true);// flush函数的调用 设置为非延迟发送,为true则不组装成大包发送,收到东西马上发出
sc.setSoLinger(0);
sc.setIdleTime(IdleStatus.READER_IDLE, timeout);
acceptor.bind(new InetSocketAddress(listenPort));
}
示例9: addFilterToChain
import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder; //导入依赖的package包/类
protected void addFilterToChain( final SocketAcceptor acceptor, final String filterName, final IoFilter filter )
{
if ( acceptor == null )
{
Log.debug( "Not adding filter '{}' to acceptor that is null.", filterName );
return;
}
final DefaultIoFilterChainBuilder chain = acceptor.getFilterChain();
if ( chain.contains( COMPRESSION_FILTER_NAME ) )
{
Log.debug( "Adding filter '{}' as the first filter after the compression filter in acceptor {}", filterName, acceptor );
chain.addAfter( COMPRESSION_FILTER_NAME, filterName, filter );
}
else if ( chain.contains( TLS_FILTER_NAME ) )
{
Log.debug( "Adding filter '{}' as the first filter after the TLS filter in acceptor {}", filterName, acceptor );
chain.addAfter( TLS_FILTER_NAME, filterName, filter );
}
else
{
Log.debug( "Adding filter '{}' as the last filter in acceptor {}", filterName, acceptor );
chain.addLast( filterName, filter );
}
}
示例10: initService
import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder; //导入依赖的package包/类
private void initService() throws Exception
{
IoBuffer.setUseDirectBuffer(false);
acceptor = new NioSocketAcceptor(
Runtime.getRuntime().availableProcessors() + 1);
config = acceptor.getSessionConfig();
config.setReuseAddress(true);
DefaultIoFilterChainBuilder chain = acceptor.getFilterChain();
chain.addLast("codec", new ProtocolCodecFilter(
new TextLineCodecFactory(
MailsterConstants.DEFAULT_CHARSET,
LineDelimiter.CRLF,
LineDelimiter.CRLF)));
executor = Executors.newCachedThreadPool(
ThreadFactoryUtilities.createFactory("POP3 Thread"));
chain.addLast("threadPool", new ExecutorFilter(executor));
handler = new Pop3ProtocolHandler(userManager);
}
示例11: getFilterChain
import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public final DefaultIoFilterChainBuilder getFilterChain() {
if (filterChainBuilder instanceof DefaultIoFilterChainBuilder) {
return (DefaultIoFilterChainBuilder) filterChainBuilder;
}
throw new IllegalStateException("Current filter chain builder is not a DefaultIoFilterChainBuilder.");
}
示例12: reloadSslContext
import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder; //导入依赖的package包/类
/**
* reloads the SSL context by replacing the existing SslFilter
* with a new SslFilter after reloading the keystore.
*
* Note: should be called to reload the keystore after changing the digital certificate.
*/
public void reloadSslContext() throws Exception
{
if ( !started )
{
return;
}
LOG.info( "reloading SSL context..." );
loadKeyStore();
String sslFilterName = "sslFilter";
for ( IoFilterChainBuilder chainBuilder : chainBuilders )
{
DefaultIoFilterChainBuilder dfcb = ( ( DefaultIoFilterChainBuilder ) chainBuilder );
if ( dfcb.contains( sslFilterName ) )
{
DefaultIoFilterChainBuilder newChain = ( DefaultIoFilterChainBuilder ) LdapsInitializer
.init( this );
dfcb.replace( sslFilterName, newChain.get( sslFilterName ) );
newChain = null;
}
}
StartTlsHandler handler = ( StartTlsHandler ) getExtendedOperationHandler( StartTlsHandler.EXTENSION_OID );
if ( handler != null )
{
handler.setLdapServer( this );
}
LOG.info( "reloaded SSL context successfully" );
}
示例13: initConnector
import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder; //导入依赖的package包/类
private void initConnector(InetSocketAddress isa, TransportConfig config) {
// create connector
ioConnector = new NioSocketConnector(1);
ioConnector.setConnectTimeoutMillis(config.getConnectTimeout());
SocketSessionConfig sessionConfig = ioConnector.getSessionConfig();
sessionConfig.setTcpNoDelay(true);
sessionConfig.setReceiveBufferSize(8 * 1024);
sessionConfig.setSendBufferSize(8 * 1024);
DefaultIoFilterChainBuilder chainBuilder = ioConnector.getFilterChain();
final TransportProtocolEncoder encoder = new TransportProtocolEncoder();
final TransportProtocolDecoder decoder = new TransportProtocolDecoder();
encoder.setMaxObjectSize(config.getMaxSize());
decoder.setMaxObjectSize(config.getMaxSize());
// add filter
chainBuilder.addLast("codec", new ProtocolCodecFilter(encoder, decoder));
// add keep alive filter
ActiveKeepAliveMessageFactory messageFactory = new ActiveKeepAliveMessageFactory(config.getSerializeType());
KeepAliveFilter kaFilter = new KeepAliveFilter(messageFactory, IdleStatus.BOTH_IDLE);
kaFilter.setRequestInterval(config.getHeartbeatIntervalSeconds());
kaFilter.setForwardEvent(true);
chainBuilder.addLast("keepAlive", kaFilter);
// set handler
ioConnector.setHandler(new MinaIoHandler());
ioConnector.setDefaultRemoteAddress(isa);
}
示例14: connect
import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder; //导入依赖的package包/类
/**
* �����ͻ�������
*/
public boolean connect() {
// ʵ���� �������� Socket����
client = new NioSocketConnector();
// �������ݹ�����
DefaultIoFilterChainBuilder filterChain = client.getFilterChain();
//filterChain.addLast("textCode", new ProtocolCodecFilter(
// new TextLineCodecFactory(Charset.forName("UTF-8"))));
filterChain.addLast("myChin", new ProtocolCodecFilter(
new ObjectSerializationCodecFactory()));
// �ͻ��˴������
ClientIoHandler clientIoHandler = new ClientIoHandler(loginFrame,client);
client.setHandler(clientIoHandler);
clientIoHandler.setRegisterFrame(registerFrame);
// ���ӷ�����
ConnectFuture future = client.connect(new InetSocketAddress(
IP, Port));
// �ȴ�
future.awaitUninterruptibly();
// �õ��Ự����
try {
session = future.getSession();
return true;
} catch (Exception e) {
Tools.show(loginFrame, "�����ӷ�������������û������");
client.dispose();
if(registerFrame!=null)
registerFrame.dispose();
return false;
}
// session.getCloseFuture().awaitUninterruptibly();
}
示例15: appendIoFiltersToChain
import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder; //导入依赖的package包/类
private void appendIoFiltersToChain(List<IoFilter> filters, DefaultIoFilterChainBuilder filterChain) {
if (filters != null && filters.size() > 0) {
for (IoFilter ioFilter : filters) {
filterChain.addLast(ioFilter.getClass().getCanonicalName(), ioFilter);
}
}
}