1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.channel.nio;
17
18
19 import io.netty.channel.IoEvent;
20 import io.netty.channel.IoHandle;
21 import io.netty.channel.IoRegistration;
22 import io.netty.util.internal.ObjectUtil;
23
24 import java.nio.channels.SelectableChannel;
25 import java.nio.channels.SelectionKey;
26
27
28
29
30
31
32 public abstract class NioSelectableChannelIoHandle<S extends SelectableChannel> implements IoHandle, NioIoHandle {
33 private final S channel;
34
35 public NioSelectableChannelIoHandle(S channel) {
36 this.channel = ObjectUtil.checkNotNull(channel, "channel");
37 }
38
39 @Override
40 public void handle(IoRegistration registration, IoEvent ioEvent) {
41 SelectionKey key = ((NioIoRegistration) registration).selectionKey();
42 NioSelectableChannelIoHandle.this.handle(channel, key);
43 }
44
45 @Override
46 public void close() throws Exception {
47 channel.close();
48 }
49
50 @Override
51 public SelectableChannel selectableChannel() {
52 return channel;
53 }
54
55 protected abstract void handle(S channel, SelectionKey key);
56
57 protected void deregister(S channel) {
58
59 }
60 }