private DBService createDefaultDBService ( ) { m_logger . info ( "Creating DBService for default tenant" ) ; String dbServiceName = ServerParams . instance ( ) . getModuleParamString ( "DBService" , "dbservice" ) ; if ( Utils . isEmpty ( dbServiceName ) ) { throw new RuntimeException ( "'DBService.dbservice' parameter is not defined." ) ; } DBService dbservice = null ; Tenant defaultTenant = TenantService . instance ( ) . getDefaultTenant ( ) ; boolean bDBOpened = false ; while ( ! bDBOpened ) { try { // Find and call the constructor DBService(Tenant). @ SuppressWarnings ( "unchecked" ) Class < DBService > serviceClass = ( Class < DBService > ) Class . forName ( dbServiceName ) ; Constructor < DBService > constructor = serviceClass . getConstructor ( Tenant . class ) ; dbservice = constructor . newInstance ( defaultTenant ) ; dbservice . initialize ( ) ; dbservice . start ( ) ; bDBOpened = true ; } catch ( IllegalArgumentException e ) { throw new RuntimeException ( "Cannot load specified 'dbservice': " + dbServiceName , e ) ; } catch ( ClassNotFoundException e ) { throw new RuntimeException ( "Could not load dbservice class '" + dbServiceName + "'" , e ) ; } catch ( NoSuchMethodException e ) { throw new RuntimeException ( "Required constructor missing for dbservice class: " + dbServiceName , e ) ; } catch ( SecurityException | InstantiationException | IllegalAccessException e ) { throw new RuntimeException ( "Could not invoke constructor for dbservice class: " + dbServiceName , e ) ; } catch ( InvocationTargetException e ) { // This is thrown when a constructor is invoked via reflection. if ( ! ( e . getTargetException ( ) instanceof DBNotAvailableException ) ) { throw new RuntimeException ( "Could not invoke constructor for dbservice class: " + dbServiceName , e ) ; } } catch ( DBNotAvailableException e ) { // Fall through to retry. } catch ( Throwable e ) { throw new RuntimeException ( "Failed to initialize default DBService: " + dbServiceName , e ) ; } if ( ! bDBOpened ) { m_logger . info ( "Database is not reachable. Waiting to retry" ) ; try { Thread . sleep ( db_connect_retry_wait_millis ) ; } catch ( InterruptedException ex2 ) { // ignore } } } return dbservice ; }
throws a DBNotAvailableException keep trying .