예제 #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
        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;
        }