Exemplo n.º 1
0
 private void RaiseHeartbeatFailed()
 {
     _currentConsumerTaskCancellation.Cancel();
     _heartbeatSocket.Close();
     _heartbeatSocket.Dispose();
     _consumerSocket.Close();
     _consumerSocket.Dispose();
 }
Exemplo n.º 2
0
        public void Dispose()
        {
            _cancel.Cancel();

            _heartbeatSocket.Close();
            _heartbeatSocket.Dispose();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Stop node discovery and interconnection
        /// </summary>
        private void Stop()
        {
            if (!_isRunning)
            {
                return;
            }
            _loggerDelegate?.Invoke($"Stopping {_name} {_uuid.ToShortString6()}. Publishing beacon on port 0. Removing _beacon and _inbox from poller.");

            // Stop broadcast/listen beacon by broadcasting port 0
            PublishBeacon(0);
            Thread.Sleep(1); // Allow 1 millisecond for beacon to go out
            _poller.Remove(_beacon);
            _beacon.ReceiveReady -= OnBeaconReady;
            _beacon.Unsubscribe();
            _beacon.Dispose();
            _beacon = null;

            // Stop polling on inbox
            _poller.Remove(_inbox);
            _inbox.ReceiveReady -= OnInboxReady;
            _inbox.Dispose();


            // Tell the application we are stopping
            var msg = new NetMQMessage(3);

            msg.Append("STOP");
            msg.Append(_uuid.ToByteArray());
            msg.Append(_name);
            _outbox.SendMultipartMessage(msg);
            _isRunning = false;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Release any contained resources.
        /// </summary>
        /// <param name="disposing">true if managed resources are to be released</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!disposing)
            {
                return;
            }

            if (_isRunning)
            {
                Stop();
            }
            if (_poller.IsRunning)
            {
                _poller?.Stop();
            }
            _poller?.Dispose();
            _beacon?.Dispose();
            _inbox?.Dispose();
            _outbox?.Dispose();
            foreach (var peer in _peers.Values)
            {
                peer.Destroy();
            }
            foreach (var group in _peerGroups.Values)
            {
                group.Dispose();
            }
            foreach (var group in _ownGroups.Values)
            {
                group.Dispose();
            }
        }
Exemplo n.º 5
0
        public void Kill()
        {
            _poller.Stop();

            _frontend.Close();
            _frontend.Dispose();

            _backend.Close();
            _backend.Dispose();
        }
Exemplo n.º 6
0
        public void Stop()
        {
            _cancel.Cancel();

            _heartbeatSocket.Close();
            _heartbeatSocket.Dispose();

            _publisherSocket.Close();
            _publisherSocket.Dispose();
        }
Exemplo n.º 7
0
        private void ProxyThread()
        {
            RouterSocket router = null;
            DealerSocket dealer = null;

            try
            {
                router = _ctx.CreateRouterSocket();
                dealer = _ctx.CreateDealerSocket();
                router.Bind(_frontendAddress);
                switch (_backendCxMode)
                {
                case ConnectionMode.Connect:
                    dealer.Connect(_backendAddress);
                    break;

                case ConnectionMode.Bind:
                    dealer.Bind(_backendAddress);
                    break;
                }

                router.Options.Linger = TimeSpan.Zero;
                dealer.Options.Linger = TimeSpan.Zero;
                var xproxy = new Proxy(router, dealer, null);
                xproxy.Start();
            }
            catch (TerminatingException)
            {
            }
            finally
            {
                if (router != null)
                {
                    try
                    {
                        router.Dispose();
                    }
                    catch (NetMQException)
                    {
                    }
                }
                if (dealer != null)
                {
                    try
                    {
                        dealer.Dispose();
                    }
                    catch (NetMQException)
                    {
                    }
                }
            }
        }
Exemplo n.º 8
0
 protected virtual void Dispose(bool disposing)
 {
     if (!disposedValue)
     {
         if (disposing)
         {
             shellSocket?.Dispose();
             controlSocket?.Dispose();
             ioPubSocket?.Dispose();
         }
         disposedValue = true;
     }
 }
Exemplo n.º 9
0
        public void NetMQReceiver_WithNullSerializer_ThrowsArgumentNullException()
        {
            // Arrange
            var socket = new RouterSocket();

            // Act
            TestDelegate test = () => new NetMQReceiver(socket, null, requestDispatcher);

            // Assert
            Assert.That(test, Throws.ArgumentNullException);

            // Cleanup
            socket.Dispose();
        }
Exemplo n.º 10
0
        protected override Task DestroyInternal()
        {
            _cancel.Cancel();

            _poller.Stop();

            _heartbeatSocket.Close();
            _heartbeatSocket.Dispose();

            _stateRequestSocket.Close();
            _stateRequestSocket.Dispose();

            return(Task.CompletedTask);
        }
Exemplo n.º 11
0
        private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    _poller?.Dispose();
                    _responseSocket?.Dispose();
                    _publisherSocket?.Dispose();
                }

                disposedValue = true;
            }
        }
Exemplo n.º 12
0
        public void NetMQReceiver_WithNullRequestDispatcher_ThrowsArgumentNullException()
        {
            // Arrange
            var socket = new RouterSocket();

            // Act
            TestDelegate construct = () => new NetMQReceiver(socket, messageFactory, null);

            // Assert
            Assert.That(construct, Throws.ArgumentNullException);

            // Cleanup
            socket.Dispose();
        }
Exemplo n.º 13
0
 public override void Dispose()
 {
     try
     {
         _router.Dispose();
         _runtime.Dispose();
     }
     catch (Exception e)
     {
         _logger.LogError(e.ToString());
     }
     finally
     {
         base.Dispose();
     }
 }
Exemplo n.º 14
0
        public void Kill()
        {
            _poller.Stop();

            _heartbeat.Close();
            _heartbeat.Dispose();

            _frontend.Close();
            _frontend.Dispose();

            _backend.Close();
            _backend.Dispose();

            _workerQueue.Dispose();
            _workQueue.Dispose();
        }
Exemplo n.º 15
0
        public void DisposeThrowsIfSocketAlreadyDisposed()
        {
            var socket = new RouterSocket();

            var poller = new NetMQPoller {
                socket
            };

            // Dispose the socket.
            // It is incorrect to have a disposed socket in a poller.
            // Disposed sockets can throw into the poller's thread.
            socket.Dispose();

            // Dispose throws if a polled socket is disposed
            var ex = Assert.Throws <NetMQException>(() => poller.Dispose());

            Assert.AreEqual("Invalid state detected: NetMQPoller contains a disposed NetMQSocket. Sockets must be either removed before being disposed, or disposed after the poller is disposed.", ex.Message);
        }
Exemplo n.º 16
0
        public override Task Stop()
        {
            _cancel.Cancel();

            _poller.Stop();

            _heartbeat.Close();
            _heartbeat.Dispose();

            _frontend.Close();
            _frontend.Dispose();

            _backend.Close();
            _backend.Dispose();


            return(Task.CompletedTask);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Cleans up resources
        /// </summary>
        private void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    TerminateConnection();
                    if (!(socket is null))
                    {
                        socket.ReceiveReady -= OnRequestReceived;
                        socket.Dispose();
                        socket = null;
                    }
                }

                disposedValue = true;
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// Shut down the service and clean up resources.
        /// </summary>
        new public void Stop()
        {
            if (IsRunning)
            {
                try
                {
                    _routerSocket.Disconnect(_facadeAddress);
                    _routerSocket.Dispose();

                    base.Stop();
                }
                finally
                {
                    IsRunning = false;
                    NetMQConfig.Cleanup();
                }
            }
        }
Exemplo n.º 19
0
        public void Addresses_WhenDisposed_ThrowsInvalidOperationException()
        {
            // Arrange
            var socket   = new RouterSocket();
            var receiver = new NetMQReceiver(socket, messageFactory, requestDispatcher);
            var address  = TcpAddress.Wildcard(5555);

            receiver.Dispose();

            // Act
            void AddAddress() => receiver.AddAddress(address);

            // Assert
            Assert.That(AddAddress, Throws.TypeOf <InvalidOperationException>());

            // Cleanup
            socket.Dispose();
        }
Exemplo n.º 20
0
        public void Stop()
        {
            _cancel.Cancel();

            _poller.Stop();

            _heartbeat.Close();
            _heartbeat.Dispose();

            _publishStateUpdate.Close();
            _publishStateUpdate.Dispose();

            _subscribeToUpdates.Close();
            _subscribeToUpdates.Dispose();

            _stateRequest.Close();
            _stateRequest.Dispose();
        }
Exemplo n.º 21
0
        public void AddThrowsIfSocketAlreadyDisposed()
        {
            var poller = new NetMQPoller();

            var socket = new RouterSocket();

            // Dispose the socket.
            // It is incorrect to have a disposed socket in a poller.
            // Disposed sockets can throw into the poller's thread.
            socket.Dispose();

            // Adding a disposed socket throws
            var ex = Assert.Throws <ArgumentException>(() => poller.Add(socket));

            Assert.True(ex.Message.StartsWith("Must not be disposed."));
            Assert.AreEqual("socket", ex.ParamName);

            // Still dispose it. It throws after cleanup.
            Assert.Throws <NetMQException>(() => poller.Dispose());
        }
Exemplo n.º 22
0
        public async Task DisposeAsync()
        {
            _logger.Debug("Disposing...");
            if (_contextInitialized)
            {
                _removedPeers[AsPeer] = DateTime.UtcNow;
                await DistributeDeltaAsync(false);

                _router.Dispose();
                _deltas.Dispose();
                foreach (DealerSocket s in _dealers.Values)
                {
                    s.Dispose();
                }

                _dealers.Clear();

                _contextInitialized = false;
            }

            _logger.Debug("Disposed.");
        }
Exemplo n.º 23
0
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                _disposed = true; //prevent second call to Dispose
                if (disposing)
                {
                    if (null != _sessionCleanupTimer)
                    {
                        _sessionCleanupTimer.Enable = false;
                    }
                    if (null != _socketPoller)
                    {
                        _socketPoller.Dispose();
                    }
                    if (null != _sendQueue)
                    {
                        _sendQueue.Dispose();
                    }
                    if (null != _routerSocket)
                    {
                        _routerSocket.Dispose();
                    }

                    if (null != _hostPoller)
                    {
                        _hostPoller.Dispose();
                    }
                    if (null != _receivedQueue)
                    {
                        _receivedQueue.Dispose();
                    }
                    if (null != _sendFailureQueue)
                    {
                        _sendFailureQueue.Dispose();
                    }
                }
            }
        }
Exemplo n.º 24
0
 protected override void Cleanup()
 {
     m_frontend.Dispose();
     m_backend.Dispose();
 }
Exemplo n.º 25
0
 protected override void Cleanup()
 {
     m_frontend.Dispose();
     m_backend.Dispose();
     Console.WriteLine("Cleanup");
 }
Exemplo n.º 26
0
 public override void Dispose()
 {
     poller?.Dispose();
     dealerSocket?.Dispose();
     routerSocket?.Dispose();
 }
Exemplo n.º 27
0
 public void Dispose()
 {
     _input?.Dispose();
     _output?.Dispose();
 }
Exemplo n.º 28
0
 protected override void Cleanup()
 {
     m_serverSocket.Dispose();
 }