1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.ssl.ocsp;
17
18 import io.netty.channel.ChannelFactory;
19 import io.netty.channel.EventLoop;
20 import io.netty.channel.nio.NioEventLoop;
21 import io.netty.channel.nio.NioEventLoopGroup;
22 import io.netty.channel.socket.DatagramChannel;
23 import io.netty.channel.socket.SocketChannel;
24 import io.netty.channel.socket.nio.NioDatagramChannel;
25 import io.netty.channel.socket.nio.NioSocketChannel;
26
27 import static io.netty.util.internal.ObjectUtil.checkNotNull;
28
29
30
31
32
33 public final class IoTransport {
34 private final EventLoop eventLoop;
35 private final ChannelFactory<SocketChannel> socketChannel;
36 private final ChannelFactory<DatagramChannel> datagramChannel;
37
38
39
40
41
42 public static final IoTransport DEFAULT = new IoTransport(new NioEventLoopGroup(1).next(),
43 new ChannelFactory<SocketChannel>() {
44 @Override
45 public SocketChannel newChannel() {
46 return new NioSocketChannel();
47 }
48 },
49 new ChannelFactory<DatagramChannel>() {
50 @Override
51 public DatagramChannel newChannel() {
52 return new NioDatagramChannel();
53 }
54 });
55
56
57
58
59
60
61
62
63
64 public static IoTransport create(EventLoop eventLoop, ChannelFactory<SocketChannel> socketChannel,
65 ChannelFactory<DatagramChannel> datagramChannel) {
66 return new IoTransport(eventLoop, socketChannel, datagramChannel);
67 }
68
69 private IoTransport(EventLoop eventLoop, ChannelFactory<SocketChannel> socketChannel,
70 ChannelFactory<DatagramChannel> datagramChannel) {
71 this.eventLoop = checkNotNull(eventLoop, "EventLoop");
72 this.socketChannel = checkNotNull(socketChannel, "SocketChannel");
73 this.datagramChannel = checkNotNull(datagramChannel, "DatagramChannel");
74 }
75
76 public EventLoop eventLoop() {
77 return eventLoop;
78 }
79
80 public ChannelFactory<SocketChannel> socketChannel() {
81 return socketChannel;
82 }
83
84 public ChannelFactory<DatagramChannel> datagramChannel() {
85 return datagramChannel;
86 }
87 }