-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAcceptor.java
More file actions
41 lines (29 loc) · 1.1 KB
/
Acceptor.java
File metadata and controls
41 lines (29 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.nio.ByteBuffer;
import java.nio.channels.*;
import java.io.IOException;
public class Acceptor implements IAcceptHandler {
private ISocketReadWriteHandlerFactory srwf;
public Acceptor(ISocketReadWriteHandlerFactory srwf) {
this.srwf = srwf;
}
public void handleException() {
System.out.println("handleException(): of Acceptor");
}
public void handleAccept(SelectionKey key) throws IOException {
ServerSocketChannel server = (ServerSocketChannel) key.channel();
// extract the ready connection
SocketChannel client = server.accept();
Debug.DEBUG("handleAccept: Accepted connection from " + client);
// configure the connection to be non-blocking
client.configureBlocking(false);
/*
* register the new connection with *read* events/operations
* SelectionKey clientKey = client.register( selector,
* SelectionKey.OP_READ);// | SelectionKey.OP_WRITE);
*/
IReadWriteHandler rwH = srwf.createHandler();
int ops = rwH.getInitOps();
SelectionKey clientKey = client.register(key.selector(), ops);
clientKey.attach(rwH);
} // end of handleAccept
} // end of class