MCPcopy Create free account
hub / github.com/ReadyTalk/avian / runMainLoop

Method runMainLoop

test/extra/SendServer.java:47–80  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

45 }
46
47 public void runMainLoop() throws Exception {
48 boolean keepRunning = true;
49 int port = 8988;
50 ServerSocketChannel serverChannel = ServerSocketChannel.open();
51 try {
52 serverChannel.configureBlocking(false);
53 serverChannel.socket().bind(new InetSocketAddress("0.0.0.0", port));
54 Selector selector = Selector.open();
55 serverChannel.register(selector, SelectionKey.OP_ACCEPT, null);
56 while (keepRunning) {
57 System.out.println("Running main loop");
58 selector.select(10000);
59 for (SelectionKey key : selector.selectedKeys()) {
60 if (key.isAcceptable()) {
61 System.out.println("Accepting new connection");
62 SocketChannel c = ((ServerSocketChannel) key.channel()).accept();
63 if (c != null) {
64 c.configureBlocking(false);
65 c.register(selector, SelectionKey.OP_READ, new Connection());
66 }
67 } else {
68 SocketChannel c = (SocketChannel) key.channel();
69 if (c.isOpen() && key.isReadable()) {
70 Connection connection = (Connection)key.attachment();
71 connection.handleRead(c);
72 }
73 }
74 }
75 selector.selectedKeys().clear();
76 }
77 } finally {
78 serverChannel.close();
79 }
80 }
81
82 public static void main(String args[]) {
83 try {

Callers 1

mainMethod · 0.80

Calls 15

openMethod · 0.95
configureBlockingMethod · 0.95
socketMethod · 0.95
openMethod · 0.95
selectMethod · 0.95
selectedKeysMethod · 0.95
configureBlockingMethod · 0.95
handleReadMethod · 0.95
closeMethod · 0.95
registerMethod · 0.80
isAcceptableMethod · 0.80
channelMethod · 0.80

Tested by

no test coverage detected