1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.mina.transport.socket.nio;
21
22 import java.net.InetSocketAddress;
23 import java.net.SocketAddress;
24 import java.nio.channels.DatagramChannel;
25
26 import org.apache.mina.core.buffer.IoBuffer;
27 import org.apache.mina.core.service.DefaultTransportMetadata;
28 import org.apache.mina.core.service.IoProcessor;
29 import org.apache.mina.core.service.IoService;
30 import org.apache.mina.core.service.TransportMetadata;
31 import org.apache.mina.core.session.IoSession;
32 import org.apache.mina.transport.socket.DatagramSessionConfig;
33
34
35
36
37
38
39 class NioDatagramSession extends NioSession {
40 static final TransportMetadata METADATA = new DefaultTransportMetadata("nio", "datagram", true, false,
41 InetSocketAddress.class, DatagramSessionConfig.class, IoBuffer.class);
42
43 private final InetSocketAddress localAddress;
44
45 private final InetSocketAddress remoteAddress;
46
47
48
49
50 NioDatagramSession(IoService service, DatagramChannel channel, IoProcessor<NioSession> processor,
51 SocketAddress remoteAddress) {
52 super(processor, service, channel);
53 config = new NioDatagramSessionConfig(channel);
54 config.setAll(service.getSessionConfig());
55 this.remoteAddress = (InetSocketAddress) remoteAddress;
56 this.localAddress = (InetSocketAddress) channel.socket().getLocalSocketAddress();
57 }
58
59
60
61
62 NioDatagramSession(IoService service, DatagramChannel channel, IoProcessor<NioSession> processor) {
63 this(service, channel, processor, channel.socket().getRemoteSocketAddress());
64 }
65
66
67
68
69 public DatagramSessionConfig getConfig() {
70 return (DatagramSessionConfig) config;
71 }
72
73 @Override
74 DatagramChannel getChannel() {
75 return (DatagramChannel) channel;
76 }
77
78 public TransportMetadata getTransportMetadata() {
79 return METADATA;
80 }
81
82 public InetSocketAddress getRemoteAddress() {
83 return remoteAddress;
84 }
85
86 public InetSocketAddress getLocalAddress() {
87 return localAddress;
88 }
89
90 @Override
91 public InetSocketAddress getServiceAddress() {
92 return (InetSocketAddress) super.getServiceAddress();
93 }
94 }