Examples of IOSession


Examples of com.yz.net.IoSession

   * 刷新消息,会根据session的类型来具体组织消息
   * </p>
   * <br>
   */
  public void flush() {
    IoSession session = BootChat.service.getIoSession(sessionId);
    if(session == null || session.isCloseing()){
      return;
    }
   
    ProtocolType type = (ProtocolType) session.getAttribute("TYPE");
   
    PlayerManager manager = PlayerManager.getInstance();
    Vector<OutputMessage> vector = manager.getPlayerDatas(playerId);
   
    switch(type) {
    case CMWAP:
      OutputMessage[] outMsgList = null;
      synchronized (vector) {
        outMsgList = new OutputMessage[vector.size()];
        for(int i=0; i<vector.size(); i++) {
          outMsgList[i] = vector.get(i);
        }
       
        vector.clear();
      }
     
      CmWapBindMessage wapMessage = MessageFactory.createCmWapBindMessage(outMsgList);
      session.write(wapMessage);
     
      break;
    case CMNET:
      synchronized (vector) {
        for(OutputMessage outMsg : vector) {
          session.write(outMsg);
        }
        vector.clear();
      }
      break;
    }
View Full Code Here

Examples of com.yz.net.IoSession

       
        session.addAttribute("START", System.currentTimeMillis());
        session.write(new ExampleMessage(num));
      }
      */
      IoSession session = IoConnector.newSession(connector);
      IoFuture future = session.connect();
     
      future.await();
     
     
     
      //int count = 0;
      while(true) {
       
        int num = rand.nextInt(5000);
        //startTime = System.currentTimeMillis();
        session.write(new ExampleMessage(num));
        Thread.sleep(1000);
      }
     
      //connector.stop();
     
View Full Code Here

Examples of com.yz.net.IoSession

      config.setIoHandler(new EchoHandler());
      config.start(connector);
     
     
      //生成一个客户端会话
      IoSession session = IoConnector.newSession(connector);
     
      //发出连接请求
      IoFuture future = session.connect();
     
      //等待连接完成
      future.await();
     
      //连接时发生错误后的处理
      if(future.isError()) {
        System.out.println(future.getThrowable().toString());
        return;
      }
     
     
      while(true) {
       
        InputStreamReader stream = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(stream);
       
        String str = reader.readLine();
        session.write(new EchoMessage(str));   //发送echo
      }
     
    }
    catch(Exception e) {
      e.printStackTrace();
View Full Code Here

Examples of com.yz.net.IoSession

   */
  protected void closeAllSession()  {
    Iterator<Long> iter = ioSessionMap.keySet().iterator();
    while(iter.hasNext()) {
      long sessionId = iter.next();
      IoSession session = ioSessionMap.get(sessionId);
      if(session != null) {
        IoFuture future = session.close();
        future.await(2000);
      }
    }
  }
View Full Code Here

Examples of org.apache.http.nio.reactor.IOSession

    }

    @Override
  protected void readable(final SelectionKey key) {
        SessionHandle handle = (SessionHandle) key.attachment();
        IOSession session = handle.getSession();
        handle.resetLastRead();

        try {
            this.eventDispatch.inputReady(session);
        } catch (RuntimeException ex) {
            handleRuntimeException(ex);
        }
        if (session.hasBufferedInput()) {
            this.bufferingSessions.add(session);
        }
    }
View Full Code Here

Examples of org.apache.http.nio.reactor.IOSession

    }

    @Override
  protected void writable(final SelectionKey key) {
        SessionHandle handle = (SessionHandle) key.attachment();
        IOSession session = handle.getSession();
        handle.resetLastWrite();
       
        try {
            this.eventDispatch.outputReady(session);
        } catch (RuntimeException ex) {
View Full Code Here

Examples of org.apache.http.nio.reactor.IOSession

                }
            }
        }
        if (!this.bufferingSessions.isEmpty()) {
            for (Iterator<IOSession> it = this.bufferingSessions.iterator(); it.hasNext(); ) {
                IOSession session = it.next();
                if (!session.hasBufferedInput()) {
                    it.remove();
                    continue;
                }
                try {
                    int ops = session.getEventMask();
                    if ((ops & EventMask.READ) > 0) {
                        try {
                            this.eventDispatch.inputReady(session);
                        } catch (RuntimeException ex) {
                            handleRuntimeException(ex);
                        }
                        if (!session.hasBufferedInput()) {
                            it.remove();
                        }
                    }
                } catch (CancelledKeyException ex) {
                    it.remove();
View Full Code Here

Examples of org.apache.http.nio.reactor.IOSession

    @Override
  protected void timeoutCheck(final SelectionKey key, long now) {
        Object attachment = key.attachment();
        if (attachment instanceof SessionHandle) {
            SessionHandle handle = (SessionHandle) key.attachment();
            IOSession session = handle.getSession();
            int timeout = session.getSocketTimeout();
            if (timeout > 0) {
                if (handle.getLastReadTime() + timeout < now) {
                    try {
                        this.eventDispatch.timeout(session);
                    } catch (RuntimeException ex) {
View Full Code Here

Examples of org.apache.http.nio.reactor.IOSession

            }
            if (key.isWritable()) {
                writable(key);
            }
        } catch (CancelledKeyException ex) {
            IOSession session = keyCancelled(key);
            if (session != null) {
                this.closedSessions.add(session);
            }
            key.attach(null);
        }
View Full Code Here

Examples of org.apache.http.nio.reactor.IOSession

            } catch (IOException ex) {
                throw new IOReactorException("Failure registering channel " +
                        "with the selector", ex);
            }

            IOSession session = new IOSessionImpl(key, new SessionClosedCallback() {

                public void sessionClosed(IOSession session) {
                    closedSessions.add(session);
                }
               
            });
           
            int timeout = 0;
            try {
                timeout = channel.socket().getSoTimeout();
            } catch (IOException ex) {
                // Very unlikely to happen and is not fatal
                // as the protocol layer is expected to overwrite
                // this value anyways
            }
           
            session.setAttribute(IOSession.ATTACHMENT_KEY, entry.getAttachment());
            session.setSocketTimeout(timeout);
            this.sessions.add(session);

            try {
                keyCreated(key, session);
               
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.