Skip to content

Instantly share code, notes, and snippets.

@nschlimm
Created March 21, 2012 11:35
Show Gist options
  • Save nschlimm/2146334 to your computer and use it in GitHub Desktop.
Save nschlimm/2146334 to your computer and use it in GitHub Desktop.
Closing with CompletionHandler
public class SimpleChannelClose_CompletionHandler {
...
public static void main(String[] args) throws InterruptedException, IOException, ExecutionException {
...
outputfile.write(ByteBuffer.wrap("Hello".getBytes()), fileindex.getAndIncrement() * 5, "", defaultCompletionHandler);
...
}
private static CompletionHandler<Integer, String> defaultCompletionHandler = new CompletionHandler<Integer, String>() {
@Override
public void completed(Integer result, String attachment) {
// NOP
}
@Override
public void failed(Throwable exc, String attachment) {
System.out.println("Do something to avoid data loss ...");
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment