private void StopProcessing()
        {
            _stopped = true;

            if (_publisher != null)
            {
                try
                {
                    _publisher.Close();
                }
                catch
                {
                    // ignore
                }
                finally
                {
                    _publisher = null;
                }
            }

            if (_cancellableMessageProcessing != null)
            {
                try
                {
                    _cancellableMessageProcessing.Cancel();
                }
                catch
                {
                    // ignore
                }
                finally
                {
                    _cancellableMessageProcessing = null;
                }
            }

            if (_cancellablePublishing != null)
            {
                try
                {
                    _cancellablePublishing.Cancel();
                }
                catch
                {
                    // ignore
                }
                finally
                {
                    _cancellablePublishing = null;
                }
            }
        }
 public DirectoryClientActor(
     IServiceDiscoveryInterest interest,
     Group directoryPublisherGroup,
     int maxMessageSize,
     long processingInterval,
     int processingTimeout)
 {
     _interest   = interest;
     _buffer     = new MemoryStream(maxMessageSize);
     _subscriber = new MulticastSubscriber(
         DirectoryClientFactory.ClientName,
         directoryPublisherGroup,
         maxMessageSize,
         processingTimeout,
         Logger);
     _subscriber.OpenFor(SelfAs <IChannelReaderConsumer>());
     _cancellable = Stage.Scheduler.Schedule(
         SelfAs <IScheduled <object?> >(), null, TimeSpan.FromMilliseconds(1000L), TimeSpan.FromMilliseconds(processingInterval));
 }
        private void StartProcessing()
        {
            _stopped = false;
            if (_publisher == null)
            {
                try
                {
                    _publisher = new MulticastPublisherReader(
                        "vlingo-directory-service",
                        _network.PublisherGroup,
                        _network.IncomingPort,
                        _maxMessageSize,
                        SelfAs <IChannelReaderConsumer>(),
                        Logger);
                }
                catch (Exception e)
                {
                    var message = $"DIRECTORY: Failed to create multicast publisher/reader because: {e.Message}";
                    Logger.Error(message, e);
                    throw new InvalidOperationException(message, e);
                }
            }

            if (_cancellableMessageProcessing == null)
            {
                _cancellableMessageProcessing = Stage.Scheduler.Schedule(
                    SelfAs <IScheduled <IntervalType> >(),
                    IntervalType.Processing,
                    TimeSpan.Zero,
                    TimeSpan.FromMilliseconds(_timing.ProcessingInterval));
            }

            if (_cancellablePublishing == null)
            {
                _cancellablePublishing = Stage.Scheduler.Schedule(
                    SelfAs <IScheduled <IntervalType> >(),
                    IntervalType.Publishing,
                    TimeSpan.Zero,
                    TimeSpan.FromMilliseconds(_timing.ProcessingInterval));
            }
        }