예제 #1
0
        private void DedicatedSocketTask()
        {
            while (_disposeToken.IsCancellationRequested == false)
            {
                try
                {
                    _processNetworkstreamTasksAction();
                }
                catch (Exception ex)
                {
                    if (_disposeToken.IsCancellationRequested)
                    {
                        _log.WarnFormat("KafkaTcpSocket thread shutting down because of a dispose call.");
                        var disposeException = new ObjectDisposedException("Object is disposing.");
                        _sendTaskQueue.DrainAndApply(t => t.Tcp.TrySetException(disposeException));
                        _readTaskQueue.DrainAndApply(t => t.Tcp.TrySetException(disposeException));
                        return;
                    }

                    if (ex is ServerDisconnectedException)
                    {
                        if (OnServerDisconnected != null)
                        {
                            OnServerDisconnected();
                        }
                        _log.ErrorFormat(ex.Message);
                        continue;
                    }

                    _log.ErrorFormat("Exception occured in Socket handler task.  Exception: {0}", ex);
                }
            }
        }
예제 #2
0
        private void SetDisposeExceptonToPenndingTasks(Exception exception = null)
        {
            var disposeException = new ObjectDisposedException("Object is disposing.");

            if (exception == null)
            {
                _log.WarnFormat("KafkaTcpSocket thread shutting down because of a dispose call.");
                _sendTaskQueue.DrainAndApply(t => t.Tcp.TrySetException(disposeException));
                _readTaskQueue.DrainAndApply(t => t.Tcp.TrySetException(disposeException));
            }
            else
            {
                _log.WarnFormat("KafkaTcpSocket not able to connect cancel all PenndingTasks.");
                _sendTaskQueue.DrainAndApply(t => t.Tcp.TrySetException(exception));
                _readTaskQueue.DrainAndApply(t => t.Tcp.TrySetException(exception));
            }
        }
예제 #3
0
        public void TestDrainAnApplyNotInInfiniteLoop()
        {
            var aq = new AsyncCollection <bool>();

            aq.Add(true);

            var task = Task.Run(() => aq.DrainAndApply(x => aq.Add(x)));

            Assert.IsTrue(task.Wait(1000));
        }
예제 #4
0
        private void SetExceptionToAllPendingTasks(Exception ex)
        {
            if (_sendTaskQueue.Count > 0)
            {
                _log.ErrorFormat("KafkaTcpSocket received an exception, cancelling all pending tasks: {0}", ex);
            }

            var wrappedException = WrappedException(ex);

            _sendTaskQueue.DrainAndApply(t => t.Tcp.TrySetException(wrappedException));
            _readTaskQueue.DrainAndApply(t => t.Tcp.TrySetException(wrappedException));
        }
예제 #5
0
        public void TestDrainAnApplyNotInInfiniteLoop()
        {
            var aq = new AsyncCollection<bool>();

            aq.Add(true);

            var task = Task.Run(() => aq.DrainAndApply(x => aq.Add(x)));

            Assert.IsTrue(task.Wait(1000));
        }