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.SocketException;
23 import java.nio.channels.DatagramChannel;
24
25 import org.apache.mina.core.RuntimeIoException;
26 import org.apache.mina.transport.socket.AbstractDatagramSessionConfig;
27 import org.apache.mina.transport.socket.DefaultDatagramSessionConfig;
28
29
30
31
32
33
34
35 class NioDatagramSessionConfig extends AbstractDatagramSessionConfig {
36 private final DatagramChannel c;
37
38 NioDatagramSessionConfig(DatagramChannel c) {
39 this.c = c;
40 }
41
42 public int getReceiveBufferSize() {
43 try {
44 return c.socket().getReceiveBufferSize();
45 } catch (SocketException e) {
46 throw new RuntimeIoException(e);
47 }
48 }
49
50 public void setReceiveBufferSize(int receiveBufferSize) {
51 if (DefaultDatagramSessionConfig.isSetReceiveBufferSizeAvailable()) {
52 try {
53 c.socket().setReceiveBufferSize(receiveBufferSize);
54
55
56
57
58
59
60
61
62 } catch (SocketException e) {
63 throw new RuntimeIoException(e);
64 }
65 }
66 }
67
68 public boolean isBroadcast() {
69 try {
70 return c.socket().getBroadcast();
71 } catch (SocketException e) {
72 throw new RuntimeIoException(e);
73 }
74 }
75
76 public void setBroadcast(boolean broadcast) {
77 try {
78 c.socket().setBroadcast(broadcast);
79 } catch (SocketException e) {
80 throw new RuntimeIoException(e);
81 }
82 }
83
84 public int getSendBufferSize() {
85 try {
86 return c.socket().getSendBufferSize();
87 } catch (SocketException e) {
88 throw new RuntimeIoException(e);
89 }
90 }
91
92 public void setSendBufferSize(int sendBufferSize) {
93 if (DefaultDatagramSessionConfig.isSetSendBufferSizeAvailable()) {
94 try {
95 c.socket().setSendBufferSize(sendBufferSize);
96 } catch (SocketException e) {
97 throw new RuntimeIoException(e);
98 }
99 }
100 }
101
102 public boolean isReuseAddress() {
103 try {
104 return c.socket().getReuseAddress();
105 } catch (SocketException e) {
106 throw new RuntimeIoException(e);
107 }
108 }
109
110 public void setReuseAddress(boolean reuseAddress) {
111 try {
112 c.socket().setReuseAddress(reuseAddress);
113 } catch (SocketException e) {
114 throw new RuntimeIoException(e);
115 }
116 }
117
118 public int getTrafficClass() {
119 if (DefaultDatagramSessionConfig.isGetTrafficClassAvailable()) {
120 try {
121 return c.socket().getTrafficClass();
122 } catch (SocketException e) {
123 throw new RuntimeIoException(e);
124 }
125 } else {
126 return 0;
127 }
128 }
129
130 public void setTrafficClass(int trafficClass) {
131 if (DefaultDatagramSessionConfig.isSetTrafficClassAvailable()) {
132 try {
133 c.socket().setTrafficClass(trafficClass);
134 } catch (SocketException e) {
135 throw new RuntimeIoException(e);
136 }
137 }
138 }
139 }