private async Task<WriteResult> WriteNeighbour(string name, string content, IWriteableChannel channel = null) { string result = null; try { LogFacade.Instance.LogDebug("Write to " + name + " with content: '" + content + "'"); var chan = channel ?? ChannelPrototype.NewInstance(); // Timeout is config result = await chan.Write(name.ToString(), content, Configuration.Get(Constants.Configuration.ResponseLimit)); LogFacade.Instance.LogDebug("Neighbour (" + name + ") queried, with result '" + (result.IsNull() ? "<null>" : result)); } catch (Exception ex) { LogFacade.Instance.LogWarning("Neighbour (" + name + ") queried, general exception abend '" + RecurseException(ex) + "'"); } return new WriteResult { Response = result, Name = name }; }
// A null neighbour is returned if cannot be reached public async Task<Neighbour> QueryNeighbour(string name, IWriteableChannel channel = null) { Neighbour n = null; try { Stopwatch watch = new Stopwatch(); watch.Start(); string result = (await WriteNeighbour(name.ToString(), Builder.Create(new QueryRequest { Requester = Network.HostName, Timeout = Configuration.Get(Constants.Configuration.ResponseLimit) }), channel)).Response; n = result.IsNull() ? Neighbour.NonRespondingNeighbour(name) : Parser.As<Neighbour>(result); watch.Stop(); n.LastRequestElapsedTime = watch.ElapsedMilliseconds; } catch (Exception ex) { LogFacade.Instance.LogException("Neighbour write and parse failed for " + name, ex); n = Neighbour.NonRespondingNeighbour(name); } LogFacade.Instance.LogDebug("QueryNeighbour " + name + " completed in " + n.LastRequestElapsedTime + " ms"); return n; }