public void stopHawkularAgent ( ) { synchronized ( agentServiceStatus ) { if ( agentServiceStatus . get ( ) == ServiceStatus . STOPPED ) { log . infoStoppedAlready ( ) ; return ; // we are already stopped } else if ( agentServiceStatus . get ( ) == ServiceStatus . STOPPING ) { // some other thread is already stopping the agent - wait for that to finish and just return while ( agentServiceStatus . get ( ) == ServiceStatus . STOPPING ) { try { agentServiceStatus . wait ( 30000L ) ; } catch ( InterruptedException e ) { Thread . currentThread ( ) . interrupt ( ) ; return ; } return ; } } setStatus ( ServiceStatus . STOPPING ) ; } log . infoStopping ( ) ; AtomicReference < Throwable > error = new AtomicReference <> ( null ) ; // will hold the first error we encountered try { // stop the metrics exporter endpoint try { stopMetricsExporter ( ) ; } catch ( Throwable t ) { error . compareAndSet ( null , t ) ; log . debug ( "Cannot shutdown metrics exporter but will continue shutdown" , t ) ; } // disconnect from the feed comm channel try { if ( feedComm != null ) { feedComm . destroy ( ) ; feedComm = null ; } } catch ( Throwable t ) { error . compareAndSet ( null , t ) ; log . debug ( "Cannot shutdown feed comm but will continue shutdown" , t ) ; } // stop our normal protocol services try { if ( protocolServices != null ) { protocolServices . stop ( ) ; if ( inventoryStorageProxy != null ) { protocolServices . removeInventoryListener ( inventoryStorageProxy ) ; } if ( platformMBeanGenerator != null ) { platformMBeanGenerator . unregisterAllMBeans ( ) ; } if ( notificationDispatcher != null ) { protocolServices . removeInventoryListener ( notificationDispatcher ) ; } protocolServices = null ; } } catch ( Throwable t ) { error . compareAndSet ( null , t ) ; log . debug ( "Cannot shutdown protocol services but will continue shutdown" , t ) ; } // now stop the storage adapter try { if ( storageAdapter != null ) { storageAdapter . shutdown ( ) ; storageAdapter = null ; } } catch ( Throwable t ) { error . compareAndSet ( null , t ) ; log . debug ( "Cannot shutdown storage adapter but will continue shutdown" , t ) ; } // stop diagnostic reporting and spit out a final diagnostics report if ( diagnosticsReporter != null ) { diagnosticsReporter . stop ( ) ; if ( configuration . getDiagnostics ( ) . isEnabled ( ) ) { diagnosticsReporter . report ( ) ; } diagnosticsReporter = null ; } // allow subclasses to cleanup try { cleanupDuringStop ( ) ; } catch ( Exception e ) { error . compareAndSet ( null , e ) ; log . debug ( "Cannot shutdown - subclass exception" , e ) ; } // We attempted to clean everything we could. If we hit an error, throw it to log our shutdown wasn't clean if ( error . get ( ) != null ) { throw error . get ( ) ; } } catch ( Throwable t ) { log . warnFailedToStopAgent ( t ) ; } finally { setStatus ( ServiceStatus . STOPPED ) ; } }
Stops this service . If the service is already stopped this method is a no - op .