Beispiel #1
0
        public void Dispose()
        {
            var remainingWaitCount = maxWaitDurationInDispose.TotalMilliseconds / MinWaitDuration.TotalMilliseconds;

            while (_queue.QueueCurrentSize > 0 && remainingWaitCount > 0)
            {
                _waiter.Wait(MinWaitDuration);
                --remainingWaitCount;
            }

            _terminate = true;
            try
            {
                foreach (var worker in _workers)
                {
                    worker.Wait();
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }

            _workers.Clear();
        }
Beispiel #2
0
        public void Flush()
        {
            var remainingWaitCount = maxWaitDurationInFlush.TotalMilliseconds / MinWaitDuration.TotalMilliseconds;

            while (_queue.QueueCurrentSize > 0 && remainingWaitCount > 0)
            {
                _waiter.Wait(MinWaitDuration);
                --remainingWaitCount;
            }

            _requestFlush = true;
            _flushEvent.WaitOne(maxWaitDurationInFlush);
        }
        void Dequeue()
        {
            var waitDuration = MinWaitDuration;

            while (true)
            {
                if (_queue.TryDequeue(out var v))
                {
                    _handler.OnNewValue(v);
                    waitDuration = MinWaitDuration;
                }
                else
                {
                    if (_terminate)
                    {
                        return;
                    }

                    if (_handler.OnIdle())
                    {
                        _waiter.Wait(waitDuration);
                        waitDuration = waitDuration + waitDuration;
                        if (waitDuration > MaxWaitDuration)
                        {
                            waitDuration = MaxWaitDuration;
                        }
                    }
                }
            }
        }
Beispiel #4
0
        private void BlockingConnect()
        {
            while (!token.IsCancellationRequested)
            {
                try
                {
                    log.Debug("Trying to connect to broker");
                    connection = connectionFactory.CreateConnection();

                    log.Debug("Connection created");
                    connection.ConnectionShutdown += HandleConnectionShutdown;

                    aggregator.Notify(new ConnectionEstablished(this));
                    return;
                }
                catch (BrokerUnreachableException e) // looking at the client source it appears safe to catch this exception only
                {
                    log.Error("Cannot create connection, broker is unreachable", e);

                    aggregator.Notify(new ConnectionAttemptFailed());

                    if (waiter.Wait(token.WaitHandle, ConnectionAttemptInterval))
                    {
                        return;
                    }
                }
            }
        }
Beispiel #5
0
        public void Should_stop_trying_to_connect_if_disposed_of()
        {
            connectionFactory.When(f => f.CreateConnection()).Do(_ => { sut.Dispose(); throw BUE; });
            waiter.Wait(Arg.Any <WaitHandle>(), sut.ConnectionAttemptInterval).Returns(true);

            sut.Connect();

            connectionFactory.Received(1).CreateConnection();
        }
Beispiel #6
0
 private void WaitForKeypress()
 {
     if (Settings.WaitForKeypress)
     {
         _logWriter.WriteLine();
         _logWriter.WriteLine();
         _logWriter.WriteLine("Press any-key...");
         _waitAtEnd.Wait();
     }
 }
        public TestActorRef <TActor> Create <TActor>(IWaiter childWaiter, TestKitBase testKit, Props props, int expectedChildrenCount, IActorRef supervisor) where TActor : ActorBase
        {
            childWaiter.Start(testKit, expectedChildrenCount);
            TestActorRef <TActor> sut = supervisor != null
                ? testKit.ActorOfAsTestActorRef <TActor>(props, supervisor)
                : testKit.ActorOfAsTestActorRef <TActor>(props);

            childWaiter.Wait();
            return(sut);
        }
 public void TellMessage <TMessage>(IWaiter waiter, TestKitBase testKit, IActorRef recipient, TMessage message, int waitForCount, IActorRef sender = null)
 {
     waiter.Start(testKit, waitForCount);
     if (sender == null)
     {
         recipient.Tell(message);
     }
     else
     {
         recipient.Tell(message, sender);
     }
     waiter.Wait();
 }
        public Assembly AssemblyResolveHandler(object sender, ResolveEventArgs args)
        {
            if (Plugin == null)
            {
                RemoveDependencyResolver();
                return(null);
            }
            var assemblyDetails = args.Name.Split(", ".ToArray(), StringSplitOptions.RemoveEmptyEntries);
            var file            = assemblyDetails.First();
            var version         = assemblyDetails.FirstOrDefault(ad => ad.StartsWith("Version="))?
                                  .Split("=".ToArray(), StringSplitOptions.RemoveEmptyEntries)
                                  .Skip(1)?.First();
            var key = $"{file}_{version}";

            _Waiter.Wait(key);
            if (_AssemblyResolveCache.Cache.TryGetValue(key, out IAssembly cachedAssembly))
            {
                _Waiter.InProgress[key] = false;
                return(cachedAssembly.Instance);
            }
            var paths = GetPathsToSearch(Paths, args, key);

            if (paths == null || !paths.Any())
            {
                _Waiter.InProgress[key] = false;
                return(null);
            }
            foreach (var path in paths)
            {
                _AttemptedPaths[args.Name].Add(path);
                if (!Directory.Exists(path))
                {
                    Paths.Remove(path);
                    _Waiter.InProgress[key] = false;
                    continue;
                }
                var dll      = System.IO.Path.Combine(path, file + ".dll");
                var pdb      = System.IO.Path.Combine(path, file + ".pdb");
                var assembly = (string.IsNullOrWhiteSpace(version))
                    ? _AssemblyLoader.TryLoad(dll, pdb)
                    : _AssemblyLoader.TryLoad(dll, pdb, version);
                if (assembly != null)
                {
                    _Waiter.InProgress[key] = false;
                    _AssemblyResolveCache.Cache.TryAdd(key, assembly);
                    return(assembly.Instance);
                }
            }
            _Waiter.InProgress[key] = false;
            return(null);
        }
        public void Schedule(IEvent @event, Time time, Func <int, bool> maySchedule)
        {
            var scheduled = new ScheduledEvent(@event, time);

            Task.Run(async() =>
            {
                EventScheduled?.Invoke(this, scheduled);

                while (maySchedule(scheduled.TimesExecuted))
                {
                    await waiter.Wait(scheduled.TimeUntil.TotalMilliseconds());

                    @event.Execute();
                    scheduled.TimesExecuted++;
                }

                EventFinished?.Invoke(this, scheduled);
            });
        }
 private void FlashOpenDoorIndicator()
 {
     _mechanicalController.SetOpenDoorIndicatorOn();
     _waiter.Wait(TimeSpan.FromSeconds(1));
     _mechanicalController.SetOpenDoorIndicatorOff();
 }