本文整理匯總了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();
}
}