예제 #1
0
        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;
            }
        }
예제 #2
0
 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);
 }
예제 #3
0
 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);
     }
 }
예제 #4
0
 public static void StopGlobalInstance()
 {
     lock (instanceLock)
     {
         instance.Stop();
         instance = null;
     }
 }
예제 #5
0
 public static void StartGlobalInstance()
 {
     lock (instanceLock)
     {
         if (instance != null)
             instance.Start();
         else
         {
             instance = new NmsConnectionPool();
             instance.Start();
         }
     }
 }
예제 #6
0
 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);
 }
예제 #7
0
        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;
        }
예제 #8
0
        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;
        }
예제 #9
0
        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);
            }
        }
예제 #10
0
 public NmsConnectionEventArgs(INmsConnection connection)
 {
     this.Connection = connection;
 }
예제 #11
0
        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;
            }
        }
예제 #12
0
 private NmsProducer(INmsConnection connection)
     : this()
 {
     this.Setup(connection, MsgDeliveryMode.Persistent, false);
 }
예제 #13
0
 internal NmsProducer(INmsConnection connection, Destination destination, MsgDeliveryMode deliveryMode = MsgDeliveryMode.Persistent, bool synchronous = false)
     : this()
 {
     this.innerDestination = destination;
     this.Setup(connection, deliveryMode, synchronous);
 }
예제 #14
0
        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();
        }
예제 #15
0
        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);
            }
        }