本文整理汇总了Java中org.apache.mina.filter.executor.ExecutorFilter类的典型用法代码示例。如果您正苦于以下问题:Java ExecutorFilter类的具体用法?Java ExecutorFilter怎么用?Java ExecutorFilter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ExecutorFilter类属于org.apache.mina.filter.executor包,在下文中一共展示了ExecutorFilter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SocketServer
import org.apache.mina.filter.executor.ExecutorFilter; //导入依赖的package包/类
public SocketServer(int port, int threadPoolSize) {
NioSocketAcceptor acceptor = new NioSocketAcceptor();
acceptor.setHandler(new ServerHandler());
// acceptor.getFilterChain().addLast("mychian",new ProtocolCodecFilter(new TextLineCodecFactory()));
// acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));
acceptor.getFilterChain().addLast("exector", new ExecutorFilter(new OrderedThreadPoolExecutor(threadPoolSize)));
SocketSessionConfig ssc = acceptor.getSessionConfig();// 建立连接的配置文件
ssc.setReadBufferSize(4096);// 设置接收最大字节默认4096
ssc.setReceiveBufferSize(10240);// 设置输入缓冲区的大小
ssc.setSendBufferSize(10240);// 设置输出缓冲区的大小
ssc.setReuseAddress(true);// 设置每一个非主监听连接的端口可以重用
try {
// 绑定端口
acceptor.bind(new InetSocketAddress(port));
System.out.println("服务器启动正常,监听端口 " + port);
} catch (IOException e) {
e.printStackTrace();
}
}
示例2: MinaDestination
import org.apache.mina.filter.executor.ExecutorFilter; //导入依赖的package包/类
public MinaDestination(String host, int port, boolean withLogging) throws Exception {
socketAddress = new InetSocketAddress(host, port);
connector = new NioSocketConnector(Runtime.getRuntime().availableProcessors() + 1);
connector.setConnectTimeoutMillis(10000L);
connectorConfig = connector.getSessionConfig();
executor = new OrderedThreadPoolExecutor(5);
connector.getFilterChain().addLast("threadPool", new ExecutorFilter(executor));
if (withLogging) {
connector.getFilterChain().addLast("logger", new LoggingFilter());
}
SslFilter filter = new SslFilter(SSLContext.getDefault(), true);
filter.setUseClientMode(true);
connector.getFilterChain().addFirst("sslFilter", filter);
}
示例3: initialize
import org.apache.mina.filter.executor.ExecutorFilter; //导入依赖的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());
}
示例4: run
import org.apache.mina.filter.executor.ExecutorFilter; //导入依赖的package包/类
public void run() throws Exception {
if (start) {
SimpleIoProcessorPool<NioSession> simpleIoProcessorPool = new SimpleIoProcessorPool(
NioProcessor.class, LoginServer.ExecutorService);
acceptor = new NioSocketAcceptor(LoginServer.ExecutorService,
simpleIoProcessorPool);
acceptor.getSessionConfig().setTcpNoDelay(true);
acceptor.getFilterChain().addLast("ThreadPool",
new ExecutorFilter(LoginServer.ExecutorService));
acceptor.getFilterChain().addLast("executor",
new ExecutorFilter(LoginServer.ExecutorService));
acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 15);
acceptor.setHandler(new LoginGatewayHandler(this));
acceptor.bind(new InetSocketAddress(getPort()));
log.info("网关端口监听于 " + getPort());
}
}
示例5: startListner
import org.apache.mina.filter.executor.ExecutorFilter; //导入依赖的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.filter.executor.ExecutorFilter; //导入依赖的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: FilterChainBuilder
import org.apache.mina.filter.executor.ExecutorFilter; //导入依赖的package包/类
public FilterChainBuilder ( final boolean clientMode )
{
if ( !Boolean.getBoolean ( "org.eclipse.scada.protocol.ngp.common.disableStats" ) )
{
this.filters.add ( new Entry ( StatisticsFilter.DEFAULT_NAME, new StatisticsFilter () ) );
}
this.filters.add ( new Entry ( "logger.raw", new LoggerFilterFactory ( "raw" ) ) );
this.filters.add ( new Entry ( "ssl" ) );
this.filters.add ( new Entry ( "streamCompression" ) );
this.filters.add ( new Entry ( "logger", new LoggerFilterFactory ( "pre" ) ) );
this.filters.add ( new Entry ( "sync", new ExecutorFilter ( Integer.getInteger ( "org.eclipse.scada.protocol.ngp.common.coreSessionThreads", 0 ), Integer.getInteger ( "org.eclipse.scada.protocol.ngp.common.maxSessionThreads", 1 ), 1, TimeUnit.MINUTES, new NamedThreadFactory ( "org.eclipse.scada.protocol.ngp.common.FilterChainSync", false, true, THREAD_COUNTER ), IoEventType.WRITE ) ) );
this.filters.add ( new Entry ( "frameCodec", new ProtocolCodecFilter ( new FrameEncoder (), new FrameDecoder () ) ) );
this.filters.add ( new Entry ( "keepalive" ) );
this.filters.add ( new Entry ( "messageChannelCodec", new MessageChannelCodecFilter () ) );
this.filters.add ( new Entry ( "messageChannel", new IoFilterFactoryAdapter () {
@Override
public IoFilter create ()
{
// we need new instances of MessageChannelFilter
return new MessageChannelFilter ( clientMode );
}
} ) );
}
示例8: SocketServer
import org.apache.mina.filter.executor.ExecutorFilter; //导入依赖的package包/类
public SocketServer(int port, MessageHandler msgHandler, int threadPoolSize) {
mServerHandler = new ServerHandler(msgHandler);
acceptor = new NioSocketAcceptor();
acceptor.setHandler(mServerHandler);// 设置接收器的处理程序
acceptor.setReuseAddress(true) ;
// acceptor.getFilterChain().addLast("exector", new ExecutorFilter(new OrderedThreadPoolExecutor(10)));//建立有序线程池
acceptor.getFilterChain().addLast("exector", new ExecutorFilter(new OrderedThreadPoolExecutor(Runtime.getRuntime().availableProcessors()+1)));//建立有序线程池
// acceptor.getFilterChain().addLast("exector", new ExecutorFilter(new OrderedThreadPoolExecutor(128)));//建立有序线程池
/* Executor threadPool = Executors.newFixedThreadPool(threadPoolSize);// 建立线程池
acceptor.getFilterChain().addLast("exector",
new ExecutorFilter(threadPool));*/
acceptor.getFilterChain().addLast("codec",//解码\转码
new ProtocolCodecFilter(new MessageCodecFactory(Charset.forName("UTF-8"))));
try {
// 绑定端口
acceptor.bind(new InetSocketAddress(port));
logger.info("服务器启动正常,监听端口 " + port);
} catch (IOException e) {
e.printStackTrace();
}
SocketSessionConfig ssc = acceptor.getSessionConfig();// 建立连接的配置文件
ssc.setReadBufferSize(4096);// 设置接收最大字节默认4096
// ssc.setReceiveBufferSize(1024);// 设置输入缓冲区的大小
// ssc.setSendBufferSize(1024);// 设置输出缓冲区的大小
// ssc.setReuseAddress(true);// 设置每一个非主监听连接的端口可以重用
ssc.setTcpNoDelay(false);
}
示例9: buildFilterChain
import org.apache.mina.filter.executor.ExecutorFilter; //导入依赖的package包/类
protected void buildFilterChain() {
DefaultIoFilterChainBuilder filterChain = acceptor.getFilterChain();
filterChain.addLast("codec",new ProtocolCodecFilter(ProtocolCodecFactoryFactory.getInstance(rule)));
IoEventType[] DEFAULT_EVENT_SET = new IoEventType[] {
IoEventType.MESSAGE_RECEIVED
};
// businessPool用来处理DEFAULT_EVENT_SET事件,这里只处理获取
filterChain.addLast("businessPool", new ExecutorFilter(businessExecutor, DEFAULT_EVENT_SET));
}
示例10: main
import org.apache.mina.filter.executor.ExecutorFilter; //导入依赖的package包/类
public static void main(String[] args) {
NioSocketConnector connector = new NioSocketConnector();
DefaultIoFilterChainBuilder chain = connector.getFilterChain();
SocketSessionConfig config = connector.getSessionConfig();
config.setReuseAddress(true);
config.setIdleTime(IdleStatus.READER_IDLE, 20);// 读空闲 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());
connector.setHandler(new MinaMessageHandler());
connector.setConnectTimeoutMillis(15 * 1000); // 设置连接超时 ,15秒
connector.setConnectTimeoutCheckInterval(300);
// 建立连接
ConnectFuture cf = connector.connect(new InetSocketAddress("localhost", 8000));
// 等待连接创建完成
cf.awaitUninterruptibly();
Packet packet = Packet.newBuilder().setCmdId(0).setChatMsgAck(ChatMsgAck.newBuilder().setResult(123)).build();
cf.getSession().write(packet.toByteArray());
packet = Packet.newBuilder().setCmdId(1).setChatMsgAck(ChatMsgAck.newBuilder().setResult(123)).build();
cf.getSession().write(packet.toByteArray());
// 等待连接断开
cf.getSession().getCloseFuture().awaitUninterruptibly();
// 释放连接
connector.dispose();
}
示例11: MinaAcceptor
import org.apache.mina.filter.executor.ExecutorFilter; //导入依赖的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);
}
示例12: MinaConnector
import org.apache.mina.filter.executor.ExecutorFilter; //导入依赖的package包/类
public MinaConnector(CodecFactory codecFactory, int maxIoThreads, int maxTaskThreads, TaskMapper taskMapper) {
Objects.requireNonNull(codecFactory);
log.info("Initializing connector {max I/O threads: {}, max task threads: {}}",
Integer.toString(maxIoThreads),
maxTaskThreads > 0
? Integer.toString(maxTaskThreads)
: "unbounded");
connector = new NioSocketConnector(maxIoThreads);
DefaultIoFilterChainBuilder filters = connector.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();
connector.setHandler(minaAdapter);
// connector configuration
connector.getSessionConfig().setReuseAddress(true);
connector.getSessionConfig().setKeepAlive(true);
connector.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, DEFAULT_SESSION_IDLE_SECONDS);
// no Nagle's algorithm
connector.getSessionConfig().setTcpNoDelay(true);
}
示例13: CoreThreadPool
import org.apache.mina.filter.executor.ExecutorFilter; //导入依赖的package包/类
/**
* Create a new thread pool monitor mbean, giving it the pool to attach to.
*
* @param acceptor
* The pool to attach to.
*/
public CoreThreadPool(final SocketAcceptor acceptor) {
if (acceptor == null) {
throw new NullPointerException("acceptor is null");
}
//ExecutorThreadModel threadModel = (ExecutorThreadModel) acceptor.getDefaultConfig().getThreadModel();
//this.executor = (ThreadPoolExecutor) threadModel.getExecutor();
final ExecutorFilter executorFilter = (ExecutorFilter) acceptor.getFilterChain().get(EXECUTOR_FILTER_NAME);
this.executor = (ThreadPoolExecutor) executorFilter.getExecutor();
this.mina = new MINAStatCollector(acceptor);
}
示例14: bind
import org.apache.mina.filter.executor.ExecutorFilter; //导入依赖的package包/类
/**
* binds the LLRPIOHandler registered to the port specified. The bind method
* waits for an incoming READER_NOTIFICATION message with a successful
* ConnectionAttemptEvent for the timeout specified. If the timeout is set to zero,
* the bind method will not wait for an incoming READER_NOTIFICATION message.
*
* @param timeout time in ms
* @throws LLRPConnectionAttemptFailedException if ConnectionAttemptStatus 'Success' in READER_NOTIFICATION
* message is not received within time interval specified by timeout
*/
public void bind(long timeout) throws LLRPConnectionAttemptFailedException{
ExecutorService executor = new OrderedThreadPoolExecutor();
acceptor = new NioSocketAcceptor(Runtime.getRuntime().availableProcessors());
acceptor.getFilterChain().addLast("executor", new ExecutorFilter(executor));
acceptor.getFilterChain().addLast( "logger", new LoggingFilter() );
acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new LLRPProtocolCodecFactory(LLRPProtocolCodecFactory.BINARY_ENCODING)));
// MINA 2.0
acceptor.setHandler(handler);
acceptor.getSessionConfig().setReadBufferSize( 2048 );
acceptor.getSessionConfig().setIdleTime( IdleStatus.BOTH_IDLE, IDLE_TIME );
// MINA 1.1
//SocketAcceptorConfig cfg = new SocketAcceptorConfig();
//cfg.getSessionConfig().setReceiveBufferSize(2048);
try {
socketAddress = new InetSocketAddress(port);
acceptor.bind(socketAddress);//, handler);
log.info("server listening on port "+port);
} catch (IOException e) {
log.error(e.getMessage());
throw new LLRPConnectionAttemptFailedException(e.getMessage());
}
//check if llrp reader reply with a status report to indicate connection success.
//the client shall not send any information to the reader until this status report message is received
if (timeout>0) {
checkLLRPConnectionAttemptStatus(timeout);
}
}
示例15: initService
import org.apache.mina.filter.executor.ExecutorFilter; //导入依赖的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);
}
}