@Override
  public void write(final ByteBufferList list) {
    if (mServer.getAffinity() != Thread.currentThread()) {
      mServer.run(
          new Runnable() {
            @Override
            public void run() {
              write(list);
            }
          });
      return;
    }
    if (!mChannel.isConnected()) {
      assert !mChannel.isChunked();
      return;
    }

    try {
      int before = list.remaining();
      ByteBuffer[] arr = list.getAllArray();
      mChannel.write(arr);
      list.addAll(arr);
      handleRemaining(list.remaining());
      mServer.onDataSent(before - list.remaining());
    } catch (IOException e) {
      closeInternal();
      reportEndPending(e);
      reportClose(e);
    }
  }
  @Override
  public void write(final ByteBuffer b) {
    if (mServer.getAffinity() != Thread.currentThread()) {
      mServer.run(
          new Runnable() {
            @Override
            public void run() {
              write(b);
            }
          });
      return;
    }
    try {
      if (!mChannel.isConnected()) {
        assert !mChannel.isChunked();
        return;
      }

      // keep writing until the the socket can't write any more, or the
      // data is exhausted.
      int before = b.remaining();
      mChannel.write(b);
      handleRemaining(b.remaining());
      mServer.onDataSent(before - b.remaining());
    } catch (IOException ex) {
      closeInternal();
      reportEndPending(ex);
      reportClose(ex);
    }
  }
  @Override
  public void pause() {
    if (mServer.getAffinity() != Thread.currentThread()) {
      mServer.run(
          new Runnable() {
            @Override
            public void run() {
              pause();
            }
          });
      return;
    }

    if (mPaused) return;

    mPaused = true;
    try {
      mKey.interestOps(~SelectionKey.OP_READ & mKey.interestOps());
    } catch (Exception ex) {
    }
  }
  @Override
  public void resume() {
    if (mServer.getAffinity() != Thread.currentThread()) {
      mServer.run(
          new Runnable() {
            @Override
            public void run() {
              resume();
            }
          });
      return;
    }

    if (!mPaused) return;
    mPaused = false;
    try {
      mKey.interestOps(SelectionKey.OP_READ | mKey.interestOps());
    } catch (Exception ex) {
    }
    spitPending();
    if (!isOpen()) reportEndPending(mPendingEndException);
  }
Esempio n. 5
0
 private void doResume() {
   server.post(pumper);
 }
Esempio n. 6
0
 public FileDataEmitter(AsyncServer server, File file) {
   this.server = server;
   this.file = file;
   paused = !server.isAffinityThread();
   if (!paused) doResume();
 }