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


Java IoAcceptor.setHandler方法代码示例

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


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

示例1: main

import org.apache.mina.core.service.IoAcceptor; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {

		IoAcceptor acceptor = new NioSocketAcceptor();
		// 这个过滤器用来记录所有的信息,比如创建session(会话),接收消息,发送消息,关闭会话等
		acceptor.getFilterChain().addLast("logger", new LoggingFilter());
		// 用来转换二进制或协议的专用数据到消息对象中
		acceptor.getFilterChain().addLast("codec",
				new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));

		// 实时处理客户端的连接和请求
		acceptor.setHandler(new TimeServerHandler());
		acceptor.getSessionConfig().setReadBufferSize(2048);
		// 方法将定时调用一次会话,保持空闲状态。来设定时间间隔。
		acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);
		acceptor.bind(new InetSocketAddress(PORT));
	}
 
开发者ID:handexing,项目名称:frameworkAggregate,代码行数:17,代码来源:MinaTimeServer.java

示例2: main

import org.apache.mina.core.service.IoAcceptor; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
    // 创建服务器端的监听器对象
    IoAcceptor acceptor = new NioSocketAcceptor();
    // 增加日志过滤器:用于日志存储
    acceptor.getFilterChain().addLast("logger", new LoggingFilter());
    // 增加消息编码过滤器,采用UTF-8编码
    acceptor.getFilterChain().addLast("codec",
            new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));
    // 设置具体的事物逻辑处理器
    acceptor.setHandler(new TimeServerHandler());
    // 设置IoSession的一些属性
    acceptor.getSessionConfig().setReadBufferSize(2048);
    acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);
    // 设置服务器监听的端口
    acceptor.bind(new InetSocketAddress(PORT));
}
 
开发者ID:subaochen,项目名称:java-tutorial,代码行数:17,代码来源:MinaTimeServer.java

示例3: main

import org.apache.mina.core.service.IoAcceptor; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
        IoAcceptor acceptor = new NioSocketAcceptor();
//        acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, IDELTIMEOUT);

        acceptor.getFilterChain().addLast("logger", new LoggingFilter());
        acceptor.getFilterChain().addLast("myfliter", new MyFilter());
        acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new CommandCodecFactory("UTF-8")));

        KeepAliveMessageFactoryImpl kamfi = new KeepAliveMessageFactoryImpl();
        KeepAliveFilter kaf = new KeepAliveFilter(kamfi, IdleStatus.BOTH_IDLE);
        /** 是否回发 */
        kaf.setForwardEvent(true);
        acceptor.getFilterChain().addLast("heart", kaf);

        acceptor.setHandler(new CalculatorHandler());
        acceptor.bind(new InetSocketAddress(PORT));

        log.debug("socket通信服务端已启动,端口是" + PORT);
    }
 
开发者ID:Keybo1013,项目名称:mina,代码行数:20,代码来源:CalculatorServer.java

示例4: main

import org.apache.mina.core.service.IoAcceptor; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
	IoAcceptor acceptor = new NioSocketAcceptor();
	acceptor.getFilterChain().addLast("logger", new LoggingFilter());
	acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));// 指定编码过滤器
	acceptor.setHandler(new TimeServerHandler());// 指定业务逻辑处理器

	//读写 通道均在3 秒内无任何操作就进入空闲状态
	acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 3);

	acceptor.setDefaultLocalAddress(new InetSocketAddress(PORT));// 设置端口号
	acceptor.bind();// 启动监听
}
 
开发者ID:ggj2010,项目名称:javabase,代码行数:13,代码来源:MinaTimeServer.java

示例5: main

import org.apache.mina.core.service.IoAcceptor; //导入方法依赖的package包/类
/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    // TODO code application logic here
    IoAcceptor acceptor = new NioSocketAcceptor();
    acceptor.setHandler(new Mina2TesterServerHandler());

    try {
        acceptor.bind(new InetSocketAddress(7890));
    } catch (Exception e) {
        System.out.println("Config Error:" + e);
    }

    System.out.println("监听中...");

}
 
开发者ID:316181444,项目名称:GameServerFramework,代码行数:18,代码来源:Mina2Test.java

示例6: initializeAndBindPlatypusAcceptor

import org.apache.mina.core.service.IoAcceptor; //导入方法依赖的package包/类
private void initializeAndBindPlatypusAcceptor(InetSocketAddress s) throws IOException, Exception {
    //final SslFilter sslFilter = new SslFilter(sslContext); commented out until MINA Sslfilter bugs will be fixed
    ThreadPoolExecutor connectionsPollerExecutor = new ThreadPoolExecutor(1, 1,
            3L, TimeUnit.SECONDS,
            new LinkedBlockingQueue<>(),
            new PlatypusThreadFactory("nio-polling-", false));
    final IoAcceptor acceptor = new NioSocketAcceptor(connectionsPollerExecutor, new NioProcessor(executor));
    //acceptor.getFilterChain().addLast("encryption", sslFilter); commented out until MINA Sslfilter bugs will be fixed
    acceptor.getFilterChain().addLast("platypusCodec", new ProtocolCodecFilter(new ResponseEncoder(), new RequestDecoder()));
    /*
    acceptor.getFilterChain().addLast("executor", new ExecutorFilter(executor, IoEventType.EXCEPTION_CAUGHT,
            IoEventType.MESSAGE_RECEIVED, IoEventType.MESSAGE_SENT, IoEventType.SESSION_CLOSED, IoEventType.SESSION_IDLE, IoEventType.CLOSE, IoEventType.WRITE));
     */
    PlatypusRequestsHandler handler = new PlatypusRequestsHandler(this);
    acceptor.setHandler(handler);

    Integer sessionIdleTime = portsSessionIdleTimeouts != null ? portsSessionIdleTimeouts.get(s.getPort()) : null;
    if (sessionIdleTime == null || sessionIdleTime == 0) {
        sessionIdleTime = PlatypusRequestsHandler.SESSION_TIME_OUT;
    }
    Integer sessionIdleCheckInterval = portsSessionIdleCheckIntervals != null ? portsSessionIdleCheckIntervals.get(s.getPort()) : null;
    if (sessionIdleCheckInterval == null || sessionIdleCheckInterval == 0) {
        sessionIdleCheckInterval = PlatypusRequestsHandler.IDLE_TIME_EVENT;
    }
    handler.setSessionIdleCheckInterval(sessionIdleCheckInterval);
    handler.setSessionIdleTime(sessionIdleTime);
    acceptor.bind(s);
    Logger.getLogger(ServerMain.class.getName()).log(Level.INFO, "Listening platypus protocol on {0}", s.toString());
}
 
开发者ID:marat-gainullin,项目名称:platypus-js,代码行数:30,代码来源:PlatypusServer.java

示例7: main

import org.apache.mina.core.service.IoAcceptor; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
	IoAcceptor acceptor = new NioSocketAcceptor(); //TCP Acceptor
	acceptor.getFilterChain().addLast("logging", new LoggingFilter());
	acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
	acceptor.getFilterChain().addLast("mdc", new MdcInjectionFilter());
	acceptor.setHandler(new HelloServerHandler());
	acceptor.getSessionConfig().setReadBufferSize(2048);
	acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);
	acceptor.bind(new InetSocketAddress(PORT));
}
 
开发者ID:ameizi,项目名称:mina-examples,代码行数:11,代码来源:HelloTcpServer.java

示例8: ResetConnection

import org.apache.mina.core.service.IoAcceptor; //导入方法依赖的package包/类
/**
 * Cierra el socket actual y crea uno nuevo con en mismo handler
 * @throws IOException
 */
public static void ResetConnection() throws IOException{
    IoAcceptor newAcceptor = new NioSocketAcceptor();
    
    newAcceptor.getFilterChain().addLast("logger", new LoggingFilter());
    newAcceptor.setHandler( _acceptor.getHandler() );
    _acceptor.dispose();
    newAcceptor.getSessionConfig().setReadBufferSize(65536);
    newAcceptor.getSessionConfig().setIdleTime( IdleStatus.BOTH_IDLE, 10 );
    newAcceptor.bind( new InetSocketAddress( PORT ) );
    LOGGER.info("Mina Server Socket ReInitiated");
}
 
开发者ID:jenbabis22,项目名称:MXCashMarketDataDrv,代码行数:16,代码来源:DriverServer.java

示例9: scoketMain

import org.apache.mina.core.service.IoAcceptor; //导入方法依赖的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

示例10: init

import org.apache.mina.core.service.IoAcceptor; //导入方法依赖的package包/类
public void init() throws IOException {
	
	IoAcceptor acceptor = new NioSocketAcceptor();

	acceptor.getFilterChain().addLast("logger", new LoggingFilter());
	acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));

	acceptor.setHandler(new MinaChatServerHandler());
	acceptor.getSessionConfig().setReadBufferSize(2048);
	acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 600);
	
	acceptor.bind(new InetSocketAddress(port));
}
 
开发者ID:yuripourre,项目名称:mobile-chat,代码行数:14,代码来源:MinaServer.java


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