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

Class SocketSelector

classpath/java/nio/channels/SocketSelector.java:17–133  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15import java.net.Socket;
16
17class SocketSelector extends Selector {
18 protected volatile long state;
19 protected final Object lock = new Object();
20 protected boolean woken = false;
21
22 public SocketSelector() throws IOException {
23 Socket.init();
24
25 state = natInit();
26 }
27
28 public boolean isOpen() {
29 return state != 0;
30 }
31
32 public Selector wakeup() {
33 synchronized (lock) {
34 if (isOpen() && (! woken)) {
35 woken = true;
36
37 natWakeup(state);
38 }
39 }
40 return this;
41 }
42
43 private boolean clearWoken() {
44 synchronized (lock) {
45 if (woken) {
46 woken = false;
47 return true;
48 } else {
49 return false;
50 }
51 }
52 }
53
54 public synchronized int selectNow() throws IOException {
55 return doSelect(-1);
56 }
57
58 public synchronized int select() throws IOException {
59 return doSelect(0);
60 }
61
62 public synchronized int select(long interval) throws IOException {
63 if (interval < 0) throw new IllegalArgumentException();
64
65 return doSelect(interval);
66 }
67
68 public int doSelect(long interval) throws IOException {
69 if (! isOpen()) {
70 throw new ClosedSelectorException();
71 }
72
73 selectedKeys.clear();
74

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected