11 from gateway_msgs.msg
import ConnectionStatistics
12 from rocon_gateway
import gateway_hub
13 from rocon_hub_client
import hub_api
14 from rocon_python_comms
import WallRate
17 import rocon_hub_client
30 threading.Thread.__init__(self)
35 self.
hub = gateway_hub.GatewayHub(ip, port, [], [])
36 except rocon_hub_client.HubError
as e:
37 rospy.logfatal(
"Hub Watcher: unable to connect to hub: %s" % str(e))
43 Run the hub watcher (sidekick) thread at the rate specified by the 44 watcher_thread_rate parameter. The watcher thread does the following: 45 1. For all gateways available, see if we have a pinger available. 46 2. Add and remove pingers as necessary 47 3. Depending on pinger stats, update hub appropriately 50 unavailable_set = set()
52 remote_gateway_names = self.hub.list_remote_gateway_names()
55 for name
in remote_gateway_names:
57 gateway_key = hub_api.create_rocon_key(name)
59 ping_key = hub_api.create_rocon_gateway_key(name,
':ping')
60 expiration_time = self.hub._redis_server.ttl(ping_key)
63 if expiration_time
is None or expiration_time == -2:
67 seconds_since_last_seen = int(ConnectionStatistics.MAX_TTL - expiration_time)
72 if seconds_since_last_seen > rate.period:
73 rospy.logwarn(
"Hub Watcher: gateway " + name +
74 " has been unavailable for " + str(seconds_since_last_seen) +
76 unavailable_set.add(gateway_key)
77 self.hub.mark_named_gateway_available(gateway_key,
False, seconds_since_last_seen)
81 rospy.logwarn(
"Hub Watcher: gateway " + name +
82 " has been unavailable for " +
84 " seconds! Removing from hub.")
87 self.hub.unregister_named_gateway(gateway_key)
91 if gateway_key
in unavailable_set:
92 rospy.logwarn(
"Hub Watcher: gateway " + name +
93 " detected available again !")
94 unavailable_set.remove(gateway_key)
95 self.hub.mark_named_gateway_available(gateway_key,
True, seconds_since_last_seen)
def __init__(self, ip, port)