@@ -60,23 +60,25 @@ private[spark] abstract class WebUI(
60
60
def getHandlers : Seq [ServletContextHandler ] = handlers
61
61
def getSecurityManager : SecurityManager = securityManager
62
62
63
- /** Attach a tab to this UI, along with all of its attached pages. */
64
- def attachTab (tab : WebUITab ) {
63
+ /** Attaches a tab to this UI, along with all of its attached pages. */
64
+ def attachTab (tab : WebUITab ): Unit = {
65
65
tab.pages.foreach(attachPage)
66
66
tabs += tab
67
67
}
68
68
69
- def detachTab (tab : WebUITab ) {
69
+ /** Detaches a tab from this UI, along with all of its attached pages. */
70
+ def detachTab (tab : WebUITab ): Unit = {
70
71
tab.pages.foreach(detachPage)
71
72
tabs -= tab
72
73
}
73
74
74
- def detachPage (page : WebUIPage ) {
75
+ /** Detaches a page from this UI, along with all of its attached handlers. */
76
+ def detachPage (page : WebUIPage ): Unit = {
75
77
pageToHandlers.remove(page).foreach(_.foreach(detachHandler))
76
78
}
77
79
78
- /** Attach a page to this UI. */
79
- def attachPage (page : WebUIPage ) {
80
+ /** Attaches a page to this UI. */
81
+ def attachPage (page : WebUIPage ): Unit = {
80
82
val pagePath = " /" + page.prefix
81
83
val renderHandler = createServletHandler(pagePath,
82
84
(request : HttpServletRequest ) => page.render(request), securityManager, conf, basePath)
@@ -88,41 +90,41 @@ private[spark] abstract class WebUI(
88
90
handlers += renderHandler
89
91
}
90
92
91
- /** Attach a handler to this UI. */
92
- def attachHandler (handler : ServletContextHandler ) {
93
+ /** Attaches a handler to this UI. */
94
+ def attachHandler (handler : ServletContextHandler ): Unit = {
93
95
handlers += handler
94
96
serverInfo.foreach(_.addHandler(handler))
95
97
}
96
98
97
- /** Detach a handler from this UI. */
98
- def detachHandler (handler : ServletContextHandler ) {
99
+ /** Detaches a handler from this UI. */
100
+ def detachHandler (handler : ServletContextHandler ): Unit = {
99
101
handlers -= handler
100
102
serverInfo.foreach(_.removeHandler(handler))
101
103
}
102
104
103
105
/**
104
- * Add a handler for static content .
106
+ * Detaches the content handler at `path` URI .
105
107
*
106
- * @param resourceBase Root of where to find resources to serve.
107
- * @param path Path in UI where to mount the resources.
108
+ * @param path Path in UI to unmount.
108
109
*/
109
- def addStaticHandler ( resourceBase : String , path : String ): Unit = {
110
- attachHandler( JettyUtils .createStaticHandler(resourceBase, path))
110
+ def detachHandler ( path : String ): Unit = {
111
+ handlers.find(_.getContextPath() == path).foreach(detachHandler )
111
112
}
112
113
113
114
/**
114
- * Remove a static content handler .
115
+ * Adds a handler for static content.
115
116
*
116
- * @param path Path in UI to unmount.
117
+ * @param resourceBase Root of where to find resources to serve.
118
+ * @param path Path in UI where to mount the resources.
117
119
*/
118
- def removeStaticHandler ( path : String ): Unit = {
119
- handlers.find(_.getContextPath() == path).foreach(detachHandler )
120
+ def addStaticHandler ( resourceBase : String , path : String = " /static " ): Unit = {
121
+ attachHandler( JettyUtils .createStaticHandler(resourceBase, path))
120
122
}
121
123
122
- /** Initialize all components of the server. */
124
+ /** A hook to initialize components of the UI */
123
125
def initialize (): Unit
124
126
125
- /** Bind to the HTTP server behind this web interface. */
127
+ /** Binds to the HTTP server behind this web interface. */
126
128
def bind (): Unit = {
127
129
assert(serverInfo.isEmpty, s " Attempted to bind $className more than once! " )
128
130
try {
@@ -136,17 +138,17 @@ private[spark] abstract class WebUI(
136
138
}
137
139
}
138
140
139
- /** Return the url of web interface. Only valid after bind() . */
141
+ /** @return The url of web interface. Only valid after [[ bind ]] . */
140
142
def webUrl : String = s " http:// $publicHostName: $boundPort"
141
143
142
- /** 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 ]] . */
143
145
def boundPort : Int = serverInfo.map(_.boundPort).getOrElse(- 1 )
144
146
145
- /** Stop the server behind this web interface. Only valid after bind() . */
147
+ /** Stops the server behind this web interface. Only valid after [[ bind ]] . */
146
148
def stop (): Unit = {
147
149
assert(serverInfo.isDefined,
148
150
s " Attempted to stop $className before binding to a server! " )
149
- serverInfo.get .stop()
151
+ serverInfo.foreach(_ .stop() )
150
152
}
151
153
}
152
154
0 commit comments