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; } }
private NmsConsumer(INmsConnection connection, Destination destination, string selector) { this.id = idCounter++; this.selector = selector; this.destination = destination; this.connection = connection; this.connection.ConnectionInterrupted += new EventHandler<NmsConnectionEventArgs>(connection_ConnectionInterrupted); this.connection.ConnectionResumed += new EventHandler<NmsConnectionEventArgs>(connection_ConnectionResumed); }
internal NmsMultiConsumer(INmsConnection connection, Destination destination, int consumerCount, Func<MessageFactory, IMessage, IMessage> messageReceivedCallback, string selector = null) : this() { for (int i = 0; i < consumerCount; i++) { log.Debug("[{2}] Creating consumer #{0} to destination {1}", i, destination, connection.ID); var consumer = new NmsConsumer(connection, destination, messageReceivedCallback, selector); this.consumers.Add(consumer); } }
public static void StopGlobalInstance() { lock (instanceLock) { instance.Stop(); instance = null; } }
public static void StartGlobalInstance() { lock (instanceLock) { if (instance != null) instance.Start(); else { instance = new NmsConnectionPool(); instance.Start(); } } }
internal NmsConsumer(INmsConnection connection, Destination destination, Func<MessageFactory, IMessage, IMessage> messageReceivedCallback, string selector = null) : this(connection, destination, selector) { this.requestReplyCallback = messageReceivedCallback; this.SetupRequestReply(connection, destination, messageReceivedCallback, selector); }
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; }
void connection_ConnectionResumed(object sender, NmsConnectionEventArgs e) { lock (this) { if (this.isInitialized) return; log.Info("[{0}] Resuming consumer #{1} on this connection.", e.Connection.ID, this.id); this.connection = (INmsConnection)sender; if (this.requestOnlyCallback != null) this.SetupRequestOnly(this.connection, this.destination, this.requestOnlyCallback, this.selector); else if (this.requestReplyCallback != null) this.SetupRequestReply(this.connection, this.destination, this.requestReplyCallback, this.selector); } }
public NmsConnectionEventArgs(INmsConnection connection) { this.Connection = connection; }
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 NmsProducer(INmsConnection connection) : this() { this.Setup(connection, MsgDeliveryMode.Persistent, false); }
internal NmsProducer(INmsConnection connection, Destination destination, MsgDeliveryMode deliveryMode = MsgDeliveryMode.Persistent, bool synchronous = false) : this() { this.innerDestination = destination; this.Setup(connection, deliveryMode, synchronous); }
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_ConnectionResumed(object sender, NmsConnectionEventArgs e) { lock (this) { if (this.isInitialized) return; log.Info("[{0}] Resuming producer #{1} on this connection.", e.Connection.ID, this.id); this.connection = (INmsConnection)sender; this.Setup(this.connection, this.deliveryMode, this.isSynchronous); } }