Пример #1
0
        private HeartBeatData GetHeartBeatData(byte[] heartBeatDataAsBytes)
        {
            if (heartBeatDataAsBytes.Length == 0)
            {
                throw new HeartBeatDataIsEmptyException();
            }

            BinaryFormatter formatter     = new BinaryFormatter();
            MemoryStream    memStream     = new MemoryStream(heartBeatDataAsBytes);
            HeartBeatData   heartBeatdata = (HeartBeatData)formatter.Deserialize(memStream);

            return(heartBeatdata);
        }
Пример #2
0
        void MessageReceivedCallback(IAsyncResult result)
        {
            if (OnHeartBeatReceived != null)
            {
                IPEndPoint  remoteEndPoint = new IPEndPoint(IPAddress.Broadcast, _protocolPort);
                SocketError socketErrorCode;
                _udpClient.EndReceive(result, out socketErrorCode);
                HeartBeatData heartBeatData = GetHeartBeatData(recBuffer);

                OnHeartBeatReceived(heartBeatData);
            }

            Listen();
        }
Пример #3
0
        private void HeartBeatTracker(HeartBeatData heartBeatData)
        {
            IPAddress nodeIPAddress = new IPAddress(heartBeatData.IPAddress);
            Node      node          = _activeNodes.Find(x => x.EndPoint.ToString() == nodeIPAddress.ToString());

            NodeUpdateAction updateAction;

            if (node != null)
            {
                //update the last heard time, node state
                node.HeartBeatLastHeardAt = DateTime.Now;
                node.NodeState            = heartBeatData.NodeState;
                node.EndPoint             = nodeIPAddress;
                node.ServicePort          = heartBeatData.ServicePort;

                updateAction = NodeUpdateAction.Updated;
            }
            else
            {
                node = new Node()
                {
                    EndPoint             = nodeIPAddress,
                    ServicePort          = heartBeatData.ServicePort,
                    HeartBeatLastHeardAt = DateTime.Now,
                    NodeState            = heartBeatData.NodeState
                };

                lock (_activeNodes)
                {
                    _activeNodes.Add(node); //add the new node which appears to have just come online.
                }

                updateAction = NodeUpdateAction.Added;
            }

            if (OnNodeListUpdated != null)
            {
                OnNodeListUpdated(node, updateAction);
            }
        }
Пример #4
0
        private byte[] GetSerializedHeartBeatData()
        {
            HeartBeatData heartBeatData = new HeartBeatData()
            {
                IPAddress = TcpHelper.SelfIPAddress.GetAddressBytes(),
                ServicePort = _servicePort,
                NodeState = this.NodeState //whatever beat kind is currently mentioned
            };

            BinaryFormatter formatter = new BinaryFormatter();
            MemoryStream memStream = new MemoryStream();
            formatter.Serialize(memStream, heartBeatData);
            return memStream.ToArray();
        }
Пример #5
0
        private void HeartBeatTracker(HeartBeatData heartBeatData)
        {
            IPAddress nodeIPAddress = new IPAddress(heartBeatData.IPAddress);
            Node node = _activeNodes.Find(x => x.EndPoint.ToString() == nodeIPAddress.ToString());

            NodeUpdateAction updateAction;

            if (node != null)
            {
                //update the last heard time, node state
                node.HeartBeatLastHeardAt = DateTime.Now;
                node.NodeState = heartBeatData.NodeState;
                node.EndPoint = nodeIPAddress;
                node.ServicePort = heartBeatData.ServicePort;

                updateAction = NodeUpdateAction.Updated;
            }
            else
            {
                node = new Node()
                {
                    EndPoint = nodeIPAddress,
                    ServicePort = heartBeatData.ServicePort,
                    HeartBeatLastHeardAt = DateTime.Now,
                    NodeState = heartBeatData.NodeState
                };

                lock (_activeNodes)
                {
                    _activeNodes.Add(node); //add the new node which appears to have just come online.
                }

                updateAction = NodeUpdateAction.Added;
            }

            if (OnNodeListUpdated != null)
                OnNodeListUpdated(node, updateAction);
        }