-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNativeTaskSelector.java
More file actions
executable file
·70 lines (57 loc) · 1.82 KB
/
NativeTaskSelector.java
File metadata and controls
executable file
·70 lines (57 loc) · 1.82 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import java.io.IOException;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.spi.AbstractSelectableChannel;
import java.nio.channels.spi.AbstractSelector;
import java.util.Set;
/**
* NativeTaskSelector isn't a "real" Selector, it's a dummy object because we
* want to hook into the goodness of AbstractSelector. AbstractSelector uses
* some cunning private goop (sun.misc.SharedSecrets) to hook into the current
* thread object and receive notifications when the thread is interrupted.
* Since that's what we're after, we implement AbstractSelector simply to
* receive that notification.
*/
class NativeTaskSelector extends AbstractSelector {
protected NativeTaskSelector(NativeTask task_) {
super(null);
task = task_;
}
public void registerStart() { begin(); }
public void registerEnd() { end(); }
final private NativeTask task;
@Override
protected void implCloseSelector() throws IOException {
}
@Override
protected SelectionKey register(AbstractSelectableChannel arg0, int arg1,
Object arg2) {
throw new UnsupportedOperationException();
}
@Override
public Set<SelectionKey> keys() {
throw new UnsupportedOperationException();
}
@Override
public int select() throws IOException {
throw new UnsupportedOperationException();
}
@Override
public int select(long arg0) throws IOException {
throw new UnsupportedOperationException();
}
@Override
public int selectNow() throws IOException {
throw new UnsupportedOperationException();
}
@Override
public Set<SelectionKey> selectedKeys() {
throw new UnsupportedOperationException();
}
@Override
public Selector wakeup() {
System.out.println("Received notification of Thread interrupt");
task.wakeupTask();
return this;
}
}