/**
  * Stops all inbound message producers (that are not {@link OrderlyShutdownCapable}) - may cause
  * interrupts.
  */
 @ManagedOperation
 public void stopInboundMessageProducers() {
   for (Lifecycle producer : this.inboundLifecycleMessageProducers) {
     if (!(producer instanceof OrderlyShutdownCapable)) {
       if (logger.isInfoEnabled()) {
         logger.info("Stopping message producer " + producer);
       }
       producer.stop();
     }
   }
 }
 /** Stops this repository. */
 @Override
 public void stop() {
   final Status status = _status.get();
   if (status == Status.STOPPING || status == Status.STOPPED) {
     return; // nothing to stop in this thread
   }
   if (_status.compareAndSet(status, Status.STOPPING) == false) {
     return; // another thread just beat this one
   }
   for (final Lifecycle obj : _lifecycles) {
     try {
       obj.stop();
     } catch (final Exception ex) {
       // ignore
     }
   }
   _status.set(Status.STOPPED);
 }
 @ManagedOperation
 public void stopActiveChannels() {
   // Stop any "active" channels (JMS etc).
   for (Entry<String, DirectChannelMetrics> entry : this.allChannelsByName.entrySet()) {
     DirectChannelMetrics metrics = entry.getValue();
     MessageChannel channel = metrics.getMessageChannel();
     if (channel instanceof Lifecycle) {
       if (logger.isInfoEnabled()) {
         logger.info("Stopping channel " + channel);
       }
       ((Lifecycle) channel).stop();
     }
   }
 }
  /** Marks this repository as complete and ready for use. */
  @Override
  public void start() {
    final Status status = _status.get();
    if (status == Status.STARTING) {
      return; // already starting
    }
    checkStatus(status, Status.CREATING);
    if (_status.compareAndSet(status, Status.STARTING) == false) {
      return; // another thread just beat this one
    }
    try {
      // Spring interfaces
      for (final Lifecycle obj : _lifecycles) {
        obj.start();
      }

      // JMX managed resources
      final MBeanServer jmxServer = findInstance(MBeanServer.class);
      if (jmxServer != null) {
        final MBeanExporter exporter = new MBeanExporter();
        exporter.setServer(jmxServer);
        for (final Map.Entry<ObjectName, Object> resourceEntry : _managedResources.entrySet()) {
          exporter.registerManagedResource(resourceEntry.getValue(), resourceEntry.getKey());
        }
      }

      _status.set(Status.RUNNING);

    } catch (final RuntimeException ex) {
      _status.set(Status.FAILED);
      throw ex;
    } finally {
      // reduce memory usage and avoid memory leaks
      _managedResources.clear();
      _initialized.clear();
    }
  }
 /** Stops all message sources - may cause interrupts. */
 @ManagedOperation
 public void stopMessageSources() {
   for (Entry<String, MessageSourceMetrics> entry : this.allSourcesByName.entrySet()) {
     MessageSourceMetrics sourceMetrics = entry.getValue();
     if (sourceMetrics instanceof Lifecycle) {
       if (logger.isInfoEnabled()) {
         logger.info("Stopping message source " + sourceMetrics);
       }
       ((Lifecycle) sourceMetrics).stop();
     } else {
       if (logger.isInfoEnabled()) {
         logger.info("Message source " + sourceMetrics + " cannot be stopped");
       }
     }
   }
 }