public void SendMessage(WireSendingMessage message, IEndpoint endpoint) { TransportPipe pipe; var customEndpoint = (CustomTcpEndpoint) endpoint; if (!_endpointToPipe.TryGetValue(customEndpoint, out pipe)) { pipe = new TcpTransportPipeMultiThread(3000000, HighWaterMarkBehavior.Block, customEndpoint.EndPoint, _transport); _endpointToPipe.Add(customEndpoint, pipe); } var wait = default(SpinWait); var sent = false; bool first = true; var buffer = _serializer.Serialize(message.MessageData); do { sent = pipe.Send(new ArraySegment<byte>(buffer, 0, buffer.Length), true); if (!first) wait.SpinOnce(); else first = false; } while (!sent && wait.Count < 1000); if (!sent) //peer is disconnected (or underwater from too many message), raise some event? { Console.WriteLine("AAAAG"); _logger.Info(string.Format("disconnect of endpoint {0}", customEndpoint.EndPoint)); EndpointDisconnected(endpoint); pipe.Dispose(); _endpointToPipe.Remove(customEndpoint); } }
public void SendMessage(WireSendingMessage message, IEndpoint endpoint) { throw new NotImplementedException(); }
private void SendToSelfShadows(Guid messageId, bool processSuccessful, PeerId originatingPeer, IEndpoint originalEndpoint, string originalMessageType, OutboundDisruptorEntry data) { var selfShadows = _selfShadows ?? Enumerable.Empty<ServicePeer>(); if (selfShadows.Any()) { var message = new ShadowCompletionMessage(messageId, originatingPeer, _peerConfiguration.PeerId, processSuccessful, originalEndpoint, originalMessageType); var endpoints = selfShadows.Select(x => x.HandledMessages.Single(y => y.MessageType == typeof(ShadowCompletionMessage)).Endpoint).Distinct(); foreach (var shadowEndpoint in endpoints) { var messageData = CreateMessageWireData(message); var wireMessage = new WireSendingMessage(messageData, shadowEndpoint); data.NetworkSenderData.WireMessages.Add(wireMessage); } } }
private void SendShadowMessages(IEnumerable<MessageSubscription> concernedSubscriptions, MessageWireData messageData, OutboundDisruptorEntry disruptorData) { foreach (var subscription in concernedSubscriptions) { HashSet<ServicePeer> targetShadows; if (_peersToShadows.TryGetValue(subscription.Peer, out targetShadows)) { var endpoints = targetShadows.Select(x => x.HandledMessages.Single(y => y.MessageType == typeof(ShadowMessageCommand)).Endpoint).Distinct(); foreach (var endpoint in endpoints) { var shadowMessage = new ShadowMessageCommand(messageData, subscription.Peer, true, subscription.Endpoint); var shadowMessageData = CreateMessageWireData(shadowMessage); var wireMessage = new WireSendingMessage(shadowMessageData, endpoint); disruptorData.NetworkSenderData.WireMessages.Add(wireMessage); } } } }
public void SendMessage(WireSendingMessage message, IEndpoint endpoint) { ZmqSocket socket; var zmqEndpoint = (ZmqEndpoint)endpoint; if (!_endpointsToSockets.TryGetValue(zmqEndpoint, out socket)) { socket = CreatePushSocket(zmqEndpoint); _endpointsToSockets.Add(zmqEndpoint, socket); } var status = SendStatus.TryAgain; var wait = default(SpinWait); bool first = true; // _watch.Start(); var buffer = _serializer.Serialize(message.MessageData); do { socket.Send(buffer, buffer.Length, SocketFlags.DontWait); status = socket.SendStatus; if (!first) wait.SpinOnce(); else first = false; } while (status == SendStatus.TryAgain && wait.Count < 1000); if (socket.SendStatus != SendStatus.Sent) //peer is disconnected (or underwater from too many message), raise some event? { _logger.Info(string.Format("disconnect of endpoint {0}", zmqEndpoint.Endpoint)); EndpointDisconnected(endpoint); //dispose socket and allow for re-creation of socket with same endpoint; everything will get slow as hell if we continue trying? or only if high water mark socket.Dispose(); _endpointsToSockets.Remove(zmqEndpoint); } }