class M2X::MQTT::Client::PacketRouter
Public Class Methods
new()
click to toggle source
# File lib/m2x/mqtt/client/packet_router.rb, line 5 def initialize @lock = Mutex.new @queues = Hash.new { |hash, key| hash[key] = [] } end
Public Instance Methods
fetch(mqtt_client, topic)
click to toggle source
# File lib/m2x/mqtt/client/packet_router.rb, line 10 def fetch(mqtt_client, topic) @lock.synchronize do packet = @queues[topic].shift return packet if packet loop do packet = mqtt_client.get_packet return packet if topic == packet.topic @queues[packet.topic] << packet end end end
json_fetch(mqtt_client, topic)
click to toggle source
# File lib/m2x/mqtt/client/packet_router.rb, line 24 def json_fetch(mqtt_client, topic) JSON.parse(fetch(mqtt_client, topic).payload) end