Add {@link Consumer}s invoked when the {@link Server} is stopping.
(see: {@link ServerListener#serverStopping(Server)})
172007
@SafeVarargs
    public final ServerListenerBuilder addStoppingCallbacks(Consumer<? super Server>... consumers) {
        return addStoppingCallbacks(Arrays.asList(consumers));
    }
1289378
public synchronized void onServerUnavailable(final String id) {
        logger.debug("[onServerUnavailable] id = {}", id);

        Server server = getServerById(id);

        if (server != null) {
            server.setAvailable(false);
            refreshServers();
        }
    }
165512
synchronized void setServerProcessStopping() {
        this.requiredState = InternalState.STOPPED;
        internalSetState(null, InternalState.STOPPED, InternalState.PROCESS_STOPPING);
    }
876905
@Override
  public void stop() {
    logger().log("Server stopping...");

    failTimedOutMissingContentRequests();

    channel.stop();
    channel.close();

    for (final Dispatcher dispatcher : dispatcherPool) {
      dispatcher.stop();
    }

    logger().log("Server stopped.");

    super.stop();
  }
637346
public synchronized void serverStopping() {
        if (tc.isEntryEnabled())
            Tr.entry(tc, "serverStopping ", new Object[] { this });

        _serverStopping = true;

        Statement lockingStmt = null;
        String queryString = "";
        ResultSet nonLockingRS = null;
        // Need to establish a reserved connection at this point that can be used in log close processing.
        try {
            _reservedConn = _theDS.getConnection();

            // The BPM Test team found a case where this connection could be stale - a failover had been performed but no recovery log
            // work had been done up to the point where the server stopped. So we'll just check that it isn't stale.
            lockingStmt = _reservedConn.createStatement();
            // Use RDBMS SELECT FOR UPDATE to lock table for recovery
            queryString = "SELECT SERVER_NAME" +
                          " FROM " + _recoveryTableName + _logIdentifierString + _recoveryTableNameSuffix +
                          " WHERE RU_ID=" + "-1";
            if (tc.isDebugEnabled())
                Tr.debug(tc, "Attempt to select the HA LOCKING ROW BUT NOT for UPDATE - " + queryString);
            nonLockingRS = lockingStmt.executeQuery(queryString);
            if (!nonLockingRS.next())
                if (tc.isDebugEnabled())
                    Tr.debug(tc, "HA Locking row was NOT found");
                else if (tc.isDebugEnabled())
                    Tr.debug(tc, "HA Locking row was found");
            lockingStmt.close();
            _reservedConn.commit();
        } catch (SQLException sqlex) {
            Throwable theNonTransientException = sqlex;
            Tr.audit(tc, "WTRN0107W: " +
                         "Caught SQLException when server stopping for SQL RecoveryLog " + _logName + " for server " + _serverName + " SQLException: " + sqlex);
            // Should we attempt to reconnect? This method works through the set of SQL exceptions and will
            // return TRUE if we determine that an transient DB error has occurred
            boolean retryBatch = sqlTransientErrorHandlingEnabled && isSQLErrorTransient(sqlex);
            boolean failAndReport = true;
            if (retryBatch) {
                if (tc.isDebugEnabled())
                    Tr.debug(tc, "Try to reexecute the SQL using connection from DS: " + _theDS);

                // Re-execute the SQL
                try {
                    // Get a connection to database via its datasource
                    _reservedConn = _theDS.getConnection();
                    lockingStmt = _reservedConn.createStatement();
                    nonLockingRS = lockingStmt.executeQuery(queryString);
                    if (!nonLockingRS.next())
                        if (tc.isDebugEnabled())
                            Tr.debug(tc, "HA Locking row was NOT found");
                        else if (tc.isDebugEnabled())
                            Tr.debug(tc, "HA Locking row was found");
                    lockingStmt.close();
                    _reservedConn.commit();
                    failAndReport = false;
                } catch (SQLException sqlex2) {
                    // We've caught another SQLException. Assume that we've retried the connection too soon.
                    // Make sure we inspect the latest exception
                    if (tc.isDebugEnabled())
                        Tr.debug(tc, "reset the sqlex to " + sqlex2);
                    theNonTransientException = sqlex2;
                } catch (Throwable exc) {
                    // Not a SQLException, break out of the loop and report the exception
                    if (tc.isDebugEnabled())
                        Tr.debug(tc, "Failed got exception: " + exc);

                    for (StackTraceElement ste : Thread.currentThread().getStackTrace()) {
                        if (tc.isDebugEnabled())
                            Tr.debug(tc, " " + ste);
                    }

                    theNonTransientException = exc;
                }
            }

            if (failAndReport) {
                // Throw an FFDC, but allow processing to continue
                FFDCFilter.processException(theNonTransientException, "com.ibm.ws.recoverylog.spi.SQLMultiScopeRecoveryLog.serverStopping", "464", this);

                _reservedConn = null;

                if (tc.isEntryEnabled())
                    Tr.exit(tc, "serverStopping", theNonTransientException);
            }
        } finally {
            try {
                if (nonLockingRS != null && !nonLockingRS.isClosed())
                    nonLockingRS.close();
                if (lockingStmt != null && !lockingStmt.isClosed())
                    lockingStmt.close();
            } catch (SQLException e) {
                // Log close failure but allow processing to continue
                if (tc.isDebugEnabled())
                    Tr.debug(tc, "on closing SQL resources caught exception: " + e);
            }
        }

        if (tc.isEntryEnabled())
            Tr.exit(tc, "serverStopping");
    }
474766
public Listener<CopycatServer.State> onStateChange(Consumer<CopycatServer.State> listener) {
    return stateChangeListeners.add(listener);
  }
336330
@Override
    public synchronized void stop(final StopContext context) {
        httpManagementConsumer.accept(null);
        ListenerRegistry lr = listenerRegistrySupplier.get();
        if(lr != null) {
            lr.removeListener(HTTP_MANAGEMENT);
            lr.removeListener(HTTPS_MANAGEMENT);
        }
        if (serverManagement != null) {
            try {
                serverManagement.stop();
            } finally {
                serverManagement = null;

                // Unregister sockets from the SBM
                if (socketBindingManager != null) {
                    ManagedBindingRegistry registry = useUnmanagedBindings ? socketBindingManager.getUnnamedRegistry() : socketBindingManager.getNamedRegistry();
                    if (basicManagedBinding != null) {
                        registry.unregisterBinding(basicManagedBinding);
                        basicManagedBinding = null;
                    }
                    if (secureManagedBinding != null) {
                        registry.unregisterBinding(secureManagedBinding);
                        secureManagedBinding = null;
                    }
                    socketBindingManager = null;
                    useUnmanagedBindings = false;
                }
            }
        }
    }
524118
@SafeVarargs
    public final ServerListenerBuilder addStoppedCallbacks(Consumer<? super Server>... consumers) {
        return addStoppedCallbacks(Arrays.asList(consumers));
    }
1370106
protected void startServerImpl() {
        SelendroidLogger.info("*** ServerInstrumentation#startServerImpl() ***");
        if (serverThread != null && serverThread.isAlive()) {
            return;
        }

        if (serverThread != null) {
            stopServer();
        }

        serverThread = new HttpdThread(this, serverPort);
        serverThread.startServer();
    }
516066
public void addServerSocket(
      InternalInstrumented<ServerStats> server, InternalInstrumented<SocketStats> socket) {
    ServerSocketMap serverSockets = perServerSockets.get(id(server));
    assert serverSockets != null;
    add(serverSockets, socket);
  }
240297
public void onStartWithServer(ExecutionContext<I> context, ExecutionInfo info) {
        for (ExecutionListener<I, O> listener: listeners) {
            try {
                if (!isListenerDisabled(listener)) {
                    listener.onStartWithServer(context.getChildContext(listener), info);
                }
            } catch (Throwable e) {
                if (e instanceof AbortExecutionException) {
                    throw (AbortExecutionException) e;
                }
                logger.error("Error invoking listener " + listener, e);
            }
        }
    }
1295010
public void addServerReadyConsumer(Consumer<Server> consumer) {
        synchronized (readyConsumers) {
            if (ready) {
                consumer.accept(this);
            } else {
                readyConsumers.add(consumer);
            }
        }
    }
40243
void addConsumer(ConsumerSessionImpl consumer) {
        if (TraceComponent.isAnyTracingEnabled()
            && tc.isEntryEnabled())
            SibTr.entry(tc, "addConsumer", consumer);

        _consumerList.add(consumer);

        if (TraceComponent.isAnyTracingEnabled()
            && tc.isEntryEnabled())
            SibTr.exit(tc, "addConsumer");
    }
251788
public void notifyShutdown() {
        if (m_shutdown.compareAndSet(false, true)) {
            for (KafkaExternalConsumerRunner consumer : m_consumers) {
                consumer.shutdown();
            }
            close();
        }
    }
247533
public void stopAndJoin() {
    interrupt();
    if (mServerSocket != null) {
      try {
        mServerSocket.close();
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    }
    try {
      join(5 * Constants.SECOND_MS);
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
    }
    if (isAlive()) {
      LOG.warn("Failed to stop rejecting server thread");
    }
  }
1214552
@Override
  public ServerImpl shutdown() {
    boolean shutdownTransportServers;
    synchronized (lock) {
      if (shutdown) {
        return this;
      }
      shutdown = true;
      shutdownTransportServers = started;
      if (!shutdownTransportServers) {
        transportServersTerminated = true;
        checkForTermination();
      }
    }
    if (shutdownTransportServers) {
      for (InternalServer ts : transportServers) {
        ts.shutdown();
      }
    }
    return this;
  }
708720
protected synchronized void setStopping(boolean stopping) {
        final String methodName = "setStopping()";
        this.stopping = stopping;
        traceDebug(methodName, "cacheName=" + this.cod.cacheName + " stopping=" + this.stopping);
    }