public void Dispose() { using (_lockObject.Lock()) { _clientConnection = null; foreach (var subscription in _subscriptions.Values) { subscription.Dispose(); } _subscriptions.Clear(); } }
public bool AddConnection(ServerSideConnection clientConnection) { Verify.ArgumentNotNull(clientConnection, "clientConnection"); IEnumerable<ServerSideSubscription> subscriptions = null; using (_lockObject.Lock()) { if (_clientConnection != null) { return false; } _clientConnection = clientConnection; _clientConnection.ConnectionClosed += ClientConnectionClosed; if (_subscriptions.Count > 0) { subscriptions = new List<ServerSideSubscription>(_subscriptions.Values); } } if (subscriptions != null) { foreach (var subscription in subscriptions) { subscription.ReceiveMessagesFromQueue(); } } return true; }
private void ClientConnectionClosed(object sender, EventArgs e) { using (_lockObject.Lock()) { _clientConnection = null; // If there is still no connection at this time, the session will // be considered unused. _expiresAt = DateTime.Now + _serverData.Config.UnusedSessionTimeout; } }
private void ListenerClientConnected(object sender, EventArgs e) { var newConnections = new List<ServerSideConnection>(); Log.Debug("STOMP Client connected"); lock (_lockObject) { if (_isDisposed) { return; } var listener = (IListener<StompFrame>) sender; for (;;) { var transport = listener.GetNextTransport(); if (transport == null) { break; } var clientConnection = new ServerSideConnection(transport, _serverData); clientConnection.ConnectionClosed += ClientConnectionClosed; // Perform a check here because the transport could have disconnected before // we had a chance to subscribe to the ConnectionClosed event of its connection. if (transport.Connected) { _clientConnections.Add(clientConnection); newConnections.Add(clientConnection); } else { Log.Warn("Client connection closed immediately after connection"); } } } // These objects might have received frames before they had a chance to subscribe to events foreach (var clientConnection in newConnections) { clientConnection.ProcessReceivedFrames(); } }