Github user ash211 commented on a diff in the pull request:
https://github.com/apache/spark/pull/1107#discussion_r13955228
--- 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 --
Agreed. It's slightly tricky since starting the service is slightly
different between the Jetty server and the raw socket, but I think I can wrap
the side effects up with a parametrized function on the method and make it work
Something like:
```startWithIncrements[T](startPort: Int, maxRetries: Int, startListening:
Unit => T) : Tuple2[T,Int] = {```
Does that sound right?
I'm not going to be able to work on this for a bit so if you'd like to take
a whack go for it. Otherwise I may have something late on Friday.
---
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 [email protected] or file a JIRA ticket
with INFRA.
---