示例#1
0
        public void Start()
        {
            // Don't try creating session if connection not yet up
            if (!session.IsStarted)
            {
                throw new SessionClosedException();
            }

            if (started.CompareAndSet(false, true))
            {
                try
                {
                    // Create qpid sender
                    Tracer.DebugFormat("Start Producer Id = " + ProducerId.ToString());
                    if (qpidSender == null)
                    {
                        qpidSender = session.CreateQpidSender(destination.Address);
                    }
                }
                catch (Org.Apache.Qpid.Messaging.QpidException e)
                {
                    throw new NMSException("Failed to create Qpid Sender : " + e.Message);
                }
            }
        }
示例#2
0
 protected virtual void StartAsyncDelivery()
 {
     if (asyncDelivery.CompareAndSet(false, true))
     {
         asyncDeliveryThread              = new Thread(new ThreadStart(DispatchLoop));
         asyncDeliveryThread.Name         = "Message Consumer Dispatch: " + messageQueue.QueueName;
         asyncDeliveryThread.IsBackground = true;
         asyncDeliveryThread.Start();
     }
 }
示例#3
0
 /// <summary>
 ///     Starts asynchronous message delivery of incoming messages for this connection.
 ///     Synchronous delivery is unaffected.
 /// </summary>
 public void Start()
 {
     CheckConnected();
     if (!_started.CompareAndSet(false, true))
     {
         return;
     }
     lock (_sessions.SyncRoot)
         foreach (Session session in _sessions)
         {
             session.Start();
         }
 }
示例#4
0
 /// <summary>
 /// Starts asynchronous message delivery of incoming messages for this connection.
 /// Synchronous delivery is unaffected.
 /// </summary>
 public void Start()
 {
     CheckConnected();
     if (started.CompareAndSet(false, true))
     {
         lock (sessions.SyncRoot)
         {
             foreach (Session session in sessions)
             {
                 session.Start();
             }
         }
     }
 }
示例#5
0
 /// <summary>
 /// Starts message delivery for this connection.
 /// </summary>
 public void Start()
 {
     if (started.CompareAndSet(false, true))
     {
         try
         {
             this.xmsConnection.Start();
         }
         catch (Exception ex)
         {
             ExceptionUtil.WrapAndThrowNMSException(ex);
         }
     }
 }
示例#6
0
 public void Close()
 {
     if (closed.CompareAndSet(false, true))
     {
         sessionPool.Clear();
     }
 }
示例#7
0
        public void Close()
        {
            if (closed.CompareAndSet(false, true))
            {
                try
                {
//                    this.sessionPool.Close();
                }
                catch (Exception)
                {
                }
                finally
                {
                    try
                    {
                        this.connection.Close();
                    }
                    catch (Exception)
                    {
                    }
                    finally
                    {
                        connection = null;
                    }
                }
            }
        }
示例#8
0
        internal void ClearMessagesInProgress(ref long transportInterruptionProcessingComplete)
        {
            if (this.executor != null)
            {
                this.executor.ClearMessagesInProgress();
            }

            if (this.consumers.Count == 0)
            {
                return;
            }

            // Because we are called from inside the Transport Reconnection logic
            // we spawn the Consumer clear to another Thread so that we can avoid
            // any lock contention that might exist between the consumer and the
            // connection that is reconnecting.  Use the Connection Scheduler so
            // that the clear calls are done one at a time to avoid further
            // contention on the Connection and Session resources.
            if (clearInProgress.CompareAndSet(false, true))
            {
                using (this.consumersLock.Lock())
                {
                    foreach (MessageConsumer consumer in this.consumers.Values)
                    {
                        consumer.InProgressClearRequired();
                        Interlocked.Increment(ref transportInterruptionProcessingComplete);
                        Scheduler.ExecuteAfterDelay(ClearMessages, consumer, 0);
                    }
                }

                // Clear after all consumer have had their ClearMessagesInProgress method called.
                Scheduler.ExecuteAfterDelay(ResetClearInProgressFlag, clearInProgress, 0);
            }
        }
示例#9
0
 public void shutdown()
 {
     if (_shutdown.CompareAndSet(false, true))
     {
         this.consumers.Clear();
     }
 }
示例#10
0
        /// <summary>
        /// Starts message delivery for this connection.
        /// </summary>
        public void Start()
        {
            // Create and open qpidConnection
            CheckConnected();

            if (started.CompareAndSet(false, true))
            {
                lock (sessions.SyncRoot)
                {
                    foreach (Session session in sessions)
                    {
                        // Create and start qpidSessions
                        session.Start();
                    }
                }
            }
        }
        public void Start()
        {
            if (started.CompareAndSet(false, true))
            {
                DoStartAgent();

                if (worker == null)
                {
                    Tracer.Info("Starting multicast discovery agent worker thread");
                    worker = new Thread(new ThreadStart(DiscoveryAgentRun));
                    worker.IsBackground = true;
                    worker.Start();
                }

                DoAdvertizeSelf();
            }
        }
示例#12
0
 public void shutdown()
 {
     if (_shutdown.CompareAndSet(false, true))
     {
         foreach (SessionState ss in sessions.Values)
         {
             ss.shutdown();
         }
     }
 }
示例#13
0
        protected virtual void StopAsyncDelivery()
        {
            if (asyncDelivery.CompareAndSet(true, false))
            {
                if (null != asyncDeliveryThread)
                {
                    Tracer.Info("Stopping async delivery thread.");
                    pause.Set();
                    if (!asyncDeliveryThread.Join(10000))
                    {
                        Tracer.Info("Aborting async delivery thread.");
                        asyncDeliveryThread.Abort();
                    }

                    asyncDeliveryThread = null;
                    Tracer.Info("Async delivery thread stopped.");
                }
            }
        }
示例#14
0
        protected override void OnException(ITransport sender, Exception command)
        {
            if (!_failed.CompareAndSet(false, true) || _disposing)
            {
                return;
            }

            Tracer.Warn($"Exception received in the Inactivity Monitor: {command.Message}");
            StopMonitorThreads();
            base.OnException(sender, command);
        }
示例#15
0
        public void Close()
        {
            if (closed.CompareAndSet(false, true))
            {
                Stats.RecordCloseAttempt();

                if (Configuration.FailOnClose)
                {
                    throw new Exception();
                }
            }
        }
示例#16
0
        /// <summary>
        /// Create new unmanaged session and start senders and receivers
        /// Associated connection must be open.
        /// </summary>
        public void Start()
        {
            // Don't try creating session if connection not yet up
            if (!connection.IsStarted)
            {
                throw new ConnectionClosedException();
            }

            if (started.CompareAndSet(false, true))
            {
                try
                {
                    // Create qpid session
                    if (qpidSession == null)
                    {
                        qpidSession = connection.CreateQpidSession();
                    }

                    // Start producers and consumers
                    lock (producers.SyncRoot)
                    {
                        foreach (MessageProducer producer in producers.Values)
                        {
                            producer.Start();
                        }
                    }
                    lock (consumers.SyncRoot)
                    {
                        foreach (MessageConsumer consumer in consumers.Values)
                        {
                            consumer.Start();
                        }
                    }
                }
                catch (Org.Apache.Qpid.Messaging.QpidException e)
                {
                    throw new SessionClosedException("Failed to create session : " + e.Message);
                }
            }
        }
示例#17
0
            public Boolean Iterate()
            {
                if (!_pending.CompareAndSet(true, false) || !_parent._monitorStarted.Value)
                {
                    return(_pending.Value);
                }

                var ex = new IoException("Channel was inactive for too long: " + _remote);

                _parent.OnException(_parent, ex);

                return(_pending.Value);
            }
        public void Start()
        {
            // Don't try creating receiver if session not yet up
            if (!session.IsStarted)
            {
                throw new SessionClosedException();
            }

            if (started.CompareAndSet(false, true))
            {
                try
                {
                    // Create qpid receiver
                    Tracer.DebugFormat("Start Consumer Id = " + ConsumerId.ToString());
                    if (qpidReceiver == null)
                    {
                        qpidReceiver = session.CreateQpidReceiver(destination.Address);
                        // Recover replyTo address from qpid receiver and set as the
                        // replyTo destination for received messages.
                        Address replyTo = qpidReceiver.GetAddress();
                        if (destination.IsQueue)
                        {
                            Queue queue = new Queue(replyTo.Name, replyTo.Subject, replyTo.Options);
                            replyToDestination = (Destination)queue;
                        }
                        else if (destination.IsTopic)
                        {
                            Topic topic = new Topic(replyTo.Name, replyTo.Subject, replyTo.Options);
                            replyToDestination = (Destination)topic;
                        }
                    }
                }
                catch (Org.Apache.Qpid.Messaging.QpidException e)
                {
                    throw new NMSException("Failed to create Qpid Receiver : " + e.Message);
                }
            }
        }
示例#19
0
 public override void Start()
 {
     base.Start();
     if (firstStart.CompareAndSet(true, false))
     {
         try
         {
             next.Oneway(wireFormat.PreferredWireFormatInfo);
         }
         finally
         {
             wireInfoSentDownLatch.countDown();
         }
     }
 }
示例#20
0
        private void StopMonitorThreads()
        {
            lock (_monitor)
                if (_monitorStarted.CompareAndSet(true, false))
                {
                    _connectionCheckTimer.Dispose();

                    _connectionCheckTimer.Dispose();

                    _asyncTasks.Shutdown();
                    _asyncTasks     = null;
                    _asyncWriteTask = null;
                    _asyncErrorTask = null;
                }
        }
示例#21
0
            public Boolean Iterate()
            {
                if (!_pending.CompareAndSet(true, false) || !_parent._monitorStarted.Value)
                {
                    return(_pending.Value);
                }

                try
                {
                    var info = new KeepAliveInfo();
                    _parent.Next.Oneway(info);
                }
                catch (IoException ex)
                {
                    _parent.OnException(_parent, ex);
                }

                return(_pending.Value);
            }
示例#22
0
        public static void RunCollector()
        {
            collect = true;

            if (started)
            {
                return;
            }
            started = true;

            cansend.Value = true;

            Device.StartTimer(TimeSpan.FromMilliseconds(Protocol.RefreshSpeed), () =>
            {
                if (collect && cansend.CompareAndSet(true, false))
                {
                    Task.Run(async() =>
                    {
                        try
                        {
                            var xml_scan = await Send(Protocol.ScanHardware);
                            await LoadComponents(xml_scan);
                        }
                        catch (Exception ex)
                        {
                            collect = false;
                            Device.BeginInvokeOnMainThread(() => CollectorFailed?.Invoke(new CollectorFailedEventArgs(ex.Message)));
                        }
                        finally
                        {
                            cansend.Value = true;
                        }
                    });
                }

                return(true);
            });
        }
示例#23
0
        /// <summary>
        ///     Closes the network connection.
        /// </summary>
        private void Close()
        {
            Thread theReadThread = null;

            if (_closed.CompareAndSet(false, true))
            {
                lock ( _startStopLock )
                {
                    try
                    {
                        Socket?.Shutdown(SocketShutdown.Both);
                    }
                    catch
                    {
                        // ignored
                    }

                    try
                    {
                        _socketWriter?.Dispose();
                    }
                    catch
                    {
                        // ignored
                    }
                    finally
                    {
                        _socketWriter = null;
                    }

                    try
                    {
                        _socketReader?.Dispose();
                    }
                    catch
                    {
                        // ignored
                    }
                    finally
                    {
                        _socketReader = null;
                    }

                    try
                    {
                        Socket?.Dispose();
                    }
                    catch
                    {
                        // ignored
                    }

                    theReadThread = _readThread;
                    _readThread   = null;
                    _started      = false;
                }
            }

            if (null == theReadThread)
            {
                return;
            }

            try
            {
                if (Thread.CurrentThread == theReadThread || !theReadThread.IsAlive)
                {
                    return;
                }

                if (!theReadThread.Join((Int32)_maxThreadWait.TotalMilliseconds))
                {
                    theReadThread.Abort();
                }
            }
            catch
            {
                // ignored
            }
        }