private boolean processOneRequest(Socket socket,InputStream in,OutputStream out) throws IOException, InterruptedException {
  RecordedRequest request=readRequest(socket,in,sequenceNumber);
  if (request == null) {
    return false;
  }
  requestCount.incrementAndGet();
  requestQueue.add(request);
  MockResponse response=dispatcher.dispatch(request);
  if (response.getSocketPolicy() == SocketPolicy.DISCONNECT_AFTER_READING_REQUEST) {
    logger.info("Received request: " + request + " and disconnected without responding");
    return false;
  }
  writeResponse(out,response);
  if (response.getSocketPolicy() == SocketPolicy.DISCONNECT_AT_END) {
    in.close();
    out.close();
  }
 else   if (response.getSocketPolicy() == SocketPolicy.SHUTDOWN_INPUT_AT_END) {
    socket.shutdownInput();
  }
 else   if (response.getSocketPolicy() == SocketPolicy.SHUTDOWN_OUTPUT_AT_END) {
    socket.shutdownOutput();
  }
  logger.info("Received request: " + request + " and responded: "+ response);
  sequenceNumber++;
  return true;
}

private boolean processOneRequest ( Socket socket , InputStream in , OutputStream out ) throws IOException , InterruptedException { RecordedRequest request = readRequest ( socket , in , sequenceNumber ) ; if ( request == null ) { return false ; } requestCount . incrementAndGet ( ) ; requestQueue . add ( request ) ; MockResponse response = dispatcher . dispatch ( request ) ; if ( response . getSocketPolicy ( ) == SocketPolicy . DISCONNECT_AFTER_READING_REQUEST ) { logger . info ( "Received request: " + request + " and disconnected without responding" ) ; return false ; } writeResponse ( out , response ) ; if ( response . getSocketPolicy ( ) == SocketPolicy . DISCONNECT_AT_END ) { in . close ( ) ; out . close ( ) ; } else if ( response . getSocketPolicy ( ) == SocketPolicy . SHUTDOWN_INPUT_AT_END ) { socket . shutdownInput ( ) ; } else if ( response . getSocketPolicy ( ) == SocketPolicy . SHUTDOWN_OUTPUT_AT_END ) { socket . shutdownOutput ( ) ; } logger . info ( "Received request: " + request + " and responded: " + response ) ; sequenceNumber ++ ; return true ; }
reads a request and writes its response . returns true if a request was processed .
