本文整理汇总了Java中org.apache.mina.transport.socket.nio.NioSocketAcceptor.getFilterChain方法的典型用法代码示例。如果您正苦于以下问题:Java NioSocketAcceptor.getFilterChain方法的具体用法?Java NioSocketAcceptor.getFilterChain怎么用?Java NioSocketAcceptor.getFilterChain使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mina.transport.socket.nio.NioSocketAcceptor
的用法示例。
在下文中一共展示了NioSocketAcceptor.getFilterChain方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //导入方法依赖的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: startServer
import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //导入方法依赖的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, "�˿��Ѿ�ռ�ã��뻻���˿ڣ�");
}
}
示例3: main
import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //导入方法依赖的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);
}
}
示例4: initialize
import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //导入方法依赖的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());
}
示例5: startListner
import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //导入方法依赖的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));
}
示例6: initService
import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //导入方法依赖的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);
}
示例7: MinaAcceptor
import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //导入方法依赖的package包/类
public MinaAcceptor(CodecFactory codecFactory, int maxIoThreads, int maxTaskThreads, TaskMapper taskMapper) {
Objects.requireNonNull(codecFactory);
log.info("Initializing acceptor {max I/O threads: {}, max task threads: {}}",
maxIoThreads,
maxTaskThreads > 0
? Integer.toString(maxTaskThreads)
: "unbounded");
acceptor = new NioSocketAcceptor(maxIoThreads);
DefaultIoFilterChainBuilder filters = acceptor.getFilterChain();
// encoding
filters.addLast("codec", new ProtocolCodecFilter(new MinaCodecFactory(codecFactory)));
// thread model
executor = newExecutor(maxTaskThreads, taskMapper);
filters.addLast("threadPool", new ExecutorFilter(executor));
// logging
filters.addLast("logger", new LoggingFilter());
// session handler
minaAdapter = new MinaAdapter();
acceptor.setHandler(minaAdapter);
// acceptor configuration
// disable disconnection on unbind
acceptor.setCloseOnDeactivation(false);
// port reuse when socket is in TIME_WAIT state
acceptor.setReuseAddress(true);
acceptor.getSessionConfig().setReuseAddress(true);
acceptor.getSessionConfig().setKeepAlive(true);
acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, DEFAULT_SESSION_IDLE_SECONDS);
// no Nagle's algorithm
acceptor.getSessionConfig().setTcpNoDelay(true);
}
示例8: initService
import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //导入方法依赖的package包/类
/**
* Initializes the runtime service.
*/
private void initService()
{
try
{
IoBuffer.setUseDirectBuffer(false);
acceptor = new NioSocketAcceptor(Runtime.getRuntime().availableProcessors() + 1);
acceptor.getSessionConfig().setReuseAddress(true);
DefaultIoFilterChainBuilder chain = acceptor.getFilterChain();
if (LOG.isTraceEnabled())
chain.addLast("logger", new LoggingFilter());
codecFactory = new SMTPCodecFactory(config);
chain.addLast("codec", new ProtocolCodecFilter(codecFactory));
executor = Executors.newCachedThreadPool(new ThreadFactory() {
int sequence;
public Thread newThread(Runnable r)
{
sequence += 1;
return new Thread(r, "MailsterSMTP Thread "+sequence);
}
});
chain.addLast("threadPool", new ExecutorFilter(executor));
handler = new SMTPConnectionHandler(getConfig(), getCommandHandler(),
getDeliveryHandlerFactory());
}
catch (Exception ex)
{
throw new RuntimeException(ex);
}
}
示例9: bind
import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //导入方法依赖的package包/类
@Override
public MinaAcceptance bind() {
// This socket acceptor will handle incoming connections
acceptor = new NioSocketAcceptor(transportConfig.getNioProcessorCount());
acceptor.setReuseAddress(true);
acceptor.setBacklog(128);
SocketSessionConfig sessionConfig = acceptor.getSessionConfig();
sessionConfig.setTcpNoDelay(true);
// set read buffer size
sessionConfig.setReceiveBufferSize(16 * 1024);
sessionConfig.setSendBufferSize(16 * 1024);
// get filter chain builder
DefaultIoFilterChainBuilder chainBuilder = acceptor.getFilterChain();
// add message codec filter
final TransportProtocolEncoder encoder = new TransportProtocolEncoder();
final TransportProtocolDecoder decoder = new TransportProtocolDecoder();
encoder.setMaxObjectSize(transportConfig.getMaxSize());
decoder.setMaxObjectSize(transportConfig.getMaxSize());
chainBuilder.addLast("codec", new ProtocolCodecFilter(encoder, decoder));
// add keep alive filter
KeepAliveFilter kaFilter = new KeepAliveFilter(new PassiveKeepAliveMessageFactory(), IdleStatus.BOTH_IDLE);
kaFilter.setRequestInterval(transportConfig.getHeartbeatIntervalSeconds());
kaFilter.setForwardEvent(true);
chainBuilder.addLast("keepAlive", kaFilter);
// add business handler
acceptor.setHandler(new MinaIoHandler());
try {
acceptor.bind(serviceAddress);
int processorCount = transportConfig.getBusinessProcessorCount();
if (processorCount > 0) {
NamedThreadFactory threadFactory = new NamedThreadFactory("Mina-BusinssProcessor");
executorService = Executors.newFixedThreadPool(processorCount, threadFactory);
}
} catch (Exception e) {
throw new RuntimeException("can't bind service on " + serviceAddress, e);
}
LOG.info("mina acceptance bind on {}", serviceAddress);
return this;
}
示例10: main
import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
NioSocketAcceptor acceptor = new NioSocketAcceptor();
DefaultIoFilterChainBuilder chain = acceptor.getFilterChain();
MdcInjectionFilter mdcInjectionFilter = new MdcInjectionFilter();
chain.addLast("mdc", mdcInjectionFilter);
SigHashTable sht = new SigHashTable();
/*
* FileSignature d0=new FileSignature("test data");
* SigManager.printByteArray(d0);
*
* FileSignature d1=new FileSignature(new File("ftphome//test.txt"));
* SigManager.printByteArray(d1);
*
* FileSignature d2=newFileSignature(
* "Design and Implementation of Virtualized Network Simulator");
* SigManager.printByteArray(d2);
*
* sht.addSignature(d0); sht.addSignature(d1); sht.addSignature(d2);
*/
PeerlessDbSupport peerlessDbSupport = new PeerlessDbSupport(ServerConfig.ServerDb);
peerlessDbSupport.connect();
peerlessDbSupport.createSchema();
SuperPeerManager superPeerManager = new SuperPeerManager();
// Add SSL filter if SSL is enabled.
if (USE_SSL) {
addSSLSupport(chain);
}
// chain.addLast("codec", new ProtocolCodecFilter(new
// TextLineCodecFactory()));
chain.addLast("codec", new ProtocolCodecFilter(
new ObjectSerializationCodecFactory()));
addLogger(chain);
// Bind
acceptor.setHandler(new PeerlessProtocolHandler(sht, peerlessDbSupport, superPeerManager));
acceptor.bind(new InetSocketAddress(ServerConfig.PORT));
System.out.println("Listening on port " + ServerConfig.PORT);
try {
new PeerlessUdpServer(peerlessDbSupport, sht);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}