Пример #1
0
        /// <summary>
        /// Calls FindSuccessor() remotely, using a default retry value of three.
        /// </summary>
        /// <param name="node">The remote node on which to call FindSuccessor().</param>
        /// <param name="id">The ID to look up.</param>
        /// <param name="retryCount">The number of times to retry the operation in case of error.</param>
        /// <returns>The Successor of ID, or NULL in case of error.</returns>
        public static ChordNode CallFindSuccessor(ChordNode node, ulong id, int retryCount = RetryCount)
        {
            var instance = Instance(node);

            while (retryCount-- > 0)
            {
                try
                {
                    if (ChordNodeInstance.IsInstanceValid(instance, "CallFindSuccessor111111111"))
                    {
                        var retVal = instance.FindSuccessor(id);
                        instance.Close();
                        return(retVal);
                    }
                }
                catch (Exception e)
                {
                    Log(LogLevel.Debug, "Remote Invoker", $"CallFindSuccessor error: {e.Message}");
                }
            }
            if (ChordNodeInstance.IsInstanceValid(instance, "CallFindSuccessor222222222222"))
            {
                instance.Close();
            }
            return(null);
        }
Пример #2
0
        public static void CallNotify(ChordNode remoteNode, ChordNode node, int retryCount = RetryCount)
        {
            var instance = Instance(remoteNode);

            while (retryCount-- > 0)
            {
                try
                {
                    if (ChordNodeInstance.IsInstanceValid(instance, "CallNotify1111111111111111111"))
                    {
                        instance.Notify(node);
                        instance.Close();
                        return;
                    }
                }
                catch (Exception e)
                {
                    Log(LogLevel.Debug, "Remote Invoker", $"CallNotify error: {e.Message}");
                }
            }
            if (ChordNodeInstance.IsInstanceValid(instance, "CallNotify2222222222222222") && instance.State != CommunicationState.Closed)
            {
                instance.Close();
            }
        }
Пример #3
0
        public static ChordNode GetPredecessor(ChordNode node, int retryCount = RetryCount)
        {
            var instance = Instance(node);

            while (retryCount-- > 0)
            {
                try
                {
                    if (ChordNodeInstance.IsInstanceValid(instance, "GetPredecessor111111111111"))
                    {
                        var retVal = instance.Predecessor;
                        instance.Close();
                        return(retVal);
                    }
                }
                catch (Exception e)
                {
                    Log(LogLevel.Debug, "Remote Accessor", $"GetPredecessor error: {e.Message}");
                }
            }
            if (ChordNodeInstance.IsInstanceValid(instance, "GetPredecessor222222222222222") && instance.State != CommunicationState.Closed)
            {
                instance.Close();
            }
            return(null);
        }
Пример #4
0
        private ChordNode GetValidNode()
        {
            var list = GetNodes();

            ChordNode node = null;

            foreach (var n in list)
            {
                if (ChordNodeInstance.IsInstanceValid(ChordServer.Instance(n), "send file"))
                {
                    node = n;
                    break;
                }
            }

            return(node);
        }
Пример #5
0
        public static List <ChordNode> FindServiceAddress()
        {
            var discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());

            Log(LogLevel.Debug, "Discovery", "Discovering ChordNode Instances");
            try
            {
                var endpoints = discoveryClient.Find(new FindCriteria(typeof(IChordNodeInstance))
                {
                    MaxResults = 4
                }).Endpoints;


                var tmp = endpoints.Select(x => {
                    var inst      = Instance(x.Address);
                    ChordNode ret = null;
                    if (ChordNodeInstance.IsInstanceValid(inst, "from FindServiceAddress"))
                    {
                        ret = !inst.LocalNode.Equals(ChordServer.LocalNode) ? inst.LocalNode : null;
                        inst.Close();
                    }
                    return(ret);
                }).Where(x => x != null).ToList();

                if (endpoints.Count > 0)
                {
                    Log(LogLevel.Debug, "FindServiceAddress", $"Discovery {tmp.Count} nodes found");
                    return(tmp);
                }
                else
                {
                    Log(LogLevel.Error, "Discovery", "Nothing found");
                }
            }
            catch (Exception e)
            {
                Log(LogLevel.Error, "Discovery", "Nothing found");
            }
            return(new List <ChordNode>());
        }