Skip to content

StochasticTinkr/net.virtualinfinity.nio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

net.virtualinfinity.nio

Basic NIO and EventLoop.

This library provides a EventLoop class, which and aid in creating NIO based applications.

The basic idea is that you create an EventLoop object, which you can register handlers for selectable channels, as well as events to fire off in the future.

The library makes no assumptions about the threading model you wish to use. You will need to call "run()" on the EventLoop object for it to do its job.

A typical "main" might look like this:

public static void main(String[] args) throws IOException {
    final EventLoop eventLoop = new EventLoop();
    ServerSocketChannel serverChanel = ServerSocketChannel.open();
    serverChannel.configureBlocking(false);
    serverChannel.bind(new InetSocketAddress(80));

    eventLoop.registerHandler(serverChannel, createServerListener());

    eventLoop.run();
}