geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/AcceptorImpl.java
@Override
  public void accept() {
    while (isRunning()) {
      if (SystemFailure.getFailure() != null) {
        // Allocate no objects here!
        ServerSocket s = serverSock;
        if (s != null) {
          try {
            s.close();
          } catch (IOException e) {
            // don't care
          }
        }
        SystemFailure.checkFailure(); // throws
      }
      // moved this check out of the try. If we are cancelled then we need
      // to break out of this while loop.

      crHelper.checkCancelInProgress(null); // throws

      Socket socket = null;
      try {
        socket = serverSock.accept();
        crHelper.checkCancelInProgress(null); // throws

        // Optionally enable SO_KEEPALIVE in the OS network protocol.
        socket.setKeepAlive(SocketCreator.ENABLE_TCP_KEEP_ALIVE);

        // The synchronization below was added to prevent close from being
        // called
        // while a ServerConnection is being instantiated. This should prevent
        // the
        // following exception:
        // [severe 2004/12/15 18:49:17.671 PST gemfire2 Server connection from
        // balrog.gemstone.com:58478-0x6ce1 nid=0x1334aa] Uncaught exception in
        // thread Server connection from balrog.gemstone.com:58478
        // java.lang.NullPointerException
        // at
        // org.apache.geode.internal.cache.tier.sockets.ServerConnection.run(ServerConnection.java:107)

        synchronized (this.syncLock) {
          if (!isRunning()) {
            closeSocket(socket);
            break;
          }
        }
        this.loggedAcceptError = false;

        handOffNewClientConnection(socket, serverConnectionFactory);
      } catch (InterruptedIOException e) { // Solaris only
        closeSocket(socket);
        if (isRunning()) {
          if (logger.isDebugEnabled()) {
            logger.debug("Aborted due to interrupt: {}", e);
          }
        }
      } catch (IOException e) {
        closeSocket(socket);
        if (isRunning()) {
          if (!this.loggedAcceptError) {
            this.loggedAcceptError = true;
            logger.error(LocalizedMessage.create(
                LocalizedStrings.AcceptorImpl_CACHE_SERVER_UNEXPECTED_IOEXCEPTION_FROM_ACCEPT, e));
          }
          // Why sleep?
          // try {Thread.sleep(3000);} catch (InterruptedException ie) {}
        }
      } catch (CancelException e) {
        closeSocket(socket);
        throw e;
      } catch (Exception e) {
        closeSocket(socket);
        if (isRunning()) {
          logger.fatal(LocalizedMessage
              .create(LocalizedStrings.AcceptorImpl_CACHE_SERVER_UNEXPECTED_EXCEPTION, e));
        }
      }
    }
  }
/**
   * {@linkplain ServerSocket#accept Listens}for a client to connect and then creates a new
   * {@link ServerConnection}to handle messages from that client.
   */
ServerSocket#accept Listensfor a client to connect and then creates a new
ServerConnectionto handle messages from that client.
ServerSocket#accept Listensfor a client to connect and then creates a new ServerConnectionto handle messages from that client .
@Override
  public void accept() {
    while (isRunning()) {
      if (SystemFailure.getFailure() != null) {
        ServerSocket s = serverSock;
        if (s != null) {
          try {
            s.close();
          } catch (IOException e) {
          }
        }
        SystemFailure.checkFailure(); 
      }
      crHelper.checkCancelInProgress(null); 
      Socket socket = null;
      try {
        socket = serverSock.accept();
        crHelper.checkCancelInProgress(null); 
        socket.setKeepAlive(SocketCreator.ENABLE_TCP_KEEP_ALIVE);
        synchronized (this.syncLock) {
          if (!isRunning()) {
            closeSocket(socket);
            break;
          }
        }
        this.loggedAcceptError = false;
        handOffNewClientConnection(socket, serverConnectionFactory);
      } catch (InterruptedIOException e) { 
        closeSocket(socket);
        if (isRunning()) {
          if (logger.isDebugEnabled()) {
            logger.debug("Aborted due to interrupt: {}", e);
          }
        }
      } catch (IOException e) {
        closeSocket(socket);
        if (isRunning()) {
          if (!this.loggedAcceptError) {
            this.loggedAcceptError = true;
            logger.error(LocalizedMessage.create(
                LocalizedStrings.AcceptorImpl_CACHE_SERVER_UNEXPECTED_IOEXCEPTION_FROM_ACCEPT, e));
          }
        }
      } catch (CancelException e) {
        closeSocket(socket);
        throw e;
      } catch (Exception e) {
        closeSocket(socket);
        if (isRunning()) {
          logger.fatal(LocalizedMessage
              .create(LocalizedStrings.AcceptorImpl_CACHE_SERVER_UNEXPECTED_EXCEPTION, e));
        }
      }
    }
  }
@ Override public void accept ( ) { while ( isRunning ( ) ) { if ( SystemFailure . getFailure ( ) != null ) { ServerSocket s = serverSock ; if ( s != null ) { try { s . close ( ) ; } catch ( IOException e ) { } } SystemFailure . checkFailure ( ) ; } crHelper . checkCancelInProgress ( null ) ; Socket socket = null ; try { socket = serverSock . accept ( ) ; crHelper . checkCancelInProgress ( null ) ; socket . setKeepAlive ( SocketCreator . ENABLE_TCP_KEEP_ALIVE ) ; synchronized ( this . syncLock ) { if ( ! isRunning ( ) ) { closeSocket ( socket ) ; break ; } } this . loggedAcceptError = false ; handOffNewClientConnection ( socket , serverConnectionFactory ) ; } catch ( InterruptedIOException e ) { closeSocket ( socket ) ; if ( isRunning ( ) ) { if ( logger . isDebugEnabled ( ) ) { logger . debug ( "Aborted due to interrupt: {}" , e ) ; } } } catch ( IOException e ) { closeSocket ( socket ) ; if ( isRunning ( ) ) { if ( ! this . loggedAcceptError ) { this . loggedAcceptError = true ; logger . error ( LocalizedMessage . create ( LocalizedStrings . AcceptorImpl_CACHE_SERVER_UNEXPECTED_IOEXCEPTION_FROM_ACCEPT , e ) ) ; } } } catch ( CancelException e ) { closeSocket ( socket ) ; throw e ; } catch ( Exception e ) { closeSocket ( socket ) ; if ( isRunning ( ) ) { logger . fatal ( LocalizedMessage . create ( LocalizedStrings . AcceptorImpl_CACHE_SERVER_UNEXPECTED_EXCEPTION , e ) ) ; } } } }
{@linkplain ServerSocket#accept Listens}for a client to connect and then creates a new
 {@link ServerConnection}to handle messages from that client.
{ @linkplain ServerSocket#accept Listens } for a client to connect and then creates a new { @link ServerConnection } to handle messages from that client .
// Allocate no objects here! // don't care // throws // moved this check out of the try. If we are cancelled then we need // to break out of this while loop. // throws // throws // Optionally enable SO_KEEPALIVE in the OS network protocol. // The synchronization below was added to prevent close from being // called // while a ServerConnection is being instantiated. This should prevent // the // following exception: // [severe 2004/12/15 18:49:17.671 PST gemfire2 Server connection from // balrog.gemstone.com:58478-0x6ce1 nid=0x1334aa] Uncaught exception in // thread Server connection from balrog.gemstone.com:58478 // java.lang.NullPointerException // at // org.apache.geode.internal.cache.tier.sockets.ServerConnection.run(ServerConnection.java:107) // Solaris only // Why sleep? // try {Thread.sleep(3000);} catch (InterruptedException ie) {}