public void Dispose() { lock (this) { this.isDisposed = true; this.consumer.Dispose(); this.consumer = null; if (this.replyProducer != null) { this.replyProducer.Dispose(); this.replyProducer = null; } this.requestReplyCallback = null; this.session.Dispose(); this.session = null; this.connection.ConnectionInterrupted -= new EventHandler<NmsConnectionEventArgs>(connection_ConnectionInterrupted); this.connection.ConnectionResumed -= new EventHandler<NmsConnectionEventArgs>(connection_ConnectionResumed); this.connection = null; } }
internal IDestination GetDestination(INmsSession session) { switch (this.destinationType) { case DestinationType.Destination: return this.destination; case DestinationType.DestinationName: return session.GetDestination(this.destinationName); default: throw new NotImplementedException("Could not get destination."); } }
private void SetupRequestReply(INmsConnection connection, Destination destination, Func<MessageFactory, IMessage, IMessage> messageReceivedCallback, string selector = null) { this.session = connection.GetSession(); this.consumer = (selector == null) ? this.session.CreateConsumer(destination.GetDestination(this.session)) : session.CreateConsumer(destination.GetDestination(this.session), selector); this.consumer.Listener += new MessageListener(this.RequestReplyCallback); this.replyProducer = this.session.CreateProducer(); this.replyProducer.DeliveryMode = MsgDeliveryMode.NonPersistent; this.isInitialized = true; }
private void SetupRequestOnly(INmsConnection connection, Destination destination, Action<IMessage> messageReceivedCallback, string selector = null) { this.session = connection.GetSession(); this.consumer = (selector == null) ? this.session.CreateConsumer(destination.GetDestination(this.session)) : session.CreateConsumer(destination.GetDestination(this.session), selector); this.consumer.Listener += new MessageListener(this.RequestOnlyCallback); this.isInitialized = true; }
public void Dispose() { lock (this) { this.producer.Dispose(); this.producer = null; if (this.isInitializedForSynchronous) { this.responseBuffer.Clear(); this.responseBuffer = null; this.responseConsumer.Dispose(); this.responseConsumer = null; } this.connection.ConnectionInterrupted -= new EventHandler<NmsConnectionEventArgs>(connection_ConnectionInterrupted); this.connection.ConnectionResumed -= new EventHandler<NmsConnectionEventArgs>(connection_ConnectionResumed); this.session.Dispose(); this.session = null; this.messageFactory = null; this.connection = null; this.destination = null; this.asr.Close(); this.asr = null; } }
private void Setup(INmsConnection connection, MsgDeliveryMode deliveryMode, bool synchronous) { this.isSynchronous = synchronous; this.deliveryMode = deliveryMode; this.connection = connection; this.session = connection.GetSession(); this.messageFactory = new MessageFactory(this.session.InnerSession); this.connection.ConnectionInterrupted += new EventHandler<NmsConnectionEventArgs>(connection_ConnectionInterrupted); this.connection.ConnectionResumed += new EventHandler<NmsConnectionEventArgs>(connection_ConnectionResumed); if (this.innerDestination == null) { this.producer = this.session.CreateProducer(); } else { this.destination = this.innerDestination.GetDestination(this.session); this.producer = this.session.CreateProducer(this.destination); } this.producer.DeliveryMode = deliveryMode; if (synchronous) this.InitializeForSynchronous(); this.isInitialized = true; this.asr.Set(); }
void connection_ConnectionInterrupted(object sender, NmsConnectionEventArgs e) { lock (this) { if (this.connection != sender) return; this.isInitialized = false; this.isInitializedForSynchronous = false; this.asr.Reset(); log.Warn("[{0}] Producer #{1}'s connection was lost. Attempting to recreate.", e.Connection.ID, this.id); this.producer.Dispose(); this.producer = null; this.session.Dispose(); this.session = null; try { this.Setup(this.connection, this.deliveryMode, this.isSynchronous); } catch (Exception ex) { log.Warn("[{0}] Failed to recreate producer using this connection ({1}). Waiting for resume condition to restart.", e.Connection.ID, ex.Message); } } }