Package com.google.code.hs4j.network.core

Examples of com.google.code.hs4j.network.core.Session


  /**
   * Cancel selection key
   */
  public void closeSelectionKey(SelectionKey key) {
    if (key.attachment() instanceof Session) {
      Session session = (Session) key.attachment();
      if (session != null) {
        session.close();
      }
    }
  }
View Full Code Here


  }

  private final AtomicInteger sets = new AtomicInteger();

  public Session selectSession() throws HandlerSocketException {
    Session session = this.sessionList.get(this.sets.incrementAndGet()
        % this.sessionList.size());
    int retryCount = 0;
    while ((session == null || session.isClosed()) && retryCount++ < 6) {
      session = this.sessionList.get(this.sets.incrementAndGet()
          % this.sessionList.size());
    }
    if (session == null || session.isClosed()) {
      throw new HandlerSocketException(
          "Could not find an open connection");
    }
    return session;
  }
View Full Code Here

   * @see
   * com.google.code.hs4j.network.hs.HandlerCOnnector#send(com.google.code
   * .hs4j.Command)
   */
  public void send(final Command msg) throws HandlerSocketException {
    Session session = this.selectSession();
    session.write(msg);
  }
View Full Code Here

    super(configuration, handler, codecFactory);
  }

  @Override
  protected final void dispatchReadEvent(SelectionKey key) {
    Session session = (Session) key.attachment();
    if (session != null) {
      ((NioSession) session).onEvent(EventType.READABLE, key.selector());
    } else {
      log
          .warn("Could not find session for readable event,maybe it is closed");
View Full Code Here

    }
  }

  @Override
  protected final void dispatchWriteEvent(SelectionKey key) {
    Session session = (Session) key.attachment();
    if (session != null) {
      ((NioSession) session).onEvent(EventType.WRITEABLE, key.selector());
    } else {
      log
          .warn("Could not find session for writable event,maybe it is closed");
View Full Code Here

    SocketChannel sc = null;
    try {
      sc = this.serverSocketChannel.accept();
      if (sc != null) {
        configureSocketChannel(sc);
        Session session = buildSession(sc);
        // enable read
        this.selectorManager.registerSession(session,
            EventType.ENABLE_READ);
        session.start();
        super.onAccept(selectionKey); // for statistics
      } else {
        log.debug("Accept fail");
      }
    } catch (IOException e) {
View Full Code Here

TOP

Related Classes of com.google.code.hs4j.network.core.Session

Copyright © 2018 www.massapicom. 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.