Stop the RegistrationManagerImpl

it is idempotent, it can be invoked in multiple times while in same state. But not thread safe.
488717
@Override
    public void stop(){
        if (isStarted) {
            synchronized (this) {
                if (isStarted) {
                    if (getRegistrationService() instanceof Closable) {
                        ((Closable) getRegistrationService()).stop();
                    }
                    isStarted = false;
                }
            }
        }

    }
448974
public void stop()
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "stop");

    if(started)
    {
      started = false;
      if(keyGroup != null)
        keyGroup.stopMember();
    }

    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "stop");
  }
1164441
public void stop()
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(tc, "stop");
    
    try
    {    
      _lockManager.lockExclusive();

      // Flag that we are in a started state. 
      _started = false;
    }      
    finally
    {
      _lockManager.unlockExclusive();
    }
    
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(tc, "stop");    
  }
833477
@Override
    public void stop() {
        if (!HAConfiguration.isHAEnabled(configuration)) {
            LOG.info("HA is not enabled, no need to stop leader election service");
            return;
        }
        try {
            leaderLatch.close();
            curatorFactory.close();
        } catch (IOException e) {
            LOG.error("Error closing leader latch", e);
        }
    }
1076207
private void shutdownImpl(ShutdownModeAmp mode, 
                            ExitCode exitCode,
                            Result<String> result)
  {
    // start the fail-safe thread in case the shutdown fails
    FailSafeHaltThread haltThread = _failSafeHaltThread;
    
    if (haltThread != null) {
      haltThread.startShutdown();
    }

    if (exitCode == null) {
      exitCode = ExitCode.FAIL_SAFE_HALT;
    }
    
    _exitCode.compareAndSet(null, exitCode);

    try {
      SystemManager systemManager = _systemManagerRef.get();
        
      if (systemManager != null) {
        systemManager.shutdown(mode);
      }
    } catch (Throwable e) {
      log.log(Level.WARNING, e.toString(), e);
    } finally {
      _systemManagerRef = null;
      _lifecycle.toDestroy();

      System.err.println("\nShutdown reason: " + exitCode + "\n");

      log.warning("Shutdown reason: " + exitCode);
      
      if (result != null) {
        result.ok("Shutdown reason: " + exitCode);
      }

      if (! _isEmbedded) {
        System.exit(exitCode.ordinal());
      }
    }
  }
806352
@Invalidate
    public void stop() {
        unregisterConfigurationsExposedAsServices();
        if (registration != null) {
            registration.unregister();
            registration = null;
            try {
                watcher.removeAndStopIfNeeded(configFile.getParentFile());
            } catch (RuntimeException e) { //NOSONAR
                // An exception can be thrown when the platform is shutting down.
                // ignore it.
            }
        }
    }
888788
synchronized void unregister() {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "unregister", this);
        }
        if (registration != null) {
            registration.unregister();
            registration = null;
        }
    }
22679
@Override
    public void stop() {
        super.stop();
        try {
            getContext().unregisterReceiver(mBroadcastReceiver);
        } catch(IllegalArgumentException e) {
            Log.d(TAG, "Unable to unregister receiver when stopping, probably not registered");
        }
    }
1111778
public synchronized void stop() {
    Preconditions.checkState(notifListener != null, "logger has not been started");
    for (GarbageCollectorMXBean mbean : ManagementFactory.getGarbageCollectorMXBeans()) {
      if (mbean instanceof NotificationEmitter) {
        final NotificationEmitter emitter = (NotificationEmitter) mbean;
        try {
          emitter.removeNotificationListener(notifListener);
        } catch (ListenerNotFoundException e) {
          LOGGER.warn("could not remove gc listener", e);
        }
      }
    }
    notifListener = null;
  }
258346
def halt(self):
        
        if self._callback:
            self._thread_continue = False
            self._thread.join()
571796
public synchronized void stop(boolean graceful)
        throws InterruptedException
    {
        boolean ov=_gracefulStop;
        try
        {
            _gracefulStop=graceful;
            stop();
        }
        finally
        {
            _gracefulStop=ov;
        }
    }
248429
void unregister(ResourceMonitorImpl monitorImpl)
   {
      Set<Entry<WatchKey, ResourceMonitorImpl>> entrySet = keys.entrySet();
      Iterator<Entry<WatchKey, ResourceMonitorImpl>> iterator = entrySet.iterator();
      while (iterator.hasNext())
      {
         Entry<WatchKey, ResourceMonitorImpl> next = iterator.next();
         if (next.getValue() == monitorImpl)
         {
            next.getKey().cancel();
            iterator.remove();
         }
      }
   }
403377
private static final void stopBroker() {
		AbstractApplicationContext instance = context.getAndSet(null);
		if (instance != null) {
			Thread safetyTimer = new Thread() {

				public void run() {
					try {
						Thread.sleep(15000);
						Runtime.getRuntime().halt(1);
					} catch (Throwable ignored) {
					}
				}

			};
			safetyTimer.setDaemon(true);
			safetyTimer.start();
			try {
				instance.stop();
			} catch (Throwable ignored) {
			}
			try {
				Thread.sleep(600);
			} catch (Throwable interrupted) {
			}
			Runtime.getRuntime().halt(0);
		}
	}
221512
void unregisterEntry(ListIterator<PathElement> iterator, String value, ConcreteNotificationHandlerRegistration.NotificationHandlerEntry entry) {
        NotificationHandlerNodeRegistry registry = childRegistries.get(value);
        if (registry == null) {
            return;
        }
        registry.unregisterEntry(iterator, entry);
    }
985910
void stop() {
        try {
            dm.stop(getBundleContext());
        } catch (DirectoryMonitoringException e) {
            LOG.error("Failed to stop " + DirectoryMonitor.class.getName() + " for the directory " + monitoredDirectory, e);
        }
        declarationsFiles.clear();
        declarationRegistrationManager.unregisterAll();
    }
1143261
public void stop() {

		// Cancel the timer
		this.logger.info( "The DM is about to be stopped." );
		if( this.timer != null ) {
			this.timer.cancel();
			this.timer =  null;
		}

		// Save the instances
		for( ManagedApplication ma : this.applicationMngr.getManagedApplications())
			ConfigurationUtils.saveInstances( ma );

		// Disable notifications to listeners
		this.notificationMngr.disableNotifications();

		// Stop the target configurator
		this.targetConfigurator.stop();

		// Stops listening to the debug queue.
		if( this.messagingClient != null ) {
			try {
				this.messagingClient.listenToTheDm( ListenerCommand.STOP );

			} catch ( IOException e ) {
				this.logger.log( Level.WARNING, "Cannot stop to listen to the debug queue", e );
			}

			this.messagingClient.getMessageProcessor().stopProcessor();
			this.messagingClient.getMessageProcessor().interrupt();
			try {
				this.messagingClient.closeConnection();

			} catch( IOException e ) {
				this.logger.warning( "The messaging client could not be terminated correctly. " + e.getMessage());
				Utils.logException( this.logger, e );
			}
		}

		this.logger.info( "The DM was stopped." );
	}
27017
public void stop() {
        synchronized (this.startStopMonitor) {
            doStop();

            // If we registered a JVM shutdown hook, we don't need it anymore now:
            // We've already explicitly closed the context.
            if (this.shutdownHook != null) {
                try {
                    Runtime.getRuntime().removeShutdownHook(this.shutdownHook);
                } catch (final IllegalStateException ex) {
                    // ignore - VM is already shutting down
                }
            }
        }
    }