@@ -61,24 +61,24 @@ private[spark] abstract class WebUI(
6161 def getSecurityManager : SecurityManager = securityManager
6262
6363 /** Attaches a tab to this UI, along with all of its attached pages. */
64- def attachTab (tab : WebUITab ) {
64+ def attachTab (tab : WebUITab ): Unit = {
6565 tab.pages.foreach(attachPage)
6666 tabs += tab
6767 }
6868
69- /** Detaches a tab from this UI. */
70- def detachTab (tab : WebUITab ) {
69+ /** Detaches a tab from this UI, along with all of its attached pages . */
70+ def detachTab (tab : WebUITab ): Unit = {
7171 tab.pages.foreach(detachPage)
7272 tabs -= tab
7373 }
7474
75- /** Detaches a page from this UI. */
76- def detachPage (page : WebUIPage ) {
75+ /** Detaches a page from this UI, along with all of its attached handlers . */
76+ def detachPage (page : WebUIPage ): Unit = {
7777 pageToHandlers.remove(page).foreach(_.foreach(detachHandler))
7878 }
7979
8080 /** Attaches a page to this UI. */
81- def attachPage (page : WebUIPage ) {
81+ def attachPage (page : WebUIPage ): Unit = {
8282 val pagePath = " /" + page.prefix
8383 val renderHandler = createServletHandler(pagePath,
8484 (request : HttpServletRequest ) => page.render(request), securityManager, conf, basePath)
@@ -91,17 +91,26 @@ private[spark] abstract class WebUI(
9191 }
9292
9393 /** Attaches a handler to this UI. */
94- def attachHandler (handler : ServletContextHandler ) {
94+ def attachHandler (handler : ServletContextHandler ): Unit = {
9595 handlers += handler
9696 serverInfo.foreach(_.addHandler(handler))
9797 }
9898
9999 /** Detaches a handler from this UI. */
100- def detachHandler (handler : ServletContextHandler ) {
100+ def detachHandler (handler : ServletContextHandler ): Unit = {
101101 handlers -= handler
102102 serverInfo.foreach(_.removeHandler(handler))
103103 }
104104
105+ /**
106+ * Detaches the content handler at `path` URI.
107+ *
108+ * @param path Path in UI to unmount.
109+ */
110+ def detachHandler (path : String ): Unit = {
111+ handlers.find(_.getContextPath() == path).foreach(detachHandler)
112+ }
113+
105114 /**
106115 * Adds a handler for static content.
107116 *
@@ -112,16 +121,7 @@ private[spark] abstract class WebUI(
112121 attachHandler(JettyUtils .createStaticHandler(resourceBase, path))
113122 }
114123
115- /**
116- * Removes a static content handler.
117- *
118- * @param path Path in UI to unmount.
119- */
120- def removeStaticHandler (path : String ): Unit = {
121- handlers.find(_.getContextPath() == path).foreach(detachHandler)
122- }
123-
124- /** Initializes all components of the server. */
124+ /** A hook to initialize components of the UI */
125125 def initialize (): Unit
126126
127127 /** Binds to the HTTP server behind this web interface. */
@@ -141,14 +141,14 @@ private[spark] abstract class WebUI(
141141 /** @return The url of web interface. Only valid after [[bind ]]. */
142142 def webUrl : String = s " http:// $publicHostName: $boundPort"
143143
144- /** @return The actual port to which this server is bound. Only valid after bind() . */
144+ /** @return The actual port to which this server is bound. Only valid after [[ bind ]] . */
145145 def boundPort : Int = serverInfo.map(_.boundPort).getOrElse(- 1 )
146146
147147 /** Stops the server behind this web interface. Only valid after [[bind ]]. */
148148 def stop (): Unit = {
149149 assert(serverInfo.isDefined,
150150 s " Attempted to stop $className before binding to a server! " )
151- serverInfo.get .stop()
151+ serverInfo.foreach(_ .stop() )
152152 }
153153}
154154
0 commit comments