Exemplo n.º 1
0
        /// <summary>
        /// Handles component's deregistration by reclaiming all the work it's currently been doing.
        /// </summary>
        /// <param name="sender">Component overseer that invoked the event.</param>
        /// <param name="e">Information about the deregistration.</param>
        private void OnComponentDeregistration(object sender, DeregisterationEventArgs e)
        {
            var componentType = e.Component.ComponentType;

            if (componentType == ComponentType.CommunicationServer)
            {
                var backup = e.Component as BackupServerInfo;

                throw new NotImplementedException();
                // TODO implement
            }
            if (componentType == ComponentType.TaskManager)
            {
                var component = e.Component as SolverNodeInfo;

                var problemsBeingDivided = _problems.Values.Where(p =>
                                                                  p.DividingNodeId == component.ComponentId &&
                                                                  p.State == Problem.ProblemState.BeingDivided);

                foreach (var p in problemsBeingDivided)
                {
                    p.DividingNodeId = null;
                    p.State          = Problem.ProblemState.AwaitingDivision;
                }

                var partialSolutionsBeingMerged = _partialSolutions.Values.Where(ps =>
                                                                                 ps.MergingNodeId == component.ComponentId &&
                                                                                 ps.State == PartialSolution.PartialSolutionState.BeingMerged);

                foreach (var ps in partialSolutionsBeingMerged)
                {
                    ps.MergingNodeId = null;
                    ps.State         = PartialSolution.PartialSolutionState.AwaitingMerge;
                }
            }
            else if (componentType == ComponentType.ComputationalNode)
            {
                var component = e.Component as SolverNodeInfo;

                var partialProblemsBeingComputed = _partialProblems.Values.Where(pp =>
                                                                                 pp.ComputingNodeId == component.ComponentId &&
                                                                                 pp.State == PartialProblem.PartialProblemState.BeingComputed);

                foreach (var pp in partialProblemsBeingComputed)
                {
                    pp.ComputingNodeId = null;
                    pp.State           = PartialProblem.PartialProblemState.AwaitingComputation;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Tries to deregister a cluster component.
        /// </summary>
        /// <param name="componentId">ID of the component to deregister.</param>
        /// <returns>True if succeeded to deregister the component. False otherwise.</returns>
        public bool TryDeregister(ulong componentId)
        {
            ComponentInfo deregisteredComponent;

            if (_registeredComponents.TryRemove(componentId, out deregisteredComponent))
            {
                if (Deregistration != null)
                {
                    Logger.Info("Deregistering " + deregisteredComponent.ComponentType +
                                " (id: " + deregisteredComponent.ComponentId + ").");

                    var args = new DeregisterationEventArgs
                    {
                        Component = deregisteredComponent
                    };
                    Deregistration(this, args);
                }
                return(true);
            }
            return(false);
        }