CompletionHandler<Integer, AsyncTaskInstance> handler
= new CompletionHandler<Integer, AsyncTaskInstance>() {
@Override
public void completed(Integer numRead, AsyncTaskInstance task) {
ThreadContext curTC = tc.gc.getCurrentThreadContext();
try {
if (numRead == -1) {
task.seq = -1;
callback(curTC, task, -1, Str, Null);
} else {
readBuffer.flip();
SixModelObject decoded = decoder.decode(tc, readBuffer, numRead);
readBuffer.compact();
callback(curTC, task, task.seq++, decoded, Null);
channel.read(readBuffer, task, this);
}
} catch (Throwable t) {
failed(t, task);
}
}
@Override
public void failed(Throwable t, AsyncTaskInstance task) {
ThreadContext curTC = tc.gc.getCurrentThreadContext();
SixModelObject err = (t instanceof AsynchronousCloseException)
? Str : Ops.box_s(t.toString(), Str, curTC);
callback(curTC, task, -1, Str, err);
}