/// <summary> /// Serializes and transmits a frame to the server /// </summary> /// <param name="Frame"> /// The <seealso cref="StompFrame"/> to send to the server /// </param> /// <exception cref="ArgumentException"> /// Thrown if /// <list type="number"> /// <item>You attempt to serialize a frame class that has no <seealso cref="StompFrameType"/> attribute</item> /// <item>You attempt to send a frame that is marked as server to client only</item> /// <item>You fail to fill in a mandatory frame parameter</item> /// </list> /// </exception> public void SendFrame(StompFrame Frame) { // Get some metadata about the frame that we'll need StompFrameType SFT = Frame.GetType().GetCustomAttribute <StompFrameType>(); // Validate frame before doing anything else if (SFT == null) { throw new ArgumentException("Attempt to serialize frame without frame type attribute", "Frame"); } if (SFT.Direction == StompFrameDirection.ServerToClient) { throw new ArgumentException("Attempt to send server frame from client", "Frame"); } // Serialize the frame and convert to byte array byte[] Data = Frame.Serialize(); // Now send the frame lock (_Client) { _Client.GetStream().Write(Data, 0, Data.Length); _Client.GetStream().WriteByte(0); _HeartbeatTxIntervalTimeout = _HeartbeatTxInterval; } }
private void ServerStatusCallback(object state) { List<ServerSideSession> sessions; List<MessageQueue> messageQueues; using (_lockObject.Lock()) { if (_serverStatusMessageQueue == null) { return; } sessions = new List<ServerSideSession>(_sessions.Values); messageQueues = new List<MessageQueue>(_messageQueues.Values); } // need to be unlocked to perform this, otherwise we could deadlock var message = new ServerStatusMessage { MessageQueues = new List<MessageQueueStatus>(), Sessions = new List<SessionStatus>(), }; foreach (var session in sessions) { var status = session.CreateSessionStatus(); message.Sessions.Add(status); } foreach (var messageQueue in messageQueues) { var status = messageQueue.CreateStatus(); message.MessageQueues.Add(status); } var frame = new StompFrame(StompCommand.Message); frame.Serialize(message); frame.SetExpires(_config.ServerStatusPeriod); MessageQueue queue; using (_lockObject.Lock()) { queue = _serverStatusMessageQueue; } // ReSharper disable ConditionIsAlwaysTrueOrFalse if (queue != null) // ReSharper restore ConditionIsAlwaysTrueOrFalse { queue.PublishFrame(frame); _serverStatusTimer.Change(_config.ServerStatusPeriod, TimeSpan.FromMilliseconds(-1)); } }
public void LogSendMessage(StompFrame frame, string destination) { MessageQueue messageLoggingQueue = null; if (_messageLogMessageQueue != null) { using (_lockObject.Lock()) { // ReSharper disable ConditionIsAlwaysTrueOrFalse if (_messageLogMessageQueue != null) // ReSharper restore ConditionIsAlwaysTrueOrFalse { messageLoggingQueue = _messageLogMessageQueue; } } } if (messageLoggingQueue != null) { var msg = new MessageLogMessage { SentAt = DateTime.Now, ContentLength = frame.GetInt32(StompHeader.ContentLength, 0), Destination = destination, }; var msgFrame = new StompFrame(StompCommand.Message) { Headers = { {StompHeader.Destination, messageLoggingQueue.Name} } }; msgFrame.Serialize(msg); messageLoggingQueue.PublishFrame(msgFrame); } }
/// <summary> /// Serializes and transmits a frame to the server /// </summary> /// <param name="Frame"> /// The <seealso cref="StompFrame"/> to send to the server /// </param> /// <exception cref="ArgumentException"> /// Thrown if /// <list type="number"> /// <item>You attempt to serialize a frame class that has no <seealso cref="StompFrameType"/> attribute</item> /// <item>You attempt to send a frame that is marked as server to client only</item> /// <item>You fail to fill in a mandatory frame parameter</item> /// </list> /// </exception> public void SendFrame(StompFrame Frame) { // Get some metadata about the frame that we'll need StompFrameType SFT = Frame.GetType().GetCustomAttribute<StompFrameType>(); // Validate frame before doing anything else if (SFT == null) throw new ArgumentException("Attempt to serialize frame without frame type attribute", "Frame"); if (SFT.Direction == StompFrameDirection.ServerToClient) throw new ArgumentException("Attempt to send server frame from client", "Frame"); // Serialize the frame and convert to byte array byte[] Data = Frame.Serialize(); // Now send the frame lock (_Client) { _Client.GetStream().Write(Data, 0, Data.Length); _Client.GetStream().WriteByte(0); _HeartbeatTxIntervalTimeout = _HeartbeatTxInterval; } }