vendor/bundle/ruby/1.8/gems/activemessaging-0.9.0/lib/activemessaging/gateway.rb
def start

        # subscribe - creating connections along the way
        subscribe

        # for each connection, start a thread
        @@connections.each do |name, conn|
          @@connection_threads[name] = Thread.start do
            while @@running
              begin
                Thread.current[:message] = nil
                Thread.current[:message] = conn.receive
              #catch these but then stop looping
              rescue StopProcessingException=>spe
                ActiveMessaging.logger.error "ActiveMessaging: thread[#{name}]: Processing Stopped - receive interrupted, will process last message if already received"
                # break
              #catch all others, but go back and try and recieve again
              rescue Object=>exception
                ActiveMessaging.logger.error "ActiveMessaging: thread[#{name}]: Exception from connection.receive: #{exception.message}\n" + exception.backtrace.join("\n\t")
              ensure
                dispatch Thread.current[:message] if Thread.current[:message]
                Thread.current[:message] = nil
              end
              Thread.pass
            end
            ActiveMessaging.logger.error "ActiveMessaging: thread[#{name}]: receive loop terminated"
          end
        end
        
        while @@running
          trap("TERM", "EXIT")
          living = false
          @@connection_threads.each { |name, thread| living ||=  thread.alive? }
          @@running = living
          sleep 1
        end
        ActiveMessaging.logger.error "All connection threads have died..."
      rescue Interrupt
        ActiveMessaging.logger.error "\n<<Interrupt received>>\n"  
      rescue Object=>exception
        ActiveMessaging.logger.error "#{exception.class.name}: #{exception.message}\n\t#{exception.backtrace.join("\n\t")}"
        raise exception
      ensure
        ActiveMessaging.logger.error "Cleaning up..."
        stop
        ActiveMessaging.logger.error "=> END"
      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 start
        subscribe
        @@connections.each do |name, conn|
          @@connection_threads[name] = Thread.start do
            while @@running
              begin
                Thread.current[:message] = nil
                Thread.current[:message] = conn.receive
              rescue StopProcessingException=>spe
                ActiveMessaging.logger.error "ActiveMessaging: thread[#{name}]: Processing Stopped - receive interrupted, will process last message if already received"
              rescue Object=>exception
                ActiveMessaging.logger.error "ActiveMessaging: thread[#{name}]: Exception from connection.receive: #{exception.message}\n" + exception.backtrace.join("\n\t")
              ensure
                dispatch Thread.current[:message] if Thread.current[:message]
                Thread.current[:message] = nil
              end
              Thread.pass
            end
            ActiveMessaging.logger.error "ActiveMessaging: thread[#{name}]: receive loop terminated"
          end
        end
        while @@running
          trap("TERM", "EXIT")
          living = false
          @@connection_threads.each { |name, thread| living ||=  thread.alive? }
          @@running = living
          sleep 1
        end
        ActiveMessaging.logger.error "All connection threads have died..."
      rescue Interrupt
        ActiveMessaging.logger.error "\n<<Interrupt received>>\n"  
      rescue Object=>exception
        ActiveMessaging.logger.error "#{exception.class.name}: #{exception.message}\n\t#{exception.backtrace.join("\n\t")}"
        raise exception
      ensure
        ActiveMessaging.logger.error "Cleaning up..."
        stop
        ActiveMessaging.logger.error "=> END"
      end
def start subscribe @@connections . each do | name , conn | @@connection_threads [ name ] = Thread . start do while @@running begin Thread . current [ :message ] = nil Thread . current [ :message ] = conn . receive rescue StopProcessingException => spe ActiveMessaging . logger . error "ActiveMessaging: thread[#{name}]: Processing Stopped - receive interrupted, will process last message if already received" rescue Object => exception ActiveMessaging . logger . error "ActiveMessaging: thread[#{name}]: Exception from connection.receive: #{exception.message}\n" + exception . backtrace . join ( "\n\t" ) ensure dispatch Thread . current [ :message ] if Thread . current [ :message ] Thread . current [ :message ] = nil end Thread . pass end ActiveMessaging . logger . error "ActiveMessaging: thread[#{name}]: receive loop terminated" end end while @@running trap ( "TERM" , "EXIT" ) living = false @@connection_threads . each { | name , thread | living ||= thread . alive? } @@running = living sleep 1 end ActiveMessaging . logger . error "All connection threads have died..." rescue Interrupt ActiveMessaging . logger . error "\n<<Interrupt received>>\n" rescue Object => exception ActiveMessaging . logger . error "#{exception.class.name}: #{exception.message}\n\t#{exception.backtrace.join("\n\t")}" raise exception ensure ActiveMessaging . logger . error "Cleaning up..." stop ActiveMessaging . logger . error "=> END" 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
# subscribe - creating connections along the way # for each connection, start a thread #catch these but then stop looping # break #catch all others, but go back and try and recieve again