ServerConnection clientConnection = new ServerConnection(client, timeout); Thread clientThread = factory.newThread(clientConnection); clientConnection.setConnectionThread(clientThread); synchronized (clients) { clients.add(clientConnection);
timeout.cancel(); close(); if (handle != null) { handle.dispose();
timeout.cancel(); close(); if (handle != null) { handle.dispose();
timeout.cancel(); close(); } finally { timeoutTimer.purge();
timeout.cancel(); close(); } finally { timeoutTimer.purge();
ServerConnection clientConnection = new ServerConnection(client, timeout); Thread clientThread = factory.newThread(clientConnection); synchronized (timeout) {
ServerConnection clientConnection = new ServerConnection(client, timeout); Thread clientThread = factory.newThread(clientConnection); synchronized (clients) {
ServerConnection clientConnection = new ServerConnection(client, timeout); Thread clientThread = factory.newThread(clientConnection); clientConnection.setConnectionThread(clientThread); synchronized (clients) { clients.add(clientConnection);
@Override public void close() throws IOException { synchronized (this) { if (!running) { return; } running = false; } synchronized(LauncherServer.class) { serverInstance = null; } timeoutTimer.cancel(); server.close(); synchronized (clients) { List<ServerConnection> copy = new ArrayList<>(clients); clients.clear(); for (ServerConnection client : copy) { client.close(); } } if (serverThread != null) { try { serverThread.join(); } catch (InterruptedException ie) { // no-op } } }
@Override public void close() throws IOException { synchronized (this) { if (!running) { return; } running = false; } synchronized(LauncherServer.class) { serverInstance = null; } timeoutTimer.cancel(); server.close(); synchronized (clients) { List<ServerConnection> copy = new ArrayList<>(clients); clients.clear(); for (ServerConnection client : copy) { client.close(); } } if (serverThread != null) { try { serverThread.join(); } catch (InterruptedException ie) { // no-op } } }
/** * Mark the handle as disposed, and set it as LOST in case the current state is not final. * * This method should be called only when there's a reasonable expectation that the communication * with the child application is not needed anymore, either because the code managing the handle * has said so, or because the child application is finished. */ synchronized void dispose() { if (!isDisposed()) { // First wait for all data from the connection to be read. Then unregister the handle. // Otherwise, unregistering might cause the server to be stopped and all child connections // to be closed. if (connection != null) { try { connection.waitForClose(); } catch (IOException ioe) { // no-op. } } server.unregister(this); // Set state to LOST if not yet final. setState(State.LOST, false); this.disposed = true; } }
/** * Wait for the remote side to close the connection so that any pending data is processed. * This ensures any changes reported by the child application take effect. * * This method allows a short period for the above to happen (same amount of time as the * connection timeout, which is configurable). This should be fine for well-behaved * applications, where they close the connection arond the same time the app handle detects the * app has finished. * * In case the connection is not closed within the grace period, this method forcefully closes * it and any subsequent data that may arrive will be ignored. */ public void waitForClose() throws IOException { Thread connThread = this.connectionThread; if (Thread.currentThread() != connThread) { try { connThread.join(getConnectionTimeout()); } catch (InterruptedException ie) { // Ignore. } if (connThread.isAlive()) { LOG.log(Level.WARNING, "Timed out waiting for child connection to close."); close(); } } }
/** * Wait for the remote side to close the connection so that any pending data is processed. * This ensures any changes reported by the child application take effect. * * This method allows a short period for the above to happen (same amount of time as the * connection timeout, which is configurable). This should be fine for well-behaved * applications, where they close the connection arond the same time the app handle detects the * app has finished. * * In case the connection is not closed within the grace period, this method forcefully closes * it and any subsequent data that may arrive will be ignored. */ public void waitForClose() throws IOException { Thread connThread = this.connectionThread; if (Thread.currentThread() != connThread) { try { connThread.join(getConnectionTimeout()); } catch (InterruptedException ie) { // Ignore. } if (connThread.isAlive()) { LOG.log(Level.WARNING, "Timed out waiting for child connection to close."); close(); } } }
/** * Mark the handle as disposed, and set it as LOST in case the current state is not final. * * This method should be called only when there's a reasonable expectation that the communication * with the child application is not needed anymore, either because the code managing the handle * has said so, or because the child application is finished. */ synchronized void dispose() { if (!isDisposed()) { // First wait for all data from the connection to be read. Then unregister the handle. // Otherwise, unregistering might cause the server to be stopped and all child connections // to be closed. if (connection != null) { try { connection.waitForClose(); } catch (IOException ioe) { // no-op. } } server.unregister(this); // Set state to LOST if not yet final. setState(State.LOST, false); this.disposed = true; } }
@Override public void close() throws IOException { synchronized (this) { if (running) { running = false; timeoutTimer.cancel(); server.close(); synchronized (clients) { List<ServerConnection> copy = new ArrayList<>(clients); clients.clear(); for (ServerConnection client : copy) { client.close(); } } } } if (serverThread != null) { try { serverThread.join(); } catch (InterruptedException ie) { // no-op } } }
@Override public void close() throws IOException { synchronized (this) { if (running) { running = false; timeoutTimer.cancel(); server.close(); synchronized (clients) { List<ServerConnection> copy = new ArrayList<>(clients); clients.clear(); for (ServerConnection client : copy) { client.close(); } } } } if (serverThread != null) { try { serverThread.join(); } catch (InterruptedException ie) { // no-op } } }
@Override public void close() throws IOException { if (!isOpen()) { return; } synchronized (clients) { clients.remove(this); } super.close(); }
@Override public void close() throws IOException { if (!isOpen()) { return; } synchronized (clients) { clients.remove(this); } super.close(); }