コード例 #1
0
  @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);
    }
  }
コード例 #2
0
  @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);
    }
  }
コード例 #3
0
  @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) {
    }
  }
コード例 #4
0
  @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);
  }
コード例 #5
0
 private void doResume() {
   server.post(pumper);
 }
コード例 #6
0
 public FileDataEmitter(AsyncServer server, File file) {
   this.server = server;
   this.file = file;
   paused = !server.isAffinityThread();
   if (!paused) doResume();
 }