Stop the queue-consumer gracefully.

        Wait until the last provider has been unregistered and for
        the ConsumerMixin's greenthread to exit (i.e. until all pending
        messages have been acked or requeued and all consumers stopped).
439441
def stop(self):
        
        if not self._consumers_ready.ready():
            _log.debug('stopping while consumer is starting %s', self)

            stop_exc = QueueConsumerStopped()

            # stopping before we have started successfully by brutally
            # killing the consumer thread as we don't have a way to hook
            # into the pre-consumption startup process
            self._gt.kill(stop_exc)

        self.wait_for_providers()

        try:
            _log.debug('waiting for consumer death %s', self)
            self._gt.wait()
        except QueueConsumerStopped:
            pass

        super(QueueConsumer, self).stop()
        _log.debug('stopped %s', self)
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;
  }
322413
def _recv_cancel(self, method_frame):
        '''
        '''
        self.logger.warning("consumer cancelled by broker: %r", method_frame)

        consumer_tag = method_frame.args.read_shortstr()

        # NOTE: per RabbitMQ spec, no-wait is always true in Basic.Cancel from
        # broker

        # Remove consumer from this basic instance
        try:
            cancel_cb = self._broker_cancel_cb_map.pop(consumer_tag)
        except KeyError:
            # Must be a race condition between user's cancel and broker's cancel
            self.logger.warning(
                '_recv_cancel: no broker-cancel-cb entry for consumer tag %r',
                consumer_tag)
        else:
            if callable(cancel_cb):
                # Purge from base class only when user supplies cancel_cb
                self._purge_consumer_by_tag(consumer_tag)

                # Notify user
                cancel_cb(consumer_tag)
370331
def stop(self):
        
        # self.loop.call_soon_threadsafe(self.loop.stop)
        # self.loop.stop()
        # self._longPoll.cancel()
        # self._shortPoll.cancel()
        if self.connected:
            LOGGER.info('Disconnecting from MQTT... {}:{}'.format(self._server, self._port))
            self._mqttc.publish(self.topicSelfConnection, json.dumps({'node': self.profileNum, 'connected': False}), retain=True)
            self._mqttc.loop_stop()
            self._mqttc.disconnect()
        try:
            for watcher in self.__stopObservers:
                watcher()
        except KeyError as e:
            LOGGER.exception('KeyError in gotConfig: {}'.format(e), exc_info=True)
1199903
def maybe_resume_consumer(self):
        """"""
        # If we have been paused by flow control, check and see if we are
        # back within our limits.
        #
        # In order to not thrash too much, require us to have passed below
        # the resume threshold (80% by default) of each flow control setting
        # before restarting.
        if self._consumer is None or not self._consumer.is_paused:
            return

        if self.load < self.flow_control.resume_threshold:
            self._consumer.resume()
        else:
            _LOGGER.debug("Did not resume, current load is %s", self.load)
381773
@Override
    public void resumeConsumer(int suspendFlag)
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "resumeConsumer", this);

        // Use this flag to identify whether a new thread must be spun off to look for more
        // messages
        boolean spinOffNewThread = false;
        try
        {
            // Take the lock
            this.lock();

            if (_consumerSuspended)
            {
                boolean setStillSuspended = false;

                // If we're resuming due to the ConsumerSet being resumed then we need to
                // re-check the set's state due to us not holding the set's activeMessageCount
                // lock at this time (due to the hierarchy). And if we find that the set is
                // actually suspended (due to someone else in the set getting in and adding
                // another message then we just ignore this resume as there'll be another one
                // along when the count drops back below the limit again.
                if (suspendFlag == DispatchableConsumerPoint.SUSPEND_FLAG_SET_ACTIVE_MSGS)
                    setStillSuspended = _consumerKey.isConsumerSetSuspended();

                if (!setStillSuspended)
                {
                    // clear the bit provided in the _suspendFlags
                    _suspendFlags &= ~suspendFlag;

                    if (_suspendFlags == 0) // No flags set so resume the consumer
                    {
                        _consumerSuspended = false;

                        // If the consumer is still active (started) we need
                        // to kickstart the consumer back into life to check for more
                        // messages
                        if (!_stopped && !_closing)
                        {
                            if (_asynchConsumerRegistered)
                            {
                                if (!_asynchConsumer.isAsynchConsumerRunning())
                                {
                                    // We'll have to take the full lock hierarchy and
                                    // possibly spin off another thread to start looking for more messages
                                    // (just like start())
                                    spinOffNewThread = true;
                                }
                            }
                            else
                            {
                                // Wake up any synchronous receivers
                                _waiter.signal();
                            }
                        }
                    }
                }
            }
        } finally
        {
            this.unlock();
        }

        // start a new thread to run the callback if we determined that it was necessary   
        if (spinOffNewThread)
        {
            try
            {
                _messageProcessor.startNewThread(new AsynchThread(this, false));
            } catch (InterruptedException e)
            {
                FFDCFilter.processException(
                                            e,
                                            "com.ibm.ws.sib.processor.impl.JSLocalConsumerPoint.resumeConsumer",
                                            "1:4978:1.22.5.1",
                                            this);

                SibTr.exception(tc, e);

                if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                    SibTr.exit(tc, "resumeConsumer", e);
            }
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "resumeConsumer");
    }
1326453
def stop
      return if @state != :started
      # stop receiving new incoming messages
      @service_queue.unsubscribe
      # only stop the service if all incoming and outgoing messages are complete
      decisecond_timeout = @options[:timeout]/100
      waited_deciseconds = 0 # guarantee that this loop will stop
      while (@transactions.length > 0 || @processing_messages > 0) && waited_deciseconds < decisecond_timeout
        sleep(0.1) # wait a decisecond to check the incoming and outgoing messages again
        waited_deciseconds += 1
      end

      @channel.close
      @state = :stopped
    end
1094256
public void resumeConsumer(int suspendFlag)
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "resumeConsumer", this);
    
    ArrayList<AORequestedTick> satisfiedTicks = null;

    synchronized(parent) // AOStream
    {
      try
      {
        // Take the lock
        this.lock();
        try
        {    
          if (_consumerSuspended)
          {
            // clear the bit provided in the _suspendFlags
            _suspendFlags &= ~suspendFlag;
      
            if (_suspendFlags == 0) // No flags set so resume the consumer
            {
              _consumerSuspended = false;
      
              // If the consumer is still active (started) we need
              // to kickstart the consumer back into life to check for more
              // messages
              if(!closed)
                satisfiedTicks = processQueuedMsgs(null);
            }
          }
        }
        finally
        {
          this.unlock();
        }   
      }
      catch(SINotPossibleInCurrentConfigurationException e)
      {
        // No FFDC code needed
        notifyException(e);
      }
      
      if (satisfiedTicks!=null)
      {
        // inform parent about satisfied ticks - outside lock
        int length = satisfiedTicks.size();
        for (int i = 0; i < length; i++)
        {
          AORequestedTick aotick = (AORequestedTick) satisfiedTicks.get(i);
          parent.satisfiedRequest(aotick.tick, aotick.getMessage());
        }
      }
    }
    
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "resumeConsumer");
  }
982869
public void unsetAsynchConsumer(boolean stoppable)                                                   //SIB0115d.comms
      throws SISessionUnavailableException, SISessionDroppedException,
             SIConnectionUnavailableException, SIConnectionDroppedException,
             SIErrorException,
             SIIncorrectCallException
   {
      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "unsetAsynchConsumer");

      if (sessionId == 0)
      {
         // If the session Id = 0, then no one called setSessionId(). As such we are unable to flow
         // to the server as we do not know which session to instruct the server to use.
         SIErrorException e = new SIErrorException(
            nls.getFormattedMessage("SESSION_ID_HAS_NOT_BEEN_SET_SICO1043", null, null)
         );

         FFDCFilter.processException(e, CLASS_NAME + ".unsetAsyncConsumer",
                                     CommsConstants.CONVERSATIONHELPERIMPL_01, this);

         if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(this, tc, e.getMessage(), e);

         throw e;
      }

      CommsByteBuffer request = getCommsByteBuffer();
      // Connection object id
      request.putShort(connectionObjectId);
      // Consumer session id
      request.putShort(sessionId);

      // Pass on call to server
      CommsByteBuffer reply = null;
      try
      {
         reply = jfapExchange(request,
                              (stoppable ? JFapChannelConstants.SEG_DEREGISTER_STOPPABLE_ASYNC_CONSUMER : JFapChannelConstants.SEG_DEREGISTER_ASYNC_CONSUMER), //SIB0115d.comms
                              JFapChannelConstants.PRIORITY_MEDIUM,
                              true);
      }
      catch (SIConnectionLostException e)
      {
         // No FFDC Code needed
         // Converting this to a connection dropped as that is all we can throw
         if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(this, tc, "Connection was lost", e);

         throw new SIConnectionDroppedException(e.getMessage(), e);
      }

      // Confirm appropriate data returned
      try
      {
         short err = reply.getCommandCompletionCode(JFapChannelConstants.SEG_DEREGISTER_ASYNC_CONSUMER_R);
         if (err != CommsConstants.SI_NO_EXCEPTION)
         {
            checkFor_SISessionUnavailableException(reply, err);
            checkFor_SISessionDroppedException(reply, err);
            checkFor_SIConnectionUnavailableException(reply, err);
            checkFor_SIConnectionDroppedException(reply, err);
            checkFor_SIIncorrectCallException(reply, err);
            checkFor_SIErrorException(reply, err);
            defaultChecker(reply, err);
         }
      }
      finally
      {
         if (reply != null) reply.release();
      }

      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "unsetAsynchConsumer");
   }
273377
def _need_stop(self):
        
        if not self.option.cursor_end_time:
            return False

        all_finish = True
        for shard, consumer in self.shard_consumers.items():
            if consumer.is_shutdown():
                continue

            # has not yet do any successful fetch yet or get some data
            if consumer.last_success_fetch_time == 0 or consumer.last_fetch_count > 0:
                return False

        # init self.last_owned_consumer_finish_time if it's None
        if all_finish and self.last_owned_consumer_finish_time == 0:
            self.last_owned_consumer_finish_time = time.time()

        if abs(time.time() - self.last_owned_consumer_finish_time) >= \
                self.option.consumer_group_time_out + self.option.heartbeat_interval:
            return True

        return False
1020308
def stop(self):
        
        with self.__receiver_thread_exit_condition:
            while not self.__receiver_thread_exited and self.is_connected():
                self.__receiver_thread_exit_condition.wait()
952122
public function stop()
    {
        if (!empty($this->channel)) {
            echo 'Stopping consumer by removing callbacks.' . PHP_EOL;
            $this->channel->callbacks = null;
            return true;
        } else {
            return false;
        }
    }
449571
@Override
    public void stop() throws Exception {
        log.info("Stopping {}...", name);
        submitBuffer(true);
        if (coreContainer != null) {
            coreContainer.shutdown();
        }
        if (consumer != null) {
            try {
                consumer.close();
            } catch (JMSException jmse) {
                log.warn("Failed to close consumer: {}", jmse.getMessage());
                throw jmse;
            }
        }
        if (session != null) {
            try {
                session.close();
            } catch (JMSException jmse) {
                log.warn("Failed to close consumer session: {}", jmse);
            }
        }
        if (connection != null) {
            try {
                connection.close();
            } catch (JMSException jmse) {
                log.warn("Failed to close connection: {}", jmse);
            }
        }
        timer.cancel();
    }
101835
def on_stop(self):
        
        LOGGER.debug("rabbitmq.Service.on_stop")
        self.is_started = False
        try:
            self.channel.stop_consuming()
        except Exception as e:
            LOGGER.warn("rabbitmq.Service.on_stop - Exception raised while stoping consuming")

        try:
            self.channel.close()
        except Exception as e:
            LOGGER.warn("rabbitmq.Service.on_stop - Exception raised while closing channel")

        try:
            self.connection.close()
        except Exception as e:
            LOGGER.warn("rabbitmq.Service.on_stop - Exception raised while closing connection")
875548
public void shutdown() {
        // Prevent new entries from being added ...
        this.addEntries.set(false);

        // Mark the cursor as being finished; this will stop all consumers from waiting for a batch ...
        this.cursor.complete();

        // Each of the consumer threads will complete the batch they're working on, but will then terminate ...

        // Stop the garbage collection thread (if running) ...
        if (this.gcConsumer != null) this.gcConsumer.close();

        // Now, block until all the runners have completed ...
        for (ConsumerRunner runner : new HashSet<>(consumers)) { // use a copy of the runners; they're removed when they close
            runner.waitForCompletion();
        }
        assert consumers.isEmpty();
    }
1074479
public synchronized void stopConsumers(Class<? extends Consumer> consumerClass) {
        List<ConsumerHolder> consumerHolderSubList = filterConsumersForClass(consumerClass);
        disableConsumers(consumerHolderSubList);
    }
1237047
def stop(self):
        
        while self._consumers:
            consumer = self._consumers.pop()
            consumer.stop()
        self._stopped.set()
        self._connection.close()