Exemplo n.º 1
0
 private void UpdateNodesLifetime(StatusMessage statusMessage)
 {
     try
     {
         lock (activeNodes)
         {
             NodeEntry node = null;
             lock (activeNodes)
             {
                 node = activeNodes[statusMessage.Id];
                 if (node == null)
                 {
                     _logger.Error("Error updating node lifetime. Could not find node: " + statusMessage.Id);
                     return;
                 }
                 node.LastStatusSentTime = DateTime.Now;
                 _logger.Debug("Updated node lifetime. Nodeid: " + statusMessage.Id);
             }
         }
     }
     catch (Exception ex)
     {
         _logger.Error("Could not update nodes lifetime. NodeId: " + statusMessage.Id + ". Exception: " + ex.ToString());
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Registers node in server and adds it to active nodes queue
        /// </summary>
        /// <param name="newId"></param>
        /// <param name="type"></param>
        /// <param name="solvableProblems"></param>
        /// <param name="parallelThreads"></param>
        /// <returns>0 if success, negative value if there was an error</returns>
        private void RegisterNode(ulong newId, RegisterType type, List <string> solvableProblems, byte parallelThreads)
        {
            var node = new NodeEntry(newId, type, solvableProblems, parallelThreads);

            lock (activeNodes)
            {
                activeNodes.Add(newId, node);
                _logger.Debug("Node added to server list");
            }
        }
Exemplo n.º 3
0
        private NodeEntry GetActiveNode(ulong nodeId)
        {
            NodeEntry node = null;

            if (!activeNodes.TryGetValue(nodeId, out node))
            {
                string errorMessage = "Could not get value of nodeId: " + nodeId + " from dictionary.";
                _logger.Error(errorMessage);
            }
            return(node);
        }
Exemplo n.º 4
0
        private ComputationMessage GetTaskForComputationalNode(NodeEntry node)
        {
            PartialProblemsMessage partialProblem = null;

            lock (partialProblems)
            {
                partialProblem = partialProblems.FirstOrDefault(x => node.SolvingProblems.Contains(x.ProblemType));
                if (partialProblem != null)
                {
                    partialProblems.Remove(partialProblem);
                }
            }
            return(partialProblem);
        }
Exemplo n.º 5
0
        private ComputationMessage GetTaskForNode(NodeEntry node)
        {
            switch (node.Type)
            {
            case RegisterType.TaskManager:
                return(GetTaskForTaskManager(node));

            case RegisterType.ComputationalNode:
                return(GetTaskForComputationalNode(node));

            default:
                _logger.Error("GetTaskForNode error: Unknown node type");
                return(null);
            }
        }
Exemplo n.º 6
0
        private ComputationMessage GetTaskForTaskManager(NodeEntry node)
        {
            var divideMessage = GetDivideProblemMessageForType(node.SolvingProblems);

            if (divideMessage != null)
            {
                return(divideMessage);
            }
            var partialSolutionsMessage = GetPartialSolutionForType(node.Type);

            if (partialSolutionsMessage != null)
            {
                return(partialSolutionsMessage);
            }
            return(null);
        }
Exemplo n.º 7
0
 private void RemoveUnusedNodes()
 {
     lock (activeNodes)
     {
         var nodesToDelete = activeNodes.Where(x => HasNodeExpired(x.Value)).ToList();
         for (int i = 0; i < nodesToDelete.Count; i++)
         {
             var       nodeToDelete = nodesToDelete[i];
             NodeEntry deletedNode  = null;
             lock (activeNodes)
             {
                 if (!activeNodes.Remove(nodeToDelete.Key))
                 {
                     _logger.Error("Could not remove node from activeNodes list. NodeId: " + nodeToDelete.Key);
                 }
             }
             _logger.Debug("Removed node from activeNodes list. NodeId: " + nodeToDelete.Key);
         }
     }
 }
Exemplo n.º 8
0
 private bool HasNodeExpired(NodeEntry x)
 {
     return((DateTime.Now - x.LastStatusSentTime) > DefaultTimeout);
 }