1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.mina.io.socket;
20
21 import java.net.SocketException;
22
23 import org.apache.mina.common.BaseSessionConfig;
24 import org.apache.mina.common.SessionConfig;
25 import org.apache.mina.io.IoSession;
26 import org.apache.mina.protocol.ProtocolSession;
27
28 /***
29 * A {@link SessionConfig} for socket transport (TCP/IP).
30 * You can downcast {@link SessionConfig} instance returned by
31 * {@link IoSession#getConfig()} or {@link ProtocolSession#getConfig()}
32 * if you've created datagram session using {@link SocketAcceptor} or
33 * {@link SocketConnector}.
34 *
35 * @author Trustin Lee (trustin@apache.org)
36 * @version $Rev: 210062 $, $Date: 2005-07-11 12:52:38 +0900 $,
37 */
38 public class SocketSessionConfig extends BaseSessionConfig
39 {
40 private static final int DEFAULT_READ_BUFFER_SIZE = 1024;
41
42 private final SocketSession session;
43
44 private int readBufferSize = DEFAULT_READ_BUFFER_SIZE;
45
46 SocketSessionConfig( SocketSession session )
47 {
48 this.session = session;
49 }
50
51 public boolean getKeepAlive() throws SocketException
52 {
53 return session.getChannel().socket().getKeepAlive();
54 }
55
56 public void setKeepAlive( boolean on ) throws SocketException
57 {
58 session.getChannel().socket().setKeepAlive( on );
59 }
60
61 public boolean getOOBInline() throws SocketException
62 {
63 return session.getChannel().socket().getOOBInline();
64 }
65
66 public void setOOBInline( boolean on ) throws SocketException
67 {
68 session.getChannel().socket().setOOBInline( on );
69 }
70
71 public boolean getReuseAddress() throws SocketException
72 {
73 return session.getChannel().socket().getReuseAddress();
74 }
75
76 public void setReuseAddress( boolean on ) throws SocketException
77 {
78 session.getChannel().socket().setReuseAddress( on );
79 }
80
81 public int getSoLinger() throws SocketException
82 {
83 return session.getChannel().socket().getSoLinger();
84 }
85
86 public void setSoLinger( boolean on, int linger ) throws SocketException
87 {
88 session.getChannel().socket().setSoLinger( on, linger );
89 }
90
91 public boolean getTcpNoDelay() throws SocketException
92 {
93 return session.getChannel().socket().getTcpNoDelay();
94 }
95
96 public void setTcpNoDelay( boolean on ) throws SocketException
97 {
98 session.getChannel().socket().setTcpNoDelay( on );
99 }
100
101 public int getTrafficClass() throws SocketException
102 {
103 return session.getChannel().socket().getTrafficClass();
104 }
105
106 public void setTrafficClass( int tc ) throws SocketException
107 {
108 session.getChannel().socket().setTrafficClass( tc );
109 }
110
111 public int getSendBufferSize() throws SocketException
112 {
113 return session.getChannel().socket().getSendBufferSize();
114 }
115
116 public void setSendBufferSize( int size ) throws SocketException
117 {
118 session.getChannel().socket().setSendBufferSize( size );
119 }
120
121 public int getReceiveBufferSize() throws SocketException
122 {
123 return session.getChannel().socket().getReceiveBufferSize();
124 }
125
126 public void setReceiveBufferSize( int size ) throws SocketException
127 {
128 session.getChannel().socket().setReceiveBufferSize( size );
129 }
130
131 public int getSessionReceiveBufferSize()
132 {
133 return readBufferSize;
134 }
135
136 public void setSessionReceiveBufferSize( int size )
137 {
138 if( size <= 0 )
139 {
140 throw new IllegalArgumentException( "Invalid session receive buffer size: " + size );
141 }
142
143 this.readBufferSize = size;
144 }
145 }