blocks int filled=endpoint.fill(mybuffer);
Dispatched Read
By using a different callback, the read can be done asynchronously in its own dispatched thread:
endpoint.fillInterested("ContextObj",new ExecutorCallback<String>(executor) { public void onCompleted(String context) { int filled=endpoint.fill(mybuffer); ... } public void onFailed(String context,Throwable cause) {...} });
The executor callback can also be customized to not dispatch in some circumstances when it knows it can use the callback thread and does not need to dispatch.
Blocking Write
The write contract is that the callback complete is not called until all data has been written or there is a failure. For blocking this looks like:
FutureCallback<String> future = new FutureCallback<>(); endpoint.write("ContextObj",future,headerBuffer,contentBuffer); String context = future.get(); // This blocks
Dispatched Write
Note also that multiple buffers may be passed in write so that gather writes can be done:
endpoint.write("ContextObj",new ExecutorCallback<String>(executor) { public void onCompleted(String context) { int filled=endpoint.fill(mybuffer); ... } public void onFailed(String context,Throwable cause) {...} },headerBuffer,contentBuffer);