Skip to content

Instantly share code, notes, and snippets.

@trustin
Created July 3, 2012 12:45
Show Gist options
  • Save trustin/3039522 to your computer and use it in GitHub Desktop.
Save trustin/3039522 to your computer and use it in GitHub Desktop.
java.nio.channels.FileChannel myFile = ...;
java.nio.channels.SocketChannel mySocket = java.nio.channels.SocketChannel.open();
// Perform some blocking operation here.
...
// Netty takes over.
SocketChannel ch = new NioSocketChannel(mySocket);
EventLoopGroup group = ...;
group.register(ch);
...
// Deregister from Netty.
ch.deregister().sync();
// Perform some blocking operation here.
mySocket.configureBlocking(false);
myFile.transferFrom(mySocket, ...);
// Register back again to another event loop group.
EventLoopGroup anotherGroup = ...;
anotherGroup.register(ch);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment