6060 * Main class of Zeppelin.
6161 *
6262 */
63-
6463public class ZeppelinServer extends Application {
6564 private static final Logger LOG = LoggerFactory .getLogger (ZeppelinServer .class );
6665
6766 public static Notebook notebook ;
68- public static NotebookServer notebookServer ;
69- public static Server jettyServer ;
67+ public static Server jettyWebServer ;
68+ public static NotebookServer notebookWsServer ;
7069
7170 private SchedulerFactory schedulerFactory ;
7271 private InterpreterFactory replFactory ;
7372 private NotebookRepo notebookRepo ;
7473 private SearchService notebookIndex ;
7574
76- public static void main ( String [] args ) throws Exception {
75+ public ZeppelinServer ( ) throws Exception {
7776 ZeppelinConfiguration conf = ZeppelinConfiguration .create ();
78- conf .setProperty ("args" , args );
7977
80- jettyServer = setupJettyServer (conf );
78+ this .schedulerFactory = new SchedulerFactory ();
79+ this .replFactory = new InterpreterFactory (conf , notebookWsServer );
80+ this .notebookRepo = new NotebookRepoSync (conf );
81+
82+ notebook = new Notebook (conf ,
83+ notebookRepo , schedulerFactory , replFactory , notebookWsServer , notebookIndex );
84+ }
85+
86+ public static void main (String [] args ) throws InterruptedException {
87+ ZeppelinConfiguration conf = ZeppelinConfiguration .create ();
88+ conf .setProperty ("args" , args );
8189
8290 // REST api
83- final ServletContextHandler restApi = setupRestApiContextHandler (conf );
91+ final ServletContextHandler restApiContext = setupRestApiContextHandler (conf );
8492
8593 // Notebook server
86- final ServletContextHandler notebook = setupNotebookServer (conf );
94+ final ServletContextHandler notebookContext = setupNotebookServer (conf );
8795
8896 // Web UI
8997 final WebAppContext webApp = setupWebAppContext (conf );
9098
9199 // add all handlers
92100 ContextHandlerCollection contexts = new ContextHandlerCollection ();
93- contexts .setHandlers (new Handler []{restApi , notebook , webApp });
94- jettyServer .setHandler (contexts );
101+ contexts .setHandlers (new Handler []{restApiContext , notebookContext , webApp });
102+
103+ jettyWebServer = setupJettyServer (conf );
104+ jettyWebServer .setHandler (contexts );
95105
96- LOG .info ("Start zeppelin server" );
106+ LOG .info ("Starting zeppelin server" );
97107 try {
98- jettyServer .start ();
108+ jettyWebServer .start (); //Instantiates ZeppelinServer
99109 } catch (Exception e ) {
100110 LOG .error ("Error while running jettyServer" , e );
101111 System .exit (-1 );
102112 }
103- LOG .info ("Started zeppelin server" );
113+ LOG .info ("Done, zeppelin server started " );
104114
105115 Runtime .getRuntime ().addShutdownHook (new Thread (){
106116 @ Override public void run () {
107117 LOG .info ("Shutting down Zeppelin Server ... " );
108118 try {
109- jettyServer .stop ();
110- ZeppelinServer . notebook .getInterpreterFactory ().close ();
111- ZeppelinServer . notebook .close ();
119+ jettyWebServer .stop ();
120+ notebook .getInterpreterFactory ().close ();
121+ notebook .close ();
112122 } catch (Exception e ) {
113123 LOG .error ("Error while stopping servlet container" , e );
114124 }
@@ -127,18 +137,15 @@ public static void main(String[] args) throws Exception {
127137 System .exit (0 );
128138 }
129139
130- jettyServer .join ();
140+ jettyWebServer .join ();
131141 ZeppelinServer .notebook .getInterpreterFactory ().close ();
132142 }
133143
134- private static Server setupJettyServer (ZeppelinConfiguration conf )
135- throws Exception {
136-
144+ private static Server setupJettyServer (ZeppelinConfiguration conf ) {
137145 AbstractConnector connector ;
138146 if (conf .useSsl ()) {
139147 connector = new SslSelectChannelConnector (getSslContextFactory (conf ));
140- }
141- else {
148+ } else {
142149 connector = new SelectChannelConnector ();
143150 }
144151
@@ -155,11 +162,9 @@ private static Server setupJettyServer(ZeppelinConfiguration conf)
155162 return server ;
156163 }
157164
158- private static ServletContextHandler setupNotebookServer (ZeppelinConfiguration conf )
159- throws Exception {
160-
161- notebookServer = new NotebookServer ();
162- final ServletHolder servletHolder = new ServletHolder (notebookServer );
165+ private static ServletContextHandler setupNotebookServer (ZeppelinConfiguration conf ) {
166+ notebookWsServer = new NotebookServer ();
167+ final ServletHolder servletHolder = new ServletHolder (notebookWsServer );
163168 servletHolder .setInitParameter ("maxTextMessageSize" , "1024000" );
164169
165170 final ServletContextHandler cxfContext = new ServletContextHandler (
@@ -173,9 +178,8 @@ private static ServletContextHandler setupNotebookServer(ZeppelinConfiguration c
173178 return cxfContext ;
174179 }
175180
176- private static SslContextFactory getSslContextFactory (ZeppelinConfiguration conf )
177- throws Exception {
178-
181+ @ SuppressWarnings ("deprecation" )
182+ private static SslContextFactory getSslContextFactory (ZeppelinConfiguration conf ) {
179183 // Note that the API for the SslContextFactory is different for
180184 // Jetty version 9
181185 SslContextFactory sslContextFactory = new SslContextFactory ();
@@ -196,6 +200,7 @@ private static SslContextFactory getSslContextFactory(ZeppelinConfiguration conf
196200 return sslContextFactory ;
197201 }
198202
203+ @ SuppressWarnings ("unused" ) //TODO(bzz) why unused?
199204 private static SSLContext getSslContext (ZeppelinConfiguration conf )
200205 throws Exception {
201206
@@ -242,40 +247,25 @@ private static WebAppContext setupWebAppContext(
242247 webApp .setTempDirectory (warTempDirectory );
243248 }
244249 // Explicit bind to root
245- webApp .addServlet (
246- new ServletHolder (new DefaultServlet ()),
247- "/*"
248- );
250+ webApp .addServlet (new ServletHolder (new DefaultServlet ()), "/*" );
249251 return webApp ;
250252 }
251253
252- public ZeppelinServer () throws Exception {
253- ZeppelinConfiguration conf = ZeppelinConfiguration .create ();
254-
255- this .schedulerFactory = new SchedulerFactory ();
256- this .replFactory = new InterpreterFactory (conf , notebookServer );
257- this .notebookIndex = new SearchService ();
258- this .notebookRepo = new NotebookRepoSync (conf );
259-
260- notebook = new Notebook (conf , notebookRepo , schedulerFactory , replFactory ,
261- notebookServer , notebookIndex );
262- }
263-
264254 @ Override
265255 public Set <Class <?>> getClasses () {
266256 Set <Class <?>> classes = new HashSet <Class <?>>();
267257 return classes ;
268258 }
269259
270260 @ Override
271- public java . util . Set <java . lang . Object > getSingletons () {
272- Set <Object > singletons = new HashSet <Object >();
261+ public Set <Object > getSingletons () {
262+ Set <Object > singletons = new HashSet <>();
273263
274264 /** Rest-api root endpoint */
275265 ZeppelinRestApi root = new ZeppelinRestApi ();
276266 singletons .add (root );
277267
278- NotebookRestApi notebookApi = new NotebookRestApi (notebook , notebookServer , notebookIndex );
268+ NotebookRestApi notebookApi = new NotebookRestApi (notebook , notebookWsServer , notebookIndex );
279269 singletons .add (notebookApi );
280270
281271 InterpreterRestApi interpreterApi = new InterpreterRestApi (replFactory );
0 commit comments