public Node(DistributionCommon.Schematic.Node schematic, LostNodeHandler lostHandler, RecoveredNodeHandler recoveredHandler, TimeoutHandler timeoutHandler, AssignedJobGetter jobGetter, int pingDelay) { this.Schematic = schematic; this.Reachable = false; this.client = new NetClient(this.Schematic.Address, this.Schematic.Port, this.RequestFailedHandler); this.Awake = true; this.pingDelay = pingDelay; this.watchdog = new Thread(() => this.PingLoop()); this.watchdog.Start(); Thread.Sleep(pingDelay); if (this.Reachable) { if (this.Status()) { this.Reset(); } this.Construct(); } else { this.watchdog.Abort(); throw new InitializationException(); } this.LostNode += lostHandler; this.RecoveredNode = recoveredHandler; this.Timeout += timeoutHandler; this.assignedJobs = jobGetter; }
private bool AddNode(DistributionCommon.Schematic.Node node) { bool success = false; if (!this.nodes.ContainsKey(node.ID)) { try { this.logger.Log(string.Format("Initializing node ID:{0}", node.ID)); this.nodes.Add(node.ID, new Node(node, this.LostNodeHandler, this.RecoveredNodeHandler, this.TimeoutHandler, this.AssignedJobGetter, this.config.PingDelay)); this.logger.Log(string.Format("Node ID:{0} initialized successfully", node.ID)); success = true; this.OnDistributionModification(); } catch (Node.InitializationException) { this.logger.Log("Failed to initialize node", 2); if (this.nodes.ContainsKey(node.ID)) { this.nodes.Remove(node.ID); } } } return(success); }
private Tuple <bool?, DistributionCommon.Comm.Responses.Base> HandleRequest(DistributionCommon.Comm.Requests.Construct request) { bool success = false; if (!this.constructed) { this.schematic = request.Schematic; this.constructed = true; success = true; } return(new Tuple <bool?, DistributionCommon.Comm.Responses.Base>(success, new DistributionCommon.Comm.Responses.Construct(success))); }
private Tuple <bool?, DistributionCommon.Comm.Responses.Base> HandleRequest(DistributionCommon.Comm.Requests.Reset request) { bool success = false; if (this.constructed) { this.schematic = default(DistributionCommon.Schematic.Node); this.constructed = false; foreach (var worker in this.workers.Values.ToList().FindAll(w => w.Awake)) { worker.Sleep(); } this.workers = new Dictionary <int, DistributedWorker.Worker>(); success = true; } return(new Tuple <bool?, DistributionCommon.Comm.Responses.Base>(success, new DistributionCommon.Comm.Responses.Reset(success))); }
public Construct(DistributionCommon.Schematic.Node schematic) : base() { this.Schematic = schematic; }