protected internal virtual void OnMessageReceived(Stream messageBody) { ClusterMessage message = m_formatter.Deserialize(messageBody); SnTrace.Messaging.Write("Received a '{0}' message.", message.GetType().FullName); lock (MessageListSwitchSync) { _incomingMessages.Add(message); //TODO: trace incoming and total message count // var totalMessages = _incomingMessages.Count + _messagesCount; } }
/* ============================================================================== Send */ public virtual void Send(ClusterMessage message) { try { message.SenderInfo = m_clusterMemberInfo; message.SenderInfo.ClusterMemberID = this.ReceiverName; Stream messageStream = m_formatter.Serialize(message); SnTrace.Messaging.Write("Sending a '{0}' message", message.GetType().FullName); InternalSend(messageStream, message is DebugMessage); } catch (Exception e) // logged { SnLog.WriteException(e); SnTrace.Messaging.WriteError("Sending a '{0}' message. Exception: {1}", message.GetType().FullName, e); OnSendException(message, e); } }
/* ============================================================================== Send */ public virtual async Task SendAsync(ClusterMessage message, CancellationToken cancellationToken) { try { message.SenderInfo = m_clusterMemberInfo; message.SenderInfo.ClusterMemberID = ReceiverName; Stream messageStream = m_formatter.Serialize(message); SnTrace.Messaging.Write("Sending a '{0}' message", message.GetType().FullName); await InternalSendAsync(messageStream, message is DebugMessage, cancellationToken).ConfigureAwait(false); } catch (Exception e) // logged { SnLog.WriteException(e); SnTrace.Messaging.WriteError("Sending a '{0}' message. Exception: {1}", message.GetType().FullName, e); OnSendException(message, e); } }