public Blade start ( Class < ? > mainCls , String ... args ) { try { this . loadConfig ( args ) ; this . bootClass = mainCls ; eventManager . fireEvent ( EventType . SERVER_STARTING , new Event ( ) . attribute ( "blade" , this ) ) ; Thread thread = new Thread ( ( ) -> { try { server . start ( Blade . this ) ; latch . countDown ( ) ; server . join ( ) ; } catch ( BindException e ) { log . error ( "Bind address error\n" , e ) ; System . exit ( 0 ) ; } catch ( Exception e ) { startupExceptionHandler . accept ( e ) ; } } ) ; String threadName = null != this . threadName ? this . threadName : environment . get ( ENV_KEY_APP_THREAD_NAME , null ) ; threadName = null != threadName ? threadName : DEFAULT_THREAD_NAME ; thread . setName ( threadName ) ; thread . start ( ) ; this . started = true ; Thread resourceFilesRefreshThread = new Thread ( ( ) -> { try { FileChangeDetector fileChangeDetector = new FileChangeDetector ( environment . get ( ENV_KEY_AUTO_REFRESH_DIR ) . get ( ) ) ; fileChangeDetector . processEvent ( ( event , filePath ) -> { try { //TODO: add support for Create and Delete if ( event . equals ( StandardWatchEventKinds . ENTRY_MODIFY ) ) { Path destPath = FileChangeDetector . getDestPath ( filePath , environment ) ; Files . copy ( filePath , destPath , StandardCopyOption . REPLACE_EXISTING ) ; } } catch ( IOException e ) { log . error ( "Exception when trying to copy updated file" ) ; startupExceptionHandler . accept ( e ) ; } } ) ; } catch ( IOException e ) { startupExceptionHandler . accept ( e ) ; } } ) ; if ( devMode ( ) && isAutoRefreshDir ( ) ) { log . info ( "auto refresh is enabled" ) ; resourceFilesRefreshThread . start ( ) ; } } catch ( Exception e ) { startupExceptionHandler . accept ( e ) ; } return this ; }
Start blade application