当前位置: 首页>>代码示例>>Java>>正文


Java SocketSessionConfig.setReadBufferSize方法代码示例

本文整理汇总了Java中org.apache.mina.transport.socket.SocketSessionConfig.setReadBufferSize方法的典型用法代码示例。如果您正苦于以下问题:Java SocketSessionConfig.setReadBufferSize方法的具体用法?Java SocketSessionConfig.setReadBufferSize怎么用?Java SocketSessionConfig.setReadBufferSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.mina.transport.socket.SocketSessionConfig的用法示例。


在下文中一共展示了SocketSessionConfig.setReadBufferSize方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: SocketServer

import org.apache.mina.transport.socket.SocketSessionConfig; //导入方法依赖的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();
		}
	}
 
开发者ID:langxianwei,项目名称:iot-plat,代码行数:21,代码来源:SocketServer.java

示例2: main

import org.apache.mina.transport.socket.SocketSessionConfig; //导入方法依赖的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);
	}
}
 
开发者ID:East196,项目名称:maker,代码行数:24,代码来源:BeatServer.java

示例3: initialize

import org.apache.mina.transport.socket.SocketSessionConfig; //导入方法依赖的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());
}
 
开发者ID:East196,项目名称:maker,代码行数:22,代码来源:TcpServer.java

示例4: SocketServer

import org.apache.mina.transport.socket.SocketSessionConfig; //导入方法依赖的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);
		
		
	}
 
开发者ID:langxianwei,项目名称:iot-plat,代码行数:32,代码来源:SocketServer.java

示例5: main

import org.apache.mina.transport.socket.SocketSessionConfig; //导入方法依赖的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();

}
 
开发者ID:East196,项目名称:maker,代码行数:34,代码来源:TcpClient.java

示例6: start

import org.apache.mina.transport.socket.SocketSessionConfig; //导入方法依赖的package包/类
@Override
	public void start() throws SuspendExecution, Exception {
		// Acceptor
		acceptor = new PooledNioSocketAcceptor(cpool);
		acceptor.setBacklog(1024);
		acceptor.setSessionDataStructureFactory(new PooledIoSessionDataStructureFactory(cpool));
		messageFactory = 
			new MinaMessageFactory(
//				hostAx.getActorSystem().getCustomMessageMap(), 
				hostAx.getActorSystem().getCMsgMap(),
				localInfo.getMinaMsgPoolSize(), 
				localInfo.getMinaMsgPoolInitSize(), 
				localInfo.getMinaMsgPoolMaxSize()
			);
		acceptor.getFilterChain().addLast("codec", new PooledProtocolCodecFilter(cpool, new MinaCodecFactory(messageFactory)));
		
		// Handler
		acceptor.setHandler(new MinaIoHandler(hostAx));
		
		// Config
		acceptor.setReuseAddress(true);
		SocketSessionConfig sscfg = acceptor.getSessionConfig();
		sscfg.setReadBufferSize(2048);
		sscfg.setMinReadBufferSize(2048);
		sscfg.setMaxReadBufferSize(2048);
		sscfg.setIdleTime(IdleStatus.READER_IDLE, localInfo.getMinaIdleTime());
		sscfg.setReceiveBufferSize(64 * 1024);
		sscfg.setSendBufferSize(160 * 1024);
		sscfg.setWriteTimeout(2);
		sscfg.setTcpNoDelay(true);
		sscfg.setSoLinger(-1);
		sscfg.setKeepAlive(false);
		
		// Bind
		List<SocketAddress> socketAddresses = new ArrayList<SocketAddress>();
		socketAddresses.add(new InetSocketAddress(localInfo.getHost(), localInfo.getPort()));
		acceptor.bind(socketAddresses);
	}
 
开发者ID:nousxiong,项目名称:actorx4j,代码行数:39,代码来源:MinaTcpServer.java

示例7: sessionCreated

import org.apache.mina.transport.socket.SocketSessionConfig; //导入方法依赖的package包/类
@Override
public void sessionCreated(IoSession session) throws Exception {
    SocketSessionConfig cfg = (SocketSessionConfig) session.getConfig();
    cfg.setReceiveBufferSize(2 * 1024 * 1024);
    cfg.setReadBufferSize(2 * 1024 * 1024);
    cfg.setKeepAlive(true);
    cfg.setSoLinger(0);
}
 
开发者ID:icelemon1314,项目名称:mapleLemon,代码行数:9,代码来源:MapleServerHandler.java

示例8: scoketMain

import org.apache.mina.transport.socket.SocketSessionConfig; //导入方法依赖的package包/类
public void scoketMain(){
      //构造接收器  创建非阻塞的server端的Socket连接
  	
      IoAcceptor acceptor = new NioSocketAcceptor();
      //创建业务处理类
      //ServerHandler handler = new ServerHandler();
      DemuxingServerHandler handler = new DemuxingServerHandler();
      //设置业务处理类
      acceptor.setHandler(handler);
      SocketSessionConfig cfg = (SocketSessionConfig) acceptor.getSessionConfig(); 
      //设置读取数据的缓冲区大小 
      cfg.setReadBufferSize(1024);
      //MINA在调用了close()方法后,不会再进入TIME_WAIT状态了,而直接Close掉了
      cfg.setSoLinger(0);
      cfg.getBothIdleTimeInMillis();
      //读写通道30秒内无操作进入空闲状态   
      cfg.setIdleTime(IdleStatus.BOTH_IDLE, 220);
      //将NioProcessor的IO操作线程和TimeServerHandler的业务处理线程分开
      acceptor.getFilterChain().addLast("executor", new ExecutorFilter());
      //过滤器 自定义混合解码器 采用DemuxingProtocolCodecFactory混合解码器协议
      acceptor.getFilterChain().addLast("codec",new ProtocolCodecFilter(new DemuxingAppqyProtocolCodecFactory(true,0)));
      //acceptor.getFilterChain().addLast("StringCodec", new ProtocolCodecFilter(new StringProtocalCodecFactory(Charset.forName("UTF-8"))));  
      //添加编码过滤器  这个过滤器的作用是将来自客户端输入的信息转换成一行行的文本后传递给 IoHandler ; ps:将指定名称的过滤器添加到过滤器链的末尾。
      //acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));
      //添加时间过滤器  默认间隔1秒同IP发送的连接请求将被拒绝(包括同IP下的其他端口,网上说不包含,测试之后是包含)
      //acceptor.getFilterChain().addFirst("tcpTime", new ConnectionThrottleFilter(5000));
       
      //添加日志组件
      acceptor.getFilterChain().addLast("logging", new LoggingFilter());
      //为NioSocketAcceptor增加一个线程的处理池 java运行分配少量内存的情况下  加了线程池容易内存溢出
      //acceptor.getFilterChain().addFirst("ThreadPool",new ExecutorFilter(Executors.newCachedThreadPool()));
      // 启动服务
      try {
	acceptor.bind(new InetSocketAddress(this.PORT));
	Date now = new Date();
	log.info(Language.eServerStar + this.PORT + " "+DateFormat.getDateTimeInstance().format(now));
} catch (IOException e) {

	e.printStackTrace();
	log.error(Language.ePortUse);
	log.error(Language.eServerExit);
	log.error("StackTrace:" + e.getStackTrace().toString());
	//结束程序
	System.exit(-1);
}
      
  }
 
开发者ID:Xvms,项目名称:xvms,代码行数:48,代码来源:MinaServer.java

示例9: start

import org.apache.mina.transport.socket.SocketSessionConfig; //导入方法依赖的package包/类
@Override
	public void start() throws SuspendExecution, Exception {
		connector = new PooledNioSocketConnector(cpool);
		connector.setSessionDataStructureFactory(new PooledIoSessionDataStructureFactory(cpool));
		messageFactory = 
			new MinaMessageFactory(
//				hostAx.getActorSystem().getCustomMessageMap(), 
				hostAx.getActorSystem().getCMsgMap(),
				remoteInfo.getMinaMsgPoolSize(), 
				remoteInfo.getMinaMsgPoolInitSize(), 
				remoteInfo.getMinaMsgPoolMaxSize()
			);
		connector.getFilterChain().addLast("codec", new PooledProtocolCodecFilter(cpool, new MinaCodecFactory(messageFactory)));
		connector.setHandler(new MinaIoHandler(hostAx));
		connector.setConnectTimeoutMillis(TimeUnit.SECONDS.toMillis(remoteInfo.getMinaConnectTimeout()));
		
		SocketSessionConfig sscfg = connector.getSessionConfig();
		sscfg.setReadBufferSize(2048);
		sscfg.setMinReadBufferSize(2048);
		sscfg.setMaxReadBufferSize(2048);
		sscfg.setIdleTime(IdleStatus.READER_IDLE, remoteInfo.getMinaIdleTime());
		sscfg.setReceiveBufferSize(64 * 1024);
		sscfg.setSendBufferSize(160 * 1024);
		sscfg.setWriteTimeout(2);
		sscfg.setTcpNoDelay(true);
		sscfg.setSoLinger(-1);
		sscfg.setKeepAlive(false);
		
		heartAid = hostAx.getActorSystem().spawn(hostAx, hostAx.getFiberScheduler(), new IFiberActorHandler() {
			@Override
			public void run(Actor self) throws SuspendExecution, InterruptedException {
				// 心跳计时器Actor
				Message cmsg = self.recv("INIT");
				ActorId sireAid = cmsg.getSender();
				
				Pattern pattern = new Pattern();
				pattern.match("STOP");
				pattern.after(remoteInfo.getHeartTimeout(), TimeUnit.SECONDS);
				
				while (true){
					try (PoolGuard guard = self.precv(pattern)){
						Message msg = guard.get();
						if (msg != null){
							String type = msg.getType();
							if (AtomCode.equals(type, "STOP")){
								break;
							}
						}else{
							self.send(sireAid, "HEART");
						}
					}catch (Throwable e){
						logger.error("{} heart error: {}", getClass().getSimpleName(), ExceptionUtils.printStackTrace(e));
					}
				}
			}
		}, LinkType.MONITORED);
		hostAx.send(heartAid, "INIT");
	}
 
开发者ID:nousxiong,项目名称:actorx4j,代码行数:59,代码来源:MinaTcpClient.java


注:本文中的org.apache.mina.transport.socket.SocketSessionConfig.setReadBufferSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。