void IAgentsEngine.warn_inactive_agents(AgentInfo[] agents) { foreach (var agent in agents) { _log.Trace("Agent is inactive; {0}", agent.AsSingleLineJson()); } }
void IAgentsEngine.send_goodbye_msgs(AgentInfo[] agents, string goodbyeAgent) { foreach (var agent in agents) { if (agent.AgentUri == goodbyeAgent) continue; _messenger.SendGoodbyeMsg(agent.AgentUri, goodbyeAgent); } }
AgentInfo[] IAgentsEngine.send_hello_msgs(AgentInfo[] agents, AgentInfo helloAgent, int snapshotId) { var cleanAgents = new List<AgentInfo>(); cleanAgents.Add(helloAgent); foreach (var agent in agents) { if (agent.ClearAgentsListIsCompleted == 0) continue; bool sent = _messenger.SendHelloMsg(agent.AgentUri, helloAgent.AgentUri, snapshotId); if (sent) cleanAgents.Add(agent); } return cleanAgents.ToArray(); }
void IHubRepo.SetConsequentSnapshotId(AgentInfo agent, int snapshotId, DateTime now) { lock (_mutex) _impl.SetConsequentSnapshotId(agent, snapshotId, now); }
void IHubRepo.AgentsAreUpdated(AgentInfo refAgent, AgentInfo[] cleanAgents, int snapshotId) { lock (_mutex) _impl.AgentsAreUpdated(refAgent, cleanAgents, snapshotId); }
AgentInfo[] IHubRepo.QueryDirtyAgents(AgentInfo refAgent, int snapshotId) { lock (_mutex) return _impl.QueryDirtyAgents(refAgent, snapshotId); }
private List<string> get_agent_state(AgentInfo agent) { List<string> list; _state.TryGetValue(agent.AgentUri, out list); if (list != null) return list; list = new List<string>(); _state[agent.AgentUri] = list; return list; }
private AgentInfo new_agent_info(string agentUri) { var agent = new AgentInfo { AgentUri = agentUri, SnapshotId = 0 }; _agents.Add(agentUri, agent); _state[agentUri] = null; return agent; }
void IHubRepo.SetConsequentSnapshotId(AgentInfo agent, int snapshotId, DateTime now) { Validate.NotNull(agent); agent.LastUpdateAt = now; if (agent.SnapshotId >= snapshotId) return; agent.SnapshotId = snapshotId; _state[agent.AgentUri] = null; }
AgentInfo[] IHubRepo.QueryDirtyAgents(AgentInfo refAgent, int snapshotId) { var allAgents = _agents.Values.ToArray(); var cleanAgents = get_agent_state(refAgent); Validate.NotNull(cleanAgents); var query = from agent in allAgents where !cleanAgents.Contains(agent.AgentUri) select agent; var dirtyAgents = query.ToArray(); return dirtyAgents; }
void IHubRepo.AgentsAreUpdated(AgentInfo refAgent, AgentInfo[] cleanAgents, int snapshotId) { if (refAgent.SnapshotId > snapshotId) return; var list = get_agent_state(refAgent); foreach (var agent in cleanAgents) { add_clean_agent_to_state(list, agent.AgentUri); } }
private void remove_dead_agents(AgentInfo[] agents, TimeSpan deadAgentTtl) { foreach (var agent in agents) { _log.Info("Agent at '{0}' is dead (ttl='{1}'; sending goodbye message)", agent.AgentUri, deadAgentTtl); agent_is_gone(agent.AgentUri); } }
private void clear_remote_agents_on_first_hello(AgentInfo agent) { if (Interlocked.CompareExchange(ref agent.ClearAgentsListIsSent, 1, 0) > 0) return; Interlocked.Increment(ref _counters.NewAgents); _messenger.ClearAgentsList(agent.AgentUri); agent.ClearAgentsListIsCompleted = 1; }