MCPcopy Create free account
hub / github.com/e2wugui/zeze / register

Method register

ZezeJava/ZezeJava/src/main/java/Zeze/Net/Selector.java:127–140  ·  view source on GitHub ↗
(@NotNull SelectableChannel sc, int ops, @NotNull SelectorHandle handle)

Source from the content-addressed store, hash-verified

125 }
126
127 @NotNull SelectionKey register(@NotNull SelectableChannel sc, int ops, @NotNull SelectorHandle handle) {
128 try {
129 //noinspection MagicConstant
130 SelectionKey key = sc.register(selector, ops, handle);
131 // 当引擎线程执行register时,wakeup会导致一次多余唤醒。
132 // 这在连接建立不是很繁忙的应用中问题不大。
133 // 下面通过判断是否本线程来决定是否调用wakeup。
134 if (Thread.currentThread() != this)
135 selector.wakeup(); // 不会丢失。
136 return key;
137 } catch (IOException e) {
138 throw Task.forceThrow(e);
139 }
140 }
141
142 public void close() {
143 if (Thread.currentThread() == this) {

Callers

nothing calls this directly

Calls 2

forceThrowMethod · 0.95
wakeupMethod · 0.45

Tested by

no test coverage detected