public ServerSideSubscription(ServerSideSession session, string subscriptionId, MessageQueue messageQueue, string ack) { Session = Verify.ArgumentNotNull(session, "session"); SubscriptionId = Verify.ArgumentNotNull(subscriptionId, "subscriptionId"); MessageQueue = Verify.ArgumentNotNull(messageQueue, "messageQueue"); MessageQueue.AddSubscription(this); AutoAcknowledge = ack == StompAck.Auto; MessageQueue.MessageReceived += MessageQueueMessageReceived; MessageQueue.MessagePublished += MessageQueueMessagePublished; }
public MessageQueue FindMessageQueue(string messageQueueName) { using (_lockObject.Lock()) { MessageQueue mq; if (!_messageQueues.TryGetValue(messageQueueName, out mq)) { mq = new MessageQueue(messageQueueName); _messageQueues.Add(messageQueueName, mq); if (mq.Name == typeof(ServerStatusMessage).FullName) { // special message queue name -- receives status messages _serverStatusMessageQueue = mq; // start the timer to fire soon _serverStatusTimer.Change(TimeSpan.FromMilliseconds(100), TimeSpan.FromMilliseconds(-1)); } else if (mq.Name == typeof(MessageLogMessage).FullName) { _messageLogMessageQueue = mq; } } return mq; } }
private void CleanupCallback(object state) { IEnumerable<MessageQueue> messageQueues; IEnumerable<ServerSideSession> sessions; List<MessageQueue> unusedMessageQueues = null; List<ServerSideSession> unusedSessions = null; // We don't want to lock all of the data for the time taken to cleanup // everything. What we do is get a list of all message queues and a list // of all sessions, and rely on the locks for each during the cleanup // process. using (_lockObject.Lock()) { if (_isDisposed) { return; } messageQueues = new List<MessageQueue>(_messageQueues.Values); sessions = new List<ServerSideSession>(_sessions.Values); } foreach (var messageQueue in messageQueues) { messageQueue.RemoveExpired(); if (messageQueue.IsUnused) { using (_lockObject.Lock()) { if (messageQueue.IsUnused) { Log.Debug("Clean up message queue " + messageQueue.Name); _messageQueues.Remove(messageQueue.Name); if (unusedMessageQueues == null) { unusedMessageQueues = new List<MessageQueue>(); } unusedMessageQueues.Add(messageQueue); } } } } foreach (var session in sessions) { if (session.Cleanup()) { // This session has now been removed from the _sessions collection Log.Debug("Clean up session " + session.SessionId + ": " + session.ClientId); if (unusedSessions == null) { unusedSessions = new List<ServerSideSession>(); } unusedSessions.Add(session); } } if (unusedMessageQueues != null) { foreach (var messageQueue in unusedMessageQueues) { messageQueue.Dispose(); } } if (unusedSessions != null) { foreach (var session in unusedSessions) { session.Dispose(); } } using (_lockObject.Lock()) { if (_serverStatusMessageQueue != null && _serverStatusMessageQueue.IsDisposed) { _serverStatusMessageQueue = null; } if (_messageLogMessageQueue != null && _messageLogMessageQueue.IsDisposed) { _messageLogMessageQueue = null; } } StartCleanupTimer(); }