cjwmorgan-sol commented on a change in pull request #4: AMQNET-589: Failover implementation URL: https://github.com/apache/activemq-nms-amqp/pull/4#discussion_r303096850
########## File path: src/NMS.AMQP/NmsSession.cs ########## @@ -0,0 +1,527 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using System.Collections.Concurrent; +using System.Linq; +using System.Threading.Tasks; +using Apache.NMS.AMQP.Message; +using Apache.NMS.AMQP.Meta; +using Apache.NMS.AMQP.Provider; +using Apache.NMS.AMQP.Util; + +namespace Apache.NMS.AMQP +{ + public class NmsSession : ISession + { + private readonly ConcurrentDictionary<Id, NmsMessageConsumer> consumers = new ConcurrentDictionary<Id, NmsMessageConsumer>(); + private readonly ConcurrentDictionary<Id, NmsMessageProducer> producers = new ConcurrentDictionary<Id, NmsMessageProducer>(); + + private readonly NestedIdGenerator consumerIdGenerator; + private readonly NestedIdGenerator producerIdGenerator; + private readonly AtomicBool closed = new AtomicBool(); + private readonly AtomicBool started = new AtomicBool(); + + public SessionInfo SessionInfo { get; } + public NmsConnection Connection { get; } + + private SessionDispatcher dispatcher; + + public NmsSession(NmsConnection connection, Id sessionId, AcknowledgementMode acknowledgementMode) + { + Connection = connection; + AcknowledgementMode = acknowledgementMode; + SessionInfo = new SessionInfo(sessionId) + { + ackMode = acknowledgementMode + }; + consumerIdGenerator = new NestedIdGenerator("ID:consumer", SessionInfo.Id, true); + producerIdGenerator = new NestedIdGenerator("ID:producer", SessionInfo.Id, true); + } + + public bool IsStarted => started; + + internal Task Begin() + { + return Connection.CreateResource(SessionInfo); + } + + public void Close() + { + CheckIsOnDeliveryThread(); + + if (closed.CompareAndSet(false, true)) + { + foreach (NmsMessageConsumer consumer in consumers.Values.ToArray()) Review comment: I noticed that shutdown is not called from here so the SessionDispatcher is still running after the NmsSession is closed also the parent connection still has the closed session as a member. Is detaching the session from the connection handled elsewhere? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
