The document discusses concepts related to event loops and concurrency in programming. It includes code snippets in Java showing the use of NIO selectors and channels for non-blocking I/O. Diagrams are shown illustrating reactor patterns and Vert.x modules deployed across multiple CPUs. The summary provides an overview of the main topics and techniques discussed in the technical document.
13. Channel A
Channel B
Channel C
Channel D
Selector
Event Handler 1
Event Handler 2
Event Handler 3
Event Handler 4
Event Handler 5
REACTOR
DO NOT BLOCK!
JAVA NIO
14. Selector selector = Selector.open();
channel.configureBlocking(false);
SelectionKey key = channel.register(selector, SelectionKey.OP_READ);
while(true) {
int readyChannels = selector.select();
if(readyChannels == 0) continue;
Set<SelectionKey> selectedKeys = selector.selectedKeys();
Iterator<SelectionKey> keyIterator = selectedKeys.iterator();
while(keyIterator.hasNext()) {
SelectionKey key = keyIterator.next();
if(key.isAcceptable()) {
// a connection was accepted by a ServerSocketChannel.
} else if (key.isConnectable()) {
// a connection was established with a remote server.
} else if (key.isReadable()) {
// a channel is ready for reading
} else if (key.isWritable()) {
// a channel is ready for writing
}
keyIterator.remove();
}
}