1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.directory.server.protocol.shared.transport;
20
21
22 import java.net.InetSocketAddress;
23 import java.util.List;
24
25 import org.apache.directory.api.util.Network;
26 import org.apache.mina.core.service.IoAcceptor;
27 import org.apache.mina.transport.socket.SocketAcceptor;
28 import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32
33
34
35
36
37
38 public class TcpTransport extends AbstractTransport
39 {
40
41 private boolean needClientAuth;
42
43
44 private boolean wantClientAuth;
45
46
47 private List<String> enabledProtocols;
48
49
50 private List<String> cipherSuite;
51
52
53 private static final Logger LOG = LoggerFactory.getLogger( TcpTransport.class );
54
55
56
57
58
59 public TcpTransport()
60 {
61 super();
62 }
63
64
65
66
67
68
69 public TcpTransport( int tcpPort )
70 {
71 super( null, tcpPort, DEFAULT_NB_THREADS, DEFAULT_BACKLOG_NB );
72
73 this.acceptor = createAcceptor( null, tcpPort, DEFAULT_NB_THREADS, DEFAULT_BACKLOG_NB );
74
75 LOG.debug( "TCP Transport created : <*:{},>", tcpPort );
76 }
77
78
79
80
81
82
83
84 public TcpTransport( int tcpPort, int nbThreads )
85 {
86 super( null, tcpPort, nbThreads, DEFAULT_BACKLOG_NB );
87
88 this.acceptor = createAcceptor( null, tcpPort, nbThreads, DEFAULT_BACKLOG_NB );
89
90 LOG.debug( "TCP Transport created : <*:{},>", tcpPort );
91 }
92
93
94
95
96
97
98
99 public TcpTransport( String address, int tcpPort )
100 {
101 super( address, tcpPort, DEFAULT_NB_THREADS, DEFAULT_BACKLOG_NB );
102 this.acceptor = createAcceptor( address, tcpPort, DEFAULT_NB_THREADS, DEFAULT_BACKLOG_NB );
103
104 LOG.debug( "TCP Transport created : <{}:{}>", address, tcpPort );
105 }
106
107
108
109
110
111
112
113
114
115 public TcpTransport( int tcpPort, int nbThreads, int backLog )
116 {
117 super( Network.LOOPBACK.getHostAddress(), tcpPort, nbThreads, backLog );
118 this.acceptor = createAcceptor( null, tcpPort, nbThreads, backLog );
119
120 LOG.debug( "TCP Transport created : <*:{},>", tcpPort );
121 }
122
123
124
125
126
127
128
129
130
131
132 public TcpTransport( String address, int tcpPort, int nbThreads, int backLog )
133 {
134 super( address, tcpPort, nbThreads, backLog );
135 this.acceptor = createAcceptor( address, tcpPort, nbThreads, backLog );
136
137 LOG.debug( "TCP Transport created : <{}:{},>", address, tcpPort );
138 }
139
140
141
142
143
144 public void init()
145 {
146 acceptor = createAcceptor( getAddress(), getPort(), getNbThreads(), getBackLog() );
147 }
148
149
150
151
152
153 private IoAcceptor createAcceptor( String address, int port, int nbThreads, int backLog )
154 {
155 NioSocketAcceptor acceptor = new NioSocketAcceptor( nbThreads );
156 acceptor.setReuseAddress( true );
157 acceptor.setBacklog( backLog );
158
159 InetSocketAddress socketAddress = null;
160
161
162 if ( address == null )
163 {
164
165 socketAddress = new InetSocketAddress( port );
166 }
167 else
168 {
169 socketAddress = new InetSocketAddress( address, port );
170 }
171
172 acceptor.setDefaultLocalAddress( socketAddress );
173
174 return acceptor;
175 }
176
177
178
179
180
181 public SocketAcceptor getAcceptor()
182 {
183 if ( ( acceptor != null ) && acceptor.isDisposed() )
184 {
185 acceptor = createAcceptor( getAddress(), getPort(), getNbThreads(), getBackLog() );
186 }
187
188 return acceptor == null ? null : ( SocketAcceptor ) acceptor;
189 }
190
191
192
193
194
195
196
197 public void setNeedClientAuth( boolean needClientAuth )
198 {
199 this.needClientAuth = needClientAuth;
200 }
201
202
203
204
205
206 public boolean isNeedClientAuth()
207 {
208 return needClientAuth;
209 }
210
211
212
213
214
215
216
217 public void setWantClientAuth( boolean wantClientAuth )
218 {
219 this.wantClientAuth = wantClientAuth;
220 }
221
222
223
224
225
226 public boolean isWantClientAuth()
227 {
228 return wantClientAuth;
229 }
230
231
232
233
234
235 public List<String> getEnabledProtocols()
236 {
237 return enabledProtocols;
238 }
239
240
241
242
243
244
245
246 public void setEnabledProtocols( List<String> enabledProtocols )
247 {
248 this.enabledProtocols = enabledProtocols;
249 }
250
251
252
253
254
255 public List<String> getCipherSuite()
256 {
257 return cipherSuite;
258 }
259
260
261
262
263
264
265
266 public void setEnabledCiphers( List<String> cipherSuite )
267 {
268 this.cipherSuite = cipherSuite;
269 }
270
271
272
273
274
275 @Override
276 public String toString()
277 {
278 return "TcpTransport" + super.toString();
279 }
280 }