Skip to content

Commit

Permalink
Trust the server start function to report the port the service starte…
Browse files Browse the repository at this point in the history
…d on
  • Loading branch information
ash211 committed Jul 25, 2014
1 parent 7c5bdc4 commit 038a579
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions core/src/main/scala/org/apache/spark/HttpServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private[spark] class HttpServer(resourceBase: File,
private var server: Server = null
private var port: Int = localPort

private def startOnPort(startPort: Int): Server = {
private def startOnPort(startPort: Int): (Server, Int) = {
val server = new Server()
val connector = new SocketConnector
connector.setMaxIdleTime(60*1000)
Expand Down Expand Up @@ -79,7 +79,7 @@ private[spark] class HttpServer(resourceBase: File,
server.start()
val actualPort = server.getConnectors()(0).getLocalPort()

server
(server, actualPort)
}

def start() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private[spark] class ConnectionManager(port: Int, conf: SparkConf,

private def startService(port: Int) = {
serverChannel.socket.bind(new InetSocketAddress(port))
serverChannel
(serverChannel, port)
}
PortManager.startWithIncrements(port, 3, startService)
serverChannel.register(selector, SelectionKey.OP_ACCEPT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ private[spark] object PortManager extends Logging
* @throws SparkException When unable to start service in the given number of attempts
* @return
*/
def startWithIncrements[T](startPort: Int, maxRetries: Int, startService: Int => T):
def startWithIncrements[T](startPort: Int, maxRetries: Int, startService: Int => (T, Int)):
(T, Int) = {
for( offset <- 0 to maxRetries) {
val tryPort = startPort + offset
try {
val service: T = startService(tryPort)
return (service, tryPort)
return startService(tryPort)
} catch {
case e: java.net.BindException => {
if (!e.getMessage.contains("Address already in use") ||
Expand Down

0 comments on commit 038a579

Please sign in to comment.