@Override
  public void run() {
    try {
      m_channelManager = new ClientChannelManager();

      long expireTime = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(1);

      while (m_channelManager.getActiveChannel() == null
          && System.currentTimeMillis() < expireTime) {
        TimeUnit.MILLISECONDS.sleep(1);
      }

      m_warmup.countDown();
      run0();
    } catch (Throwable e) {
      m_logger.error(e.getMessage(), e);
      m_warmup.countDown();
    } finally {
      if (m_channelManager != null) {
        m_channelManager.close();
      }

      m_latch.countDown();
    }
  }
  private void run0() throws InterruptedException {
    ByteBufAllocator allocator = m_descriptor.getByteBufAllocator();
    int initialCapacity = 4 * 1024; // 4K
    ByteBuf buf = allocator.buffer(initialCapacity);
    TransportHub hub = m_descriptor.getHub();

    while (m_active.get()) {
      Channel channel = m_channelManager.getActiveChannel();

      if (channel != null && channel.isWritable()) {
        do {
          if (hub.fill(buf)) {
            channel.writeAndFlush(buf);
            buf = allocator.buffer(initialCapacity);
          } else {
            break;
          }
        } while (channel.isWritable());
      }

      TimeUnit.MILLISECONDS.sleep(1); // 1ms
    }

    long end = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(3); // 3s timeout

    while (true) {
      Channel channel = m_channelManager.getActiveChannel();

      if (channel != null && channel.isWritable()) {
        do {
          if (hub.fill(buf)) {
            channel.writeAndFlush(buf);
            buf = allocator.buffer(initialCapacity);
          } else {
            break;
          }
        } while (channel.isWritable());
      }

      if (System.currentTimeMillis() >= end) {
        throw new InterruptedException("Timeout with messages left in the queue!");
      }

      TimeUnit.MILLISECONDS.sleep(1); // 1ms
    }
  }