Github user epahomov commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1107#discussion_r13908739
  
    --- Diff: core/src/main/scala/org/apache/spark/HttpServer.scala ---
    @@ -41,45 +41,73 @@ private[spark] class ServerStateException(message: 
String) extends Exception(mes
      * as well as classes created by the interpreter when the user types in 
code. This is just a wrapper
      * around a Jetty server.
      */
    -private[spark] class HttpServer(resourceBase: File, securityManager: 
SecurityManager)
    -    extends Logging {
    +private[spark] class HttpServer(resourceBase: File,
    +                                securityManager: SecurityManager,
    +                                localPort: Int = 0) extends Logging {
       private var server: Server = null
    -  private var port: Int = -1
    +  private var port: Int = localPort
    +
    +  private def startOnPort(startPort: Int): Tuple2[Server,Int] = {
    +    val server = new Server()
    +    val connector = new SocketConnector
    +    connector.setMaxIdleTime(60*1000)
    +    connector.setSoLingerTime(-1)
    +    connector.setPort(startPort)
    +    server.addConnector(connector)
    +
    +    val threadPool = new QueuedThreadPool
    +    threadPool.setDaemon(true)
    +    server.setThreadPool(threadPool)
    +    val resHandler = new ResourceHandler
    +    resHandler.setResourceBase(resourceBase.getAbsolutePath)
    +
    +    val handlerList = new HandlerList
    +    handlerList.setHandlers(Array(resHandler, new DefaultHandler))
    +
    +    if (securityManager.isAuthenticationEnabled()) {
    +      logDebug("HttpServer is using security")
    +      val sh = setupSecurityHandler(securityManager)
    +      // make sure we go through security handler to get resources
    +      sh.setHandler(handlerList)
    +      server.setHandler(sh)
    +    } else {
    +      logDebug("HttpServer is not using security")
    +      server.setHandler(handlerList)
    +    }
    +
    +    server.start()
    +    val actualPort = server.getConnectors()(0).getLocalPort()
    +
    +    return (server, actualPort)
    +  }
    +
    +  private def startWithIncrements(startPort: Int, maxRetries: Int): 
Tuple2[Server,Int] = {
    +    for( offset <- 0 to maxRetries) {
    --- End diff --
    
    code about selecting port to start I can see twice. Let encapsulate it in 
single method


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to