protected void doStop() throws Exception { // lets stop accepting new connections first if (serverSocket != null) { serverSocket.close(); } // now lets close all the connections try { for (TcpTransport connection : connections) { connection.stop(); } } finally { connections.clear(); } // lets join the server thread in case its blocked a little while if (runner != null && joinOnStop) { join(); runner = null; } }
/** pull Sockets from the ServerSocket */ public void run() { while (!isStopped()) { Socket socket = null; try { socket = serverSocket.accept(); if (socket != null) { if (isStopped()) { socket.close(); } else { TcpTransport transport = createTransport(socket); connectHandlers(transport); transport.start(); connections.add(transport); } } } catch (SocketTimeoutException ste) { // expect this to happen } catch (Exception e) { if (!isStopping() && !isStopped()) { onAcceptError(e); } } } }
protected void connectHandlers(TcpTransport transport) throws Exception { StompHandler inputHandler = stompHandlerFactory.createStompHandler(transport); transport.setInputHandler(inputHandler); }