Retrieve a message from the queue. Returns nil if no message is waiting
 in the given poll time. Otherwise it returns a Message.

 @param [Fixnum] poll_time
 @return [Message,nil]
 @raise [AwsActionError]
320121
def retrieve(poll_time = 1)
      response = client.receive_message(url, {"WaitTimeSeconds" => poll_time, "MaxNumberOfMessages" => 1})
      raise QueueNotFound.new(self, "not found at #{url}") if response.http_response.status == 404

      response.doc.xpath("//Message").map do |element|
        attributes = Hash[*element.xpath("Attribute").map do |attr_element|
          [attr_element.xpath("Name").text, attr_element.xpath("Value").text]
        end.flatten]

        Message.new(self, element.xpath("MessageId").text,
                    element.xpath("ReceiptHandle").text,
                    element.xpath("Body").text,
                    attributes
                   )
      end.first
    end
406594
def _async_poll(self, poller, async_seconds, async_poll_interval):
        '''  '''

        results = poller.wait(async_seconds, async_poll_interval)

        # mark any hosts that are still listed as started as failed
        # since these likely got killed by async_wrapper
        for host in poller.hosts_to_poll:
            reason = { 'failed' : 1, 'rc' : None, 'msg' : 'timed out' }
            self.runner_callbacks.on_failed(host, reason)
            results['contacted'][host] = reason

        return results
727535
def last_downtime
      send_message!(Protocol::Device::GetInfo.new,
         wait_for: Protocol::Device::StateInfo) do |payload|
        payload.downtime.to_f / NSEC_IN_SEC
      end
    end
979950
private Message pollPrefetchQueue() {
        final Message message = this.prefetchedMessages.poll();
        if (message != null) {
            // message lastReceivedOffset should be up-to-date upon each poll - as recreateLink will depend on this
            this.lastReceivedMessage = message;
            this.sendFlow(1);
        }

        return message;
    }
478175
async def poll_event(self):
        
        try:
            msg = await self.recv()
            await self.received_message(msg)
        except websockets.exceptions.ConnectionClosed as exc:
            if self._can_handle_close(exc.code):
                log.info('Websocket closed with %s (%s), attempting a reconnect.', exc.code, exc.reason)
                raise ResumeWebSocket(self.shard_id) from exc
            else:
                log.info('Websocket closed with %s (%s), cannot reconnect.', exc.code, exc.reason)
                raise ConnectionClosed(exc, shard_id=self.shard_id) from exc
805197
def receive(timeout = nil, &block)
      message = nil
      Timers::Wait.for(timeout) do |_remaining|
        message = check(timeout, &block)
        break if message
      end
      return message if message
      raise TaskTimeout, "receive timeout exceeded"
    end
274568
def get_response_time(chatbot, statement='Hello'):
    
    import time

    start_time = time.time()

    chatbot.get_response(statement)

    return time.time() - start_time
1284311
def call( severity, time, progname, msg )
      return if msg.blank? || _silence?( msg )

      msg = [
        _tagged( time, :timestamp ),
        _tagged( progname, :progname ),
        formatted_severity_tag( severity ),
        formatted_message( severity, msg )
      ].compact.join(" ")

      super severity, time, progname, msg
    end
67182
def result(self, msg, do_reset=False):
        
        result = "%s (%s s)" % (msg, time.time() - self.start)
        if do_reset:
            self.start = time.time()
        return result
436146
@Override
    public V pollFromAny(long timeout, TimeUnit unit, String... queueNames) throws InterruptedException {
        return get(pollFromAnyAsync(timeout, unit, queueNames));
    }
383370
def poll_from source, opts={}
    debug "trying to acquire poll lock for: #{source}..."
    if source.try_lock
      begin
        source.poll do |sym, args|
          case sym
          when :add
            m = Message.build_from_source source, args[:info]
            old_m = Index.build_message m.id
            m.labels += args[:labels]
            m.labels.delete :inbox  if source.archived?
            m.labels.delete :unread if source.read?
            m.labels.delete :unread if m.source_marked_read? # preserve read status if possible
            m.labels.each { |l| LabelManager << l }
            m.labels = old_m.labels + (m.labels - [:unread, :inbox]) if old_m
            m.locations = old_m.locations + m.locations if old_m
            HookManager.run "before-add-message", :message => m
            yield :add, m, old_m, args[:progress] if block_given?
            Index.sync_message m, true

            if Index.message_joining_killed? m
              m.labels += [:killed]
              Index.sync_message m, true
            end

            ## We need to add or unhide the message when it either did not exist
            ## before at all or when it was updated. We do *not* add/unhide when
            ## the same message was found at a different location
            if old_m
              UpdateManager.relay self, :updated, m
            elsif !old_m or not old_m.locations.member? m.location
              UpdateManager.relay self, :added, m
            end
          when :delete
            Index.each_message({:location => [source.id, args[:info]]}, false) do |m|
              m.locations.delete Location.new(source, args[:info])
              Index.sync_message m, false
              if m.locations.size == 0
                yield :delete, m, [source,args[:info]], args[:progress] if block_given?
                Index.delete m.id
                UpdateManager.relay self, :location_deleted, m
              end
            end
          when :update
            Index.each_message({:location => [source.id, args[:old_info]]}, false) do |m|
              old_m = Index.build_message m.id
              m.locations.delete Location.new(source, args[:old_info])
              m.locations.push Location.new(source, args[:new_info])
              ## Update labels that might have been modified remotely
              m.labels -= source.supported_labels?
              m.labels += args[:labels]
              yield :update, m, old_m if block_given?
              Index.sync_message m, true
              UpdateManager.relay self, :updated, m
            end
          end
        end

      rescue SourceError => e
        warn "problem getting messages from #{source}: #{e.message}"

      ensure
        source.go_idle
        source.unlock
      end
    else
      debug "source #{source} is already being polled."
    end
  end
1021747
def get_message(self, message_id):
        

        for message in self.messages:
            if message.id == message_id:
                return message

        raise ArgumentError("Message ID not found", message_id=message_id)
2603
def _get_message(self, block=True, timeout=0.1, get_partition_info=None,
                     update_offset=True):
        
        start_at = time.time()
        while self.queue.empty():
            # We're out of messages, go grab some more.
            log.debug('internal queue empty, fetching more messages')
            with FetchContext(self, block, timeout):
                self._fetch()

            if not block or time.time() > (start_at + timeout):
                break

        try:
            partition, message = self.queue.get_nowait()

            if update_offset:
                # Update partition offset
                self.offsets[partition] = message.offset + 1

                # Count, check and commit messages if necessary
                self.count_since_commit += 1
                self._auto_commit()

            if get_partition_info is None:
                get_partition_info = self.partition_info
            if get_partition_info:
                return partition, message
            else:
                return message
        except queue.Empty:
            log.debug('internal queue empty after fetch - returning None')
            return None
630695
def _got_message(self, uid, text):
        
        #TODO: use try
        e = Event(uid, E_MESSAGE, text)
        self.queue.put_nowait(e)

        self.controllers[uid][2] = time.time()
1296710
def get(self, timeout=None):
        
        if timeout is None:
            self._lock.acquire()
        else:
            self._wait(timeout)
        
        res = self.result
        if res[0]:
            return res[1]
        else:
            raise res[1]
713425
def _wait_time(self, shard_state, secs, now=datetime.datetime.now):
    
    assert shard_state.slice_start_time is not None
    delta = now() - shard_state.slice_start_time
    duration = datetime.timedelta(seconds=secs)
    if delta < duration:
      return util.total_seconds(duration - delta)
    else:
      return 0
1135928
String waitAndGetMessage() {
    synchronized (this) {
      // Wait for a message to send.
      while (this.statusMessagesToSend.isEmpty()) {
        try {
          this.wait();
        } catch (final InterruptedException e) {
          LOG.log(Level.FINE, "Interrupted. Ignoring.");
        }
      }

      // Send the message
      return getMessageForStatus(this.statusMessagesToSend.poll());
    }
  }