/* * A safe operation to call remote methods of all node in the cluster * It offers the possibility to exclude the call of the local method */ //TODO: incTrack -> NOT WORKING LIKE INTENDED, this is just good for the tracker private void clusterAction(ClusterHandler onSucess, bool incTrack) { List <string> disconected = new List <string>(); foreach (KeyValuePair <string, INode> entry in cluster) { INode node = entry.Value; if (node == null) { node = (INode)Activator.GetObject(typeof(INode), entry.Key); } this.workThr.AssyncInvoke(() => { try { onSucess(node); } catch { disconect(entry.Key); } }); } if (incTrack) { onSucess(this); } }
/* * A safe operation to call remote methods of a specific node. * Like the alike 'clusterAction()' it automatically handles disconections. */ private object nodeAction(ClusterHandler onSucess, string url) { object sucess = null; //Obtain node INode node = null; if (url == this.trkUrl) { node = this.tracker; } else { node = cluster[url]; } //Checks if proxy exists if (node == null) { node = (INode)Activator.GetObject(typeof(INode), url); } try { sucess = onSucess(node); } catch //remote server does not exist { //If call failed to tracker then we need a new one if (url == this.trkUrl) { tryPromote(); } else//If call failed to worker then report to tracker { nodeAction((trk) => { trk.disconect(url); return(null); }, this.trkUrl); } } return(sucess); }
/* * See clusterAction(ClusterHandler onSucess, bool incTrack) */ private void clusterAction(ClusterHandler onSucess) { clusterAction(onSucess, true); }