コード例 #1
0
        public ClusterNode(NodeHeader header)
        {
            this.Header = header;
            nodeList = new NodeList(this);

            Console.WriteLine(header);
            Console.WriteLine();
        }
コード例 #2
0
        public void ElectionResponse(NodeHeader node)
        {
            Node caller = nodeList.GetNode(node);

            if (caller != null)
            {
                caller.ResponseTickCount = Environment.TickCount;
            }
        }
コード例 #3
0
        public void ElectionResult(NodeHeader node)
        {
            lock (syncLock)
            {
                Header.State = NodeState.Follower;

                nodeList.SetLeader(node);

                leaderNode = nodeList.Leader;
            }
        }
コード例 #4
0
        public ClusterWelcomeMessage RegisterNode(NodeHeader node)
        {
            AddNode(node);

            ClusterWelcomeMessage message = new ClusterWelcomeMessage();

            message.NodeID = Header;
            message.NodeList = nodeList.ToHeaderList();

            return message;
        }
コード例 #5
0
        public DiscoveryService(NodeHeader header, NodeConfigCollection addresses)
        {
            this.header = header;

            this.nodes = new List<NodeConfigurationElement>();

            for (int i = 0; i < addresses.Count; i++)
            {
                this.nodes.Add(addresses[i]);
            }
        }
コード例 #6
0
        public void ElectionRequest(NodeHeader node)
        {
            Node caller = nodeList.GetNode(node);

            if (caller != null)
            {
                caller.ElectionResponse(Header);
            }

            lock (syncLock)
            {
                if (Header.State == NodeState.Follower)
                {
                    BroadcastElection();
                }
            }
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: mdelnero/ConsensusSample
        static void Main(string[] args)
        {
            ProgramSettings.Cluster = (ClusterConfigurationSection)ConfigurationManager.GetSection("ClusterSettings/Cluster");

            try
            {
                NodeHeader nodeId = new NodeHeader(Process.GetCurrentProcess().Id, ProgramSettings.Cluster.Endpoint);

                ServiceNode instance = new ServiceNode(nodeId);

                wcfServiceHost.StartPipeHost(instance, nodeId.NodeAddress);

                instance.JoinCluster();
            }
            catch (Exception)
            {
                throw;
            }

            Console.Read();
        }
コード例 #8
0
        public void ElectionResponse(NodeHeader node)
        {
            ChannelCheck();

            channel.ElectionResponse(node);
        }
コード例 #9
0
        public void ElectionRequest(NodeHeader node)
        {
            ChannelCheck();

            channel.ElectionRequest(node);
        }
コード例 #10
0
        public ClusterWelcomeMessage RegisterNode(NodeHeader node)
        {
            ChannelCheck();

            return channel.RegisterNode(node);
        }
コード例 #11
0
 public ServiceNode(NodeHeader nodeID)
     : base(nodeID)
 {
 }
コード例 #12
0
 public void OnNodeRemoved(NodeHeader node)
 {
     Console.WriteLine("Removed: " + node.NodeAddress);
 }
コード例 #13
0
 public void OnNewLeader(NodeHeader node)
 {
     if (node.ID == Header.ID)
     {
         ConsoleColor c = Console.ForegroundColor;
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine("**** LEADER ****");
         Console.ForegroundColor = c;
     }
     else
     {
         Console.WriteLine("NOVO LEADER: " + node.NodeAddress);
     }
 }
コード例 #14
0
        public Node AddNode(NodeHeader nodeHeader)
        {
            Node newNode = null;

            try
            {
                newNode = nodeList.Find(x => x.Header.ID == nodeHeader.ID);

                if (newNode != null)
                {
                    return newNode;
                }

                newNode = new Node(nodeHeader);
                nodeList.Add(newNode);

                newNode.Connect(nodeHeader.NodeAddress);

                OnNodeAdded(newNode.Header);
            }
            catch (Exception)
            {

            }

            return newNode;
        }
コード例 #15
0
        private void JoinCluster(NodeHeader networkNode)
        {
            Node node = AddNode(networkNode);

            if (node.Status == NodeStatus.Alive)
            {
                ClusterWelcomeMessage welcome = node.RegisterNode(Header);

                foreach (var item in welcome.NodeList)
                {
                    if (item.ID == Header.ID)
                    {
                        continue;
                    }

                    Node hop = AddNode(item);

                    if (hop.Status == NodeStatus.Alive)
                    {
                        hop.RegisterNode(Header);
                    }
                }
            }

            leaderNode = nodeList.Leader;
        }