vendor/bundle/ruby/1.8/gems/activemessaging-0.9.0/lib/activemessaging/gateway.rb
def stop
        # first tell the threads to stop their looping, so they'll stop when next complete a receive/dispatch cycle
        @@running = false
        
        # if they are dispatching (i.e. !thread[:message].nil?), wait for them to finish
        # if they are receiving (i.e. thread[:message].nil?), stop them by raising exception
        dispatching = true
        while dispatching
          dispatching = false
          @@connection_threads.each do |name, thread|
            if thread[:message]
              dispatching = true
              # if thread got killed, but dispatch not done, try it again
              if thread.alive?
                ActiveMessaging.logger.error "Waiting on thread #{name} to finish processing last message..."
              else
                ActiveMessaging.logger.error "Starting thread #{name} to finish processing last message..."
                msg = thread[:message]
                thread.exit
                thread = Thread.start do
                  begin
                    Thread.current[:message] = msg
                    dispatch Thread.current[:message]
                  ensure
                    Thread.current[:message] = nil
                  end
                end
              end
            else
              thread.raise StopProcessingException, "Time to stop." if thread.alive?
            end
          end
          sleep(1)
        end
        unsubscribe
        disconnect
      end
# Starts up an message listener to start polling for messages on each configured connection, and dispatching processing
Starts up an message listener to start polling for messages on each configured connection, and dispatching processing
Starts up an message listener to start polling for messages on each configured connection and dispatching processing
def stop
        @@running = false
        dispatching = true
        while dispatching
          dispatching = false
          @@connection_threads.each do |name, thread|
            if thread[:message]
              dispatching = true
              if thread.alive?
                ActiveMessaging.logger.error "Waiting on thread #{name} to finish processing last message..."
              else
                ActiveMessaging.logger.error "Starting thread #{name} to finish processing last message..."
                msg = thread[:message]
                thread.exit
                thread = Thread.start do
                  begin
                    Thread.current[:message] = msg
                    dispatch Thread.current[:message]
                  ensure
                    Thread.current[:message] = nil
                  end
                end
              end
            else
              thread.raise StopProcessingException, "Time to stop." if thread.alive?
            end
          end
          sleep(1)
        end
        unsubscribe
        disconnect
      end
def stop @@running = false dispatching = true while dispatching dispatching = false @@connection_threads . each do | name , thread | if thread [ :message ] dispatching = true if thread . alive? ActiveMessaging . logger . error "Waiting on thread #{name} to finish processing last message..." else ActiveMessaging . logger . error "Starting thread #{name} to finish processing last message..." msg = thread [ :message ] thread . exit thread = Thread . start do begin Thread . current [ :message ] = msg dispatch Thread . current [ :message ] ensure Thread . current [ :message ] = nil end end end else thread . raise StopProcessingException , "Time to stop." if thread . alive? end end sleep ( 1 ) end unsubscribe disconnect end
Starts up an message listener to start polling for messages on each configured connection, and dispatching processing
Starts up an message listener to start polling for messages on each configured connection and dispatching processing
# first tell the threads to stop their looping, so they'll stop when next complete a receive/dispatch cycle # if they are dispatching (i.e. !thread[:message].nil?), wait for them to finish # if they are receiving (i.e. thread[:message].nil?), stop them by raising exception # if thread got killed, but dispatch not done, try it again