public void run() {
int errorDelay = 0;
// Loop until we receive a shutdown command
while (running) {
// Loop if endpoint is paused
while (paused && running) {
state = AcceptorState.PAUSED;
try {
Thread.sleep(50);
} catch (InterruptedException e) {
// Ignore
}
}
if (!running) {
break;
}
state = AcceptorState.RUNNING;
try {
//if we have reached max connections, wait
countUpOrAwaitConnection();
long socket = 0;
try {
// Accept the next incoming connection from the server
// socket
socket = Socket.accept(serverSock);
} catch (Exception e) {
//we didn't get a socket
countDownConnection();
// Introduce delay if necessary
errorDelay = handleExceptionWithDelay(errorDelay);
// re-throw
throw e;
}
// Successful accept, reset the error delay
errorDelay = 0;
if (running && !paused) {
// Hand this socket off to an appropriate processor
if (!processSocketWithOptions(socket)) {
// Close socket and pool right away
destroySocket(socket);
}
} else {
// Close socket and pool right away
destroySocket(socket);
}
} catch (Throwable t) {
....
}
// The processor will recycle itself when it finishes
}
state = AcceptorState.ENDED;
}