|
Lines 15-20
Link Here
|
| 15 |
import java.io.IOException; |
15 |
import java.io.IOException; |
| 16 |
import java.net.BindException; |
16 |
import java.net.BindException; |
| 17 |
import java.net.InetSocketAddress; |
17 |
import java.net.InetSocketAddress; |
|
|
18 |
import java.net.ServerSocket; |
| 19 |
import java.net.Socket; |
| 18 |
import java.nio.channels.ServerSocketChannel; |
20 |
import java.nio.channels.ServerSocketChannel; |
| 19 |
import java.nio.channels.SocketChannel; |
21 |
import java.nio.channels.SocketChannel; |
| 20 |
|
22 |
|
|
Lines 67-73
Link Here
|
| 67 |
* in typical use via the agent controller it is a singleton in practice, |
69 |
* in typical use via the agent controller it is a singleton in practice, |
| 68 |
* every instance must have its own unique port to accept connections on |
70 |
* every instance must have its own unique port to accept connections on |
| 69 |
*/ |
71 |
*/ |
| 70 |
private ServerSocketChannel serverSocket; |
72 |
// private ServerSocketChannel serverSocketChannel; |
|
|
73 |
|
| 74 |
private ServerSocket serverSocket; |
| 75 |
|
| 71 |
|
76 |
|
| 72 |
/** |
77 |
/** |
| 73 |
* The file server status |
78 |
* The file server status |
|
Lines 102-109
Link Here
|
| 102 |
*/ |
107 |
*/ |
| 103 |
private void cleanup() { |
108 |
private void cleanup() { |
| 104 |
try { |
109 |
try { |
|
|
110 |
|
| 105 |
this.serverSocket.close(); |
111 |
this.serverSocket.close(); |
| 106 |
this.serverSocket = null; |
112 |
serverSocket = null; |
|
|
113 |
|
| 114 |
// this.serverSocketChannel.close(); |
| 115 |
// this.serverSocketChannel = null; |
| 107 |
this.parameters = null; |
116 |
this.parameters = null; |
| 108 |
} catch (IOException e) { |
117 |
} catch (IOException e) { |
| 109 |
// |
118 |
// |
|
Lines 209-224
Link Here
|
| 209 |
// Continue to hold lock until initialized, then notify waiters |
218 |
// Continue to hold lock until initialized, then notify waiters |
| 210 |
synchronized (this) { |
219 |
synchronized (this) { |
| 211 |
|
220 |
|
| 212 |
// Establish file server using a java.nio server channel |
221 |
initServerSocket(); |
| 213 |
this.serverSocket = ServerSocketChannel.open(); |
|
|
| 214 |
this.serverSocket.configureBlocking(true); |
| 215 |
|
| 216 |
// Set server socket timeout and bind to port |
| 217 |
this.serverSocket.socket().setSoTimeout(DEFAULT_SOCKET_TIMEOUT); |
| 218 |
this.serverSocket.socket().bind(new InetSocketAddress(this.getPort())); |
| 219 |
|
| 220 |
// Store the file server port to be used for the file server |
| 221 |
FileServer.setServerPort(this.serverSocket.socket().getLocalPort()); |
| 222 |
|
222 |
|
| 223 |
// Change state to initialized and notify any waiters |
223 |
// Change state to initialized and notify any waiters |
| 224 |
this.initStatus = FileServiceConstants.RA_FS_INITIALIZED; |
224 |
this.initStatus = FileServiceConstants.RA_FS_INITIALIZED; |
|
Lines 240-258
Link Here
|
| 240 |
while (!this.shutdown) { |
240 |
while (!this.shutdown) { |
| 241 |
|
241 |
|
| 242 |
// Output debug output |
242 |
// Output debug output |
| 243 |
FileSystemServices.println(NLS.bind(LocalResourceBundle.FileServerExtended_EXTENDED_FILE_SERVER_LISTENING_, String.valueOf(this.getPort())), |
243 |
FileSystemServices.println(NLS.bind(LocalResourceBundle.FileServerExtended_EXTENDED_FILE_SERVER_LISTENING_, String.valueOf(this.getPort())), this); |
| 244 |
this); |
|
|
| 245 |
|
244 |
|
| 246 |
// Block until connection is requested on known port |
245 |
// Block until connection is requested on known port |
| 247 |
SocketChannel clientChannel = this.serverSocket.accept(); |
246 |
Socket s = this.serverSocket.accept(); |
| 248 |
|
247 |
|
| 249 |
// Set socket timeout to avoid blocking forever |
248 |
// Set socket timeout to avoid blocking forever |
| 250 |
clientChannel.socket().setSoTimeout(DEFAULT_SOCKET_TIMEOUT); |
249 |
s.setSoTimeout(DEFAULT_SOCKET_TIMEOUT); |
| 251 |
clientChannel.socket().setTcpNoDelay(true); |
250 |
s.setTcpNoDelay(true); |
| 252 |
|
251 |
|
| 253 |
// Take newly connected socket to client and send to handler |
252 |
// Take newly connected socket to client and send to handler |
| 254 |
IConnectionHandler handler = (IConnectionHandler) this.parameters.getConnectionHandler(); |
253 |
IConnectionHandler handler = (IConnectionHandler) this.parameters.getConnectionHandler(); |
| 255 |
handler.connectionAccepted(SocketChannelFactory.getInstance().create(clientChannel)); |
254 |
handler.connectionAccepted(SocketChannelFactory.getInstance().create(s)); |
| 256 |
|
255 |
|
| 257 |
} |
256 |
} |
| 258 |
|
257 |
|
|
Lines 287-295
Link Here
|
| 287 |
|
286 |
|
| 288 |
// Clean-up resources appropriately |
287 |
// Clean-up resources appropriately |
| 289 |
this.cleanup(); |
288 |
this.cleanup(); |
| 290 |
|
289 |
|
| 291 |
} |
290 |
} |
| 292 |
|
|
|
| 293 |
} |
291 |
} |
|
|
292 |
|
| 293 |
private void initServerSocket() throws IOException { |
| 294 |
|
| 295 |
this.serverSocket = new ServerSocket(this.getPort()); |
| 296 |
|
| 297 |
FileServer.setServerPort(this.serverSocket.getLocalPort()); |
| 298 |
} |
| 299 |
|
| 300 |
// private void oldInitIpv4SocketChannel() throws IOException { |
| 301 |
// |
| 302 |
// // Establish file server using a java.nio server channel |
| 303 |
// this.serverSocketChannel = ServerSocketChannel.open(); |
| 304 |
// this.serverSocketChannel.configureBlocking(true); |
| 305 |
// |
| 306 |
// // Set server socket timeout and bind to port |
| 307 |
// this.serverSocketChannel.socket().setSoTimeout(DEFAULT_SOCKET_TIMEOUT); |
| 308 |
// this.serverSocketChannel.socket().bind(new InetSocketAddress(this.getPort())); |
| 309 |
// |
| 310 |
// // Store the file server port to be used for the file server |
| 311 |
// FileServer.setServerPort(this.serverSocketChannel.socket().getLocalPort()); |
| 312 |
// |
| 313 |
// } |
| 294 |
|
314 |
|
| 295 |
} |
315 |
} |