public void Post(RaftMessage message) { // TODO handle exceptions properly. _log.Info("Sending request: " + message); if (_currentClient.WebSocket.State == System.Net.WebSockets.WebSocketState.Closed || _currentClient.WebSocket.State == System.Net.WebSockets.WebSocketState.Aborted) { ErrorHandler(null); return; } _currentClient.PostResponse(message); }
public async Task PostResponse(RaftMessage message) { byte[] result; lock (this) { using (var stream = new MemoryStream()) { Serializer.Serialize(stream, message); result = stream.ToArray(); } } await SendMessageAsync(result); }
private async Task <RaftMessage> SendMessageAsync(string destination, RaftMessage message) { if (destination == null) { throw new ArgumentNullException(nameof(destination)); } var semaphor = GetLock(destination); await semaphor.WaitAsync(); try { var stream = await GetTcpStream(destination); var requestData = Serialize(new MessageWrapper { Message = message }); var requestHeader = BitConverter.GetBytes(requestData.Length); Log.Verbose("Sending {Length} bytes to {Destination} - {RequestData}", requestData.Length, destination, Encoding.UTF8.GetString(requestData)); await stream.WriteAsync(requestHeader, 0, 4); await stream.WriteAsync(requestData, 0, requestData.Length); var responseHeader = await stream.ReadExactlyAsync(4); var size = BitConverter.ToInt32(responseHeader, 0); var responseBody = await stream.ReadExactlyAsync(size); Log.Verbose("Recieved {Length} bytes from {Destination} - {RequestData}", size, destination, Encoding.UTF8.GetString(responseBody)); return(Deserialize(responseBody).Message); } finally { semaphor.Release(); } }
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: private org.neo4j.causalclustering.core.consensus.RaftMessages_ReceivedInstantClusterIdAwareMessage<?> wrap(java.time.Instant instant, RaftMessage message) private RaftMessages_ReceivedInstantClusterIdAwareMessage <object> Wrap(Instant instant, RaftMessage message) { return(RaftMessages_ReceivedInstantClusterIdAwareMessage.of(instant, _localClusterId, message)); }
private RaftMessages_ReceivedInstantClusterIdAwareMessage Wrap(RaftMessage message) { return(Wrap(_now, message)); }