/// <summary> /// Create a new instance of a host with a random ID. /// </summary> public Host() { hostInfo = new HostInfo () { Id = HostCache.RandomId () }; status = HostStatus.NoIdentity; heartbeat.Elapsed += (sender, args) => { log.Info ("Host timed out, terminating"); status = HostStatus.Disconnected; lastInter.DisconnectHost (hostInfo); heartbeat.Stop (); heartbeat.Dispose (); }; NodePool.Instance.Nodes.CollectionChanged += OnGlobalNodesChange; _nodes = new ObservableCollection<NodeInfo> (); _nodes.CollectionChanged += NodesCollectionChanged; }
/// <summary> /// Disconnect the host. /// </summary> /// <param name="hostInfo"></param> public void DisconnectHost(HostInfo hostInfo) { foreach (var node in HostCache.FindHost(hostInfo.Id).Nodes) NodePool.Instance.DestroyNode(node); HostCache.ConnectedHosts.Remove(hostInfo.Id); }
/// <summary> /// Send a message to the host. /// </summary> /// <param name="hostInfo">Host identifier.</param> /// <param name="buildMessage">Message to send.</param> public void SendTo(HostInfo hostInfo, byte[] buildMessage) { lock (server) { server.SendMore(hostInfo.Id); server.Send(buildMessage); } }