Example #1
0
        private static void PollOneFromQueue(IBlockingQueue <T> q, T expectedValue)
        {
            T result;

            Assert.IsTrue(q.Poll(Delays.Small, out result));
            Assert.That(result, Is.EqualTo(expectedValue));
        }
Example #2
0
        public void InitThreading(EPServicesContext services, EPRuntimeImpl runtime)
        {
            if (_isInboundThreading)
            {
                _inboundQueue      = MakeQueue(_config.ThreadPoolInboundCapacity, _config.ThreadPoolInboundBlocking);
                _inboundThreadPool = GetThreadPool(services.EngineURI, "Inbound", _inboundQueue, _config.ThreadPoolInboundNumThreads);
            }

            if (_isTimerThreading)
            {
                _timerQueue      = MakeQueue(_config.ThreadPoolTimerExecCapacity, _config.ThreadPoolTimerExecBlocking);
                _timerThreadPool = GetThreadPool(services.EngineURI, "TimerExec", _timerQueue, _config.ThreadPoolTimerExecNumThreads);
            }

            if (_isRouteThreading)
            {
                _routeQueue      = MakeQueue(_config.ThreadPoolRouteExecCapacity, _config.ThreadPoolRouteExecBlocking);
                _routeThreadPool = GetThreadPool(services.EngineURI, "RouteExec", _routeQueue, _config.ThreadPoolRouteExecNumThreads);
            }

            if (_isOutboundThreading)
            {
                _outboundQueue      = MakeQueue(_config.ThreadPoolOutboundCapacity, _config.ThreadPoolOutboundBlocking);
                _outboundThreadPool = GetThreadPool(services.EngineURI, "Outbound", _outboundQueue, _config.ThreadPoolOutboundNumThreads);
            }
        }
Example #3
0
 [SetUp] public void SetUp()
 {
     _queue               = MockRepository.GenerateStub <IBlockingQueue <IRunnable> >();
     _runnable            = MockRepository.GenerateMock <IRunnable>();
     _discardOldestPolicy = new ThreadPoolExecutor.DiscardOldestPolicy();
     _threadPoolExecutor  = Mockery.GeneratePartialMock <ThreadPoolExecutor>(1, 1, TimeSpan.FromSeconds(1), _queue);
 }
        public static void ConsumeAll(int produced, IBlockingQueue<object> queue, int volume)
        {
            int[] consumed = { 0 };
            while (consumed[0] < volume)
            {
                try
                {
                    Thread.Sleep(10);
                    var item = queue.Dequeue();
                    Assert.IsNotNull(item);
                    Interlocked.Increment(ref consumed[0]);
                }
                catch (Exception ex)
                {
                    Assert.Fail(ex.Message);
                }
            }

            while (consumed[0] < produced)
            {
                Assert.GreaterOrEqual(produced, consumed[0], "More messages reported consumed than produced");
            }

            Assert.AreEqual(produced, consumed[0], "Consumers reported complete before a count mismatch");
        }
        /// <summary>
        /// Create a channel with the specified queue capacity.
        /// </summary>
        public QueueChannel(int capacity)
        {
            AssertUtils.IsTrue(capacity > 0, "The capacity must be a positive integer. " +
                                             "For a zero-capacity alternative, consider using a 'RendezvousChannel'.");

            _queue = new LinkedBlockingQueue<IMessage>(capacity);
        }
Example #6
0
        public static IExecutor CreateThreadPoolTaskExecutor(int coreSize, int maxSize, int queueCapacity, string threadPrefix)
        {
            IBlockingQueue <IRunnable> queue = queueCapacity > 0 ? new LinkedBlockingQueue <IRunnable>(queueCapacity) : new LinkedBlockingQueue <IRunnable>();
            var executor = new ThreadPoolExecutor(coreSize, maxSize, TimeSpan.Zero, queue);

            if (StringUtils.HasText(threadPrefix))
            {
                // TODO new CustomizableThreadFactory(threadPrefix);
                //executor.ThreadFactory = new CustomizableThreadFactory(threadPrefix);
            }

            executor.RejectedExecutionHandler = new ThreadPoolExecutor.CallerRunsPolicy();
            // TODO executor.AfterPropertiesSet();
            return(executor);


            /*
             *
             * ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
             * executor.CorePoolSize = coreSize;
             * executor.MaxPoolSize = maxSize;
             * executor.QueueCapacity = queueCapacity;
             * if (StringUtils.HasText(threadPrefix))
             * {
             *  executor.ThreadFactory = new CustomizableThreadFactory(threadPrefix);
             * }
             * executor.RejectedExecutionHandler = new CallerRunsPolicy();
             * executor.AfterPropertiesSet();
             * return executor;
             */
        }
        /// <summary>Constructor.</summary>
        /// <param name="numThreads">
        /// -- if less than or equal to 0, then automatically determine the number
        /// of threads. Otherwise, the size of the underlying threadpool.
        /// </param>
        /// <param name="processor"/>
        /// <param name="orderResults">
        /// -- If true, return results in the order submitted. Otherwise, return results
        /// as they become available.
        /// </param>
        public MulticoreWrapper(int numThreads, IThreadsafeProcessor <I, O> processor, bool orderResults)
        {
            // Which id was the last id returned.  Only meaningful in the case
            // of a queue where output order matters.
            //  private final ExecutorCompletionService<Integer> queue;
            nThreads          = numThreads <= 0 ? Runtime.GetRuntime().AvailableProcessors() : numThreads;
            this.orderResults = orderResults;
            outputQueue       = new ConcurrentHashMap <int, O>(2 * nThreads);
            threadPool        = BuildThreadPool(nThreads);
            //    queue = new ExecutorCompletionService<Integer>(threadPool);
            idleProcessors = new ArrayBlockingQueue <int>(nThreads, false);
            callback       = null;
            // Sanity check: Fixed thread pool so prevent timeouts.
            // Default should be false
            threadPool.AllowCoreThreadTimeOut(false);
            threadPool.PrestartAllCoreThreads();
            // Setup the processors, one per thread
            IList <IThreadsafeProcessor <I, O> > procList = new List <IThreadsafeProcessor <I, O> >(nThreads);

            procList.Add(processor);
            idleProcessors.Add(0);
            for (int i = 1; i < nThreads; ++i)
            {
                procList.Add(processor.NewInstance());
                idleProcessors.Add(i);
            }
            processorList = Java.Util.Collections.UnmodifiableList(procList);
        }
 public void SetUp()
 {
     _queue = MockRepository.GenerateStub<IBlockingQueue<IRunnable>>();
     _runnable = MockRepository.GenerateMock<IRunnable>();
     _discardOldestPolicy = new ThreadPoolExecutor.DiscardOldestPolicy();
     _threadPoolExecutor = Mockery.GeneratePartialMock<ThreadPoolExecutor>(1, 1, TimeSpan.FromSeconds(1), _queue);
 }
 [SetUp] public void SetUp()
 {
     _queue              = MockRepository.GenerateStub <IBlockingQueue <IRunnable> >();
     _runnable           = MockRepository.GenerateMock <IRunnable>();
     _callerRunsPolicy   = new ThreadPoolExecutor.CallerRunsPolicy();
     _threadPoolExecutor = new ThreadPoolExecutor(1, 1, TimeSpan.FromSeconds(1), _queue);
 }
Example #10
0
        /// <summary>
        /// Create a channel with the specified queue capacity.
        /// </summary>
        public QueueChannel(int capacity)
        {
            AssertUtils.IsTrue(capacity > 0, "The capacity must be a positive integer. " +
                               "For a zero-capacity alternative, consider using a 'RendezvousChannel'.");

            _queue = new LinkedBlockingQueue <IMessage>(capacity);
        }
 public void SetUp()
 {
     _queue = MockRepository.GenerateStub<IBlockingQueue<IRunnable>>();
     _runnable = MockRepository.GenerateMock<IRunnable>();
     _callerRunsPolicy = new ThreadPoolExecutor.CallerRunsPolicy();
     _threadPoolExecutor = new ThreadPoolExecutor(1, 1, TimeSpan.FromSeconds(1), _queue);
 }
Example #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HystrixThreadPoolDefault"/> class.
        /// </summary>
        /// <param name="threadPoolKey">The key of this thread pool.</param>
        /// <param name="setter">The default properties of this thread pool.</param>
        public HystrixThreadPoolDefault(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolPropertiesSetter setter)
        {
            this.properties = HystrixPropertiesFactory.GetThreadPoolProperties(threadPoolKey, setter);
            this.queue      = HystrixPlugins.Instance.ConcurrencyStrategy.GetBlockingQueue(this.properties.MaxQueueSize.Get());
            this.threadPool = HystrixPlugins.Instance.ConcurrencyStrategy.GetThreadPool(threadPoolKey, this.properties.CoreSize, this.properties.CoreSize, this.properties.KeepAliveTime, this.queue);
            this.metrics    = HystrixThreadPoolMetrics.GetInstance(threadPoolKey, this.threadPool, this.properties);

            HystrixMetricsPublisherFactory.CreateOrRetrievePublisherForThreadPool(threadPoolKey, this.metrics, this.properties);
        }
 public WriteRunnable(
     RegressionEnvironment env,
     int numEvents,
     IBlockingQueue<string> queueCreated)
 {
     this.env = env;
     this.numEvents = numEvents;
     this.queueCreated = queueCreated;
 }
 public InsertRunnable(
     RegressionEnvironment env,
     RegressionPath path,
     int numInserted,
     IBlockingQueue<int> stageOutput) : base(env, path, "Insert")
 {
     this.numInserted = numInserted;
     this.stageOutput = stageOutput;
 }
 public DeleteRunnable(
     RegressionEnvironment env,
     RegressionPath path,
     IBlockingQueue<int> stageInput,
     IBlockingQueue<int> stageOutput) : base(env, path, "Delete")
 {
     this.stageInput = stageInput;
     this.stageOutput = stageOutput;
 }
Example #16
0
 public ProducerService(
     IApplicationLifetime lifetime,
     IBlockingQueue <IEnumerable <byte> > queue,
     IConsoleHelper console)
     : base(lifetime)
 {
     _queue   = queue;
     _console = console;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="HystrixThreadPoolDefault"/> class.
        /// </summary>
        /// <param name="threadPoolKey">The key of this thread pool.</param>
        /// <param name="setter">The default properties of this thread pool.</param>
        public HystrixThreadPoolDefault(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolPropertiesSetter setter)
        {
            this.properties = HystrixPropertiesFactory.GetThreadPoolProperties(threadPoolKey, setter);
            this.queue = HystrixPlugins.Instance.ConcurrencyStrategy.GetBlockingQueue(this.properties.MaxQueueSize.Get());
            this.threadPool = HystrixPlugins.Instance.ConcurrencyStrategy.GetThreadPool(threadPoolKey, this.properties.CoreSize, this.properties.CoreSize, this.properties.KeepAliveTime, this.queue);
            this.metrics = HystrixThreadPoolMetrics.GetInstance(threadPoolKey, this.threadPool, this.properties);

            HystrixMetricsPublisherFactory.CreateOrRetrievePublisherForThreadPool(threadPoolKey, this.metrics, this.properties);
        }
Example #18
0
        public static void Enqueue <T>([NotNull] this IBlockingQueue <T> queue, [NotNull] T value)
        {
            if (queue == null)
            {
                throw new ArgumentNullException(nameof(queue));
            }

            queue.TryEnqueue(value, Constants.InfiniteTimeout);
        }
Example #19
0
 public BeMobileTrajectService(ILogger <BeMobileTrajectService> logger, IBlockingQueue <GenericQueueTask <TrajectTaskModel> > queue, IThreadPool pool)
 {
     _logger = logger;
     _queue  = queue;
     _pool   = pool;
     if (_pool == null)
     {
         _logger.LogWarning("Threadpool service not defined, skipping restrictions");
     }
 }
 public static int ProduceAll(IBlockingQueue<object> queue, out int[] produced, int volume)
 {
     produced = new[] { 0 };
     PublishToQueue(queue, volume, produced);
     while (produced[0] < volume)
     {
         Assert.LessOrEqual(produced[0], volume, String.Format("More messages reported produced than requested: produced {0}, volume {1}", produced[0], volume));
     }
     Assert.AreEqual(produced[0], volume, String.Format("More messages produced than requested: produced {0}", produced[0]));
     return volume;
 }
Example #21
0
        private static void StopPool(IExecutorService executorService, IBlockingQueue <Runnable> queue, String name)
        {
            if (Log.IsInfoEnabled)
            {
                Log.Info("Shutting down pool " + name);
            }

            queue.Clear();
            executorService.Shutdown();
            executorService.AwaitTermination(new TimeSpan(0, 0, 10));
        }
Example #22
0
 private static void StartServices_Helper(IBlockingQueue <ServiceBE> services)
 {
     foreach (ServiceBE service in services)
     {
         try {
             StartService(service, false, false);
         } catch {
             //Services started on deki startup do not get disabled if they fail to start
         }
     }
 }
Example #23
0
        public ResultExecutionThread(IBlockingQueue <ResultExecutionTask> taskQueue)
        {
            _taskQueue = taskQueue;
            _worker    = new Thread(Run)
            {
                Name         = "Result Worker Thread",
                IsBackground = true
            };
#if !SILVERLIGHT
            _worker.SetApartmentState(ApartmentState.STA);
#endif
        }
Example #24
0
 protected IronConsole(IronRuntime runtime, params string[] supportedExtensions)
 {
     _runtime = runtime;
     _queue = new BlockingQueue<IronConsoleTask>();
     _queueWorker = new Thread(ProcessTaskQueue)
                    {
                        Name = string.Format("IronConsole Worker for {0}",
                            string.Join(", ", supportedExtensions)),
                        IsBackground = true
                    };
     _queueWorker.Start();
 }
Example #25
0
        [Test] public void AbortPolicyThrowsExceptionUponHandling()
        {
            IBlockingQueue <IRunnable> queue = MockRepository.GenerateStub <IBlockingQueue <IRunnable> >();

            var executor = Mockery.GeneratePartialMock <ThreadPoolExecutor>(1, 1, TimeSpan.FromSeconds(1), queue);
            var runnable = MockRepository.GenerateStub <IRunnable>();

            ThreadPoolExecutor.AbortPolicy abortPolicy = new ThreadPoolExecutor.AbortPolicy();
            Assert.Throws <RejectedExecutionException>(
                () => abortPolicy.RejectedExecution(runnable, executor));
            executor.AssertWasNotCalled(e => e.Execute(Arg <IRunnable> .Is.Anything));
        }
Example #26
0
 protected IronConsole(IronRuntime runtime, params string[] supportedExtensions)
 {
     _runtime     = runtime;
     _queue       = new BlockingQueue <IronConsoleTask>();
     _queueWorker = new Thread(ProcessTaskQueue)
     {
         Name = string.Format("IronConsole Worker for {0}",
                              string.Join(", ", supportedExtensions)),
         IsBackground = true
     };
     _queueWorker.Start();
 }
        public ResultExecutionThread(IBlockingQueue<ResultExecutionTask> taskQueue)
        {
            _taskQueue = taskQueue;
            _worker = new Thread(Run)
                      {
                          Name = "Result Worker Thread",
                          IsBackground = true
                      };
#if !SILVERLIGHT
            _worker.SetApartmentState(ApartmentState.STA);
#endif
        }
Example #28
0
        /// <summary>
        /// Initializes a new instance of the <see cref="QueueExecutor"/> class.
        /// </summary>
        /// <param name="numThreads">The num threads.</param>
        public QueueExecutor(int numThreads)
        {
            _eventQueue = new ImperfectBlockingQueue <WaitCallback>();

            _isHandlingEvents   = true;
            _eventHandleThreads = new Thread[numThreads];
            for (var ii = 0; ii < _eventHandleThreads.Length; ii++)
            {
                _eventHandleThreads[ii]              = new Thread(ProcessEventQueue);
                _eventHandleThreads[ii].Name         = "EsperEventHandler-" + ii;
                _eventHandleThreads[ii].IsBackground = true;
                _eventHandleThreads[ii].Start();
            }
        }
 /// <summary>
 /// Creates an <see cref="ExecutorCompletionService{T}"/> using the supplied
 /// executor for base task execution and the supplied queue as its
 /// completion queue.
 /// </summary>
 /// <param name="executor">the executor to use</param>
 /// <param name="completionQueue">the queue to use as the completion queue
 /// normally one dedicated for use by this service
 /// </param>
 /// <exception cref="System.ArgumentNullException">
 /// if the executor is null
 /// </exception>
 public ExecutorCompletionService(IExecutor executor, IBlockingQueue <IFuture <T> > completionQueue)
 {
     if (executor == null)
     {
         throw new ArgumentNullException("executor", "Executor cannot be null.");
     }
     if (completionQueue == null)
     {
         throw new ArgumentNullException("completionQueue", "Completion Queue cannot be null.");
     }
     _executor        = executor;
     _aes             = executor as AbstractExecutorService;
     _completionQueue = completionQueue;
 }
Example #30
0
        private static IExecutorService GetThreadPool(String engineURI, String name, IBlockingQueue <Runnable> queue, int numThreads)
        {
            if (Log.IsInfoEnabled)
            {
                Log.Info("Starting pool " + name + " with " + numThreads + " threads");
            }

            if (engineURI == null)
            {
                engineURI = "default";
            }

            return(new DedicatedExecutorService(name, numThreads, queue));
        }
 public void AfterPropertiesSet()
 {
     lock (_lifecycleMonitor) {
         if (!_initialized)
         {
             _trackedCorrelationIds = new ArrayBlockingQueue <object>(_trackedCorrelationIdCapacity);
             if (_autoStartup)
             {
                 Start();
             }
             _initialized = true;
         }
     }
 }
 public static void PublishToQueue(IBlockingQueue<object> queue, int volume, int[] produced)
 {
     while (produced[0] < volume)
     {
         try
         {
             queue.Enqueue(new object());
             Interlocked.Increment(ref produced[0]);
         }
         catch (Exception ex)
         {
             Assert.Fail(ex.Message);
         }
     }
 }
        /// <summary>Creates a new instance of <see cref="SingleThreadEventExecutor"/>.</summary>
        /// <param name="parent">the <see cref="IEventExecutorGroup"/> which is the parent of this instance and belongs to it.</param>
        /// <param name="threadFactory">the <see cref="IThreadFactory"/> which will be used for the used <see cref="Thread"/>.</param>
        /// <param name="addTaskWakesUp"><c>true</c> if and only if invocation of <see cref="AddTask(IRunnable)"/> will wake up the executor thread.</param>
        /// <param name="maxPendingTasks">the maximum number of pending tasks before new tasks will be rejected.</param>
        /// <param name="rejectedHandler">the <see cref="IRejectedExecutionHandler"/> to use.</param>
        protected SingleThreadEventExecutor(IEventExecutorGroup parent, IThreadFactory threadFactory, bool addTaskWakesUp,
                                            int maxPendingTasks, IRejectedExecutionHandler rejectedHandler)
            : this(parent, addTaskWakesUp, rejectedHandler)
        {
            if (threadFactory is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.threadFactory);
            }

            _maxPendingTasks   = Math.Max(16, maxPendingTasks);
            _taskQueue         = NewTaskQueue(_maxPendingTasks);
            _blockingTaskQueue = _taskQueue as IBlockingQueue <IRunnable>;

            _thread = NewThread(threadFactory);
        }
Example #34
0
        /// <summary>
        /// Creates a PeerGroup with the given parameters. The connectionDelayMillis parameter controls how long the
        /// PeerGroup will wait between attempts to connect to nodes or read from any added peer discovery sources.
        /// </summary>
        public PeerGroup(IBlockStore blockStore, NetworkParameters @params, BlockChain chain, int connectionDelayMillis)
        {
            _blockStore            = blockStore;
            _params                = @params;
            _chain                 = chain;
            _connectionDelayMillis = connectionDelayMillis;

            _inactives       = new LinkedBlockingQueue <PeerAddress>();
            _peers           = new SynchronizedHashSet <Peer>();
            _peerDiscoverers = new SynchronizedHashSet <IPeerDiscovery>();
            _peerPool        = new ThreadPoolExecutor(_coreThreads, _defaultConnections,
                                                      TimeSpan.FromSeconds(_threadKeepAliveSeconds),
                                                      new LinkedBlockingQueue <IRunnable>(1),
                                                      new PeerGroupThreadFactory());
        }
        /// <summary>
        /// Creates the BlockingQueue and the ThreadPoolExecutor.
        /// </summary>
        public void Initialize()
        {
            if (logger.IsInfoEnabled)
            {
                logger.Info("Initializing ThreadPoolExecutor" + (_objectName != null ? " '" + _objectName + "'" : ""));
            }
            if (!_threadNamePrefixSet && _objectName != null)
            {
                ThreadNamePrefix = _objectName + "-";
            }
            IBlockingQueue <IRunnable> queue = CreateQueue(_queueCapacity);

            _threadPoolExecutor = new ThreadPoolExecutor(_corePoolSize, _maxPoolSize, _keepAliveTime, queue, _threadFactory, _rejectedExecutionHandler);
            if (_allowCoreThreadTimeOut)
            {
                _threadPoolExecutor.AllowsCoreThreadsToTimeOut = true;
            }
        }
Example #36
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DedicatedExecutorService"/> class.
        /// </summary>
        /// <param name="label">The label.</param>
        /// <param name="numThreads">The num threads.</param>
        /// <param name="taskQueue">The task queue.</param>
        public DedicatedExecutorService(string label, int numThreads, IBlockingQueue <Runnable> taskQueue)
        {
            _id           = Guid.NewGuid();
            _numThreads   = numThreads;
            _threads      = new Thread[numThreads];
            _tasksRunning = 0L;
            _taskQueue    = taskQueue;
            _liveMode     = LiveMode.RUN;
            _numExecuted  = 0L;

            for (int ii = 0; ii < _numThreads; ii++)
            {
                _threads[ii]              = new Thread(HandleTasksInQueue);
                _threads[ii].Name         = "DE:" + label + ":" + _id + ":" + ii;
                _threads[ii].IsBackground = true;
                _threads[ii].Start();
            }
        }
        /// <summary>Creates a new instance of <see cref="SingleThreadEventExecutor"/>.</summary>
        /// <param name="parent">the <see cref="IEventExecutorGroup"/> which is the parent of this instance and belongs to it.</param>
        /// <param name="threadFactory">the <see cref="IThreadFactory"/> which will be used for the used <see cref="Thread"/>.</param>
        /// <param name="addTaskWakesUp"><c>true</c> if and only if invocation of <see cref="AddTask(IRunnable)"/> will wake up the executor thread.</param>
        /// <param name="taskQueue">The pending task queue.</param>
        /// <param name="rejectedHandler">the <see cref="IRejectedExecutionHandler"/> to use.</param>
        protected SingleThreadEventExecutor(IEventExecutorGroup parent, IThreadFactory threadFactory, bool addTaskWakesUp,
                                            IQueue <IRunnable> taskQueue, IRejectedExecutionHandler rejectedHandler)
            : this(parent, addTaskWakesUp, rejectedHandler)
        {
            if (threadFactory is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.threadFactory);
            }
            if (taskQueue is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.taskQueue);
            }

            _maxPendingTasks   = DefaultMaxPendingExecutorTasks;
            _taskQueue         = taskQueue;
            _blockingTaskQueue = taskQueue as IBlockingQueue <IRunnable>;

            _thread = NewThread(threadFactory);
        }
Example #38
0
        public void QueueRetursWorkQueuContainsQueuedTasks()
        {
            IBlockingQueue <IRunnable> q = new ArrayBlockingQueue <IRunnable>(10);
            var es = new ThreadPoolExecutor(1, 1, Delays.Long, q);

            ExecutorService = es;
            FutureTask <bool>[] tasks = new FutureTask <bool> [_size];
            for (int i = 0; i < _size; i++)
            {
                tasks[i] = new FutureTask <bool>(_mediumInterruptableAction, true);
                es.Execute(tasks[i]);
            }
            Thread.Sleep(Delays.Short);
            IBlockingQueue <IRunnable> wq = es.Queue;

            Assert.AreEqual(q, wq);
            Assert.IsFalse(wq.Contains(tasks[0]));
            Assert.IsTrue(wq.Contains(tasks[_size - 1]));
            for (int i = 1; i < _size; ++i)
            {
                tasks[i].Cancel(true);
            }
        }
Example #39
0
        public void Execute(ILogger logger, IBlockingQueue <BeMobileTaskModel, BEMobileSegmentTaskModel> queue)
        {
            if (BlobName == null && BlobKey == null)
            {
                logger.LogWarning("Execute called upon empty task");
                return;
            }
            logger.LogInformation("Starting BE-Mobile import task");
            BlobManager                     manager     = new BlobManager(BlobName, BlobKey);
            List <IListBlobItem>            items       = manager.ListAllBlobsAsync(BlobContainer, $"BE-Mobile/{Month}/Reistijden/{Traject}/").Result;
            CrudManager <TraveltimeSegment> crudManager = new CrudManager <TraveltimeSegment>
            {
                DatabaseKey    = CosmosKey,
                DatabaseUri    = CosmosUrl,
                DatabaseName   = DatabaseName,
                CollectionName = CollectionName,
            };

            crudManager.Init();

            List <TraveltimeSegment> segments = new List <TraveltimeSegment>();

            foreach (IListBlobItem item in items)
            {
                segments.AddRange(CSVReader.GetSegmentsFromCSVString(manager.DownloadBlob(item.Container.Name, BlobManager.getBlobIdFromURI(item.Uri)).Result));
            }

            foreach (TraveltimeSegment segment in segments)
            {
                queue.DocumentQueue.Add(new BEMobileSegmentTaskModel
                {
                    CreationMethod  = crudManager.Create,
                    SegmentToCreate = segment
                });
            }
            queue.DocumentsFinished += 1;
        }
 /// <summary> 
 /// Creates a new <see cref="ThreadPoolExecutor"/> with the given initial
 /// parameters and default thread factory and rejected execution handler.
 /// </summary>
 /// <remarks>>
 /// It may be more convenient to use one of the <see cref="Executors"/> factory
 /// methods instead of this general purpose constructor.
 /// </remarks>
 /// <param name="corePoolSize">the number of threads to keep in the pool, even if they are idle.</param>
 /// <param name="maximumPoolSize">the maximum number of threads to allow in the pool.</param>
 /// <param name="keepAliveTime">
 /// When the number of threads is greater than
 /// <see cref="CorePoolSize"/>, this is the maximum time that excess idle threads
 /// will wait for new tasks before terminating.
 /// </param>
 /// <param name="workQueue">
 /// The queue to use for holding tasks before they
 /// are executed. This queue will hold only the <see cref="IRunnable"/>
 /// tasks submitted by the <see cref="AbstractExecutorService.Execute(IRunnable)"/> method.
 /// </param>
 /// <exception cref="System.ArgumentOutOfRangeException">
 /// If <paramref name="corePoolSize"/> or <paramref name="keepAliveTime"/> is less than zero, or if <paramref name="maximumPoolSize"/>
 /// is less than or equal to zero, or if <paramref name="corePoolSize"/> is greater than <paramref name="maximumPoolSize"/>
 /// </exception>
 /// <exception cref="System.ArgumentNullException">if <paramref name="workQueue"/> is null</exception>
 /// <throws>  NullPointerException if <tt>workQueue</tt> is null </throws>
 public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, TimeSpan keepAliveTime, IBlockingQueue<IRunnable> workQueue)
     : this(
         corePoolSize, maximumPoolSize, keepAliveTime, workQueue, Executors.NewDefaultThreadFactory(),
         _defaultRejectedExecutionHandler)
 {
 }
 /// <summary> Creates a new <see cref="ThreadPoolExecutor"/> with the given initial
 /// parameters.
 /// 
 /// </summary>
 /// <param name="corePoolSize">the number of threads to keep in the pool, even if they are idle.</param>
 /// <param name="maximumPoolSize">the maximum number of threads to allow in the pool.</param>
 /// <param name="keepAliveTime">
 /// When the number of threads is greater than
 /// <see cref="CorePoolSize"/>, this is the maximum time that excess idle threads
 /// will wait for new tasks before terminating.
 /// </param>
 /// <param name="workQueue">
 /// The queue to use for holding tasks before they
 /// are executed. This queue will hold only the <see cref="IRunnable"/>
 /// tasks submitted by the <see cref="AbstractExecutorService.Execute(IRunnable)"/> method.
 /// </param>
 /// <param name="threadFactory">
 /// <see cref="IThreadFactory"/> to use for new thread creation.
 /// </param>
 /// <param name="handler">
 /// The <see cref="IRejectedExecutionHandler"/> to use when execution is blocked
 /// because the thread bounds and queue capacities are reached.
 /// </param>
 /// <exception cref="System.ArgumentOutOfRangeException">
 /// If <paramref name="corePoolSize"/> or <paramref name="keepAliveTime"/> is less than zero, or if <paramref name="maximumPoolSize"/>
 /// is less than or equal to zero, or if <paramref name="corePoolSize"/> is greater than <paramref name="maximumPoolSize"/>
 /// </exception>
 /// <exception cref="System.ArgumentNullException">if <paramref name="workQueue"/>, <paramref name="handler"/>, or <paramref name="threadFactory"/> is null</exception>
 public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, TimeSpan keepAliveTime, IBlockingQueue<IRunnable> workQueue,
                           IThreadFactory threadFactory, IRejectedExecutionHandler handler)
 {
     if (corePoolSize < 0)
     {
         throw new ArgumentOutOfRangeException("corePoolSize", corePoolSize,
                                               "core pool size cannot be less than zero.");
     }
     if (maximumPoolSize <= 0)
     {
         throw new ArgumentOutOfRangeException("maximumPoolSize", maximumPoolSize,
                                               "maximum pool size must be greater than zero");
     }
     if (maximumPoolSize < corePoolSize)
     {
         throw new ArgumentException("maximum pool size, " + maximumPoolSize +
                                     " cannot be less than core pool size, " + corePoolSize + ".", "maximumPoolSize");
     }
     if (keepAliveTime.Ticks < 0)
     {
         throw new ArgumentOutOfRangeException("keepAliveTime", keepAliveTime,
                                               "keep alive time must be greater than or equal to zero.");
     }
     if (workQueue == null)
     {
         throw new ArgumentNullException("workQueue");
     }
     if (threadFactory == null)
     {
         throw new ArgumentNullException("threadFactory");
     }
     if (handler == null)
     {
         throw new ArgumentNullException("handler");
     }
     _corePoolSize = corePoolSize;
     _maximumPoolSize = maximumPoolSize;
     _workQueue = workQueue;
     KeepAliveTime = keepAliveTime;
     _threadFactory = threadFactory;
     _rejectedExecutionHandler = handler;
     _termination = _mainLock.NewCondition();
 }
        /// <summary>
        /// Creates a PeerGroup with the given parameters. The connectionDelayMillis parameter controls how long the
        /// PeerGroup will wait between attempts to connect to nodes or read from any added peer discovery sources.
        /// </summary>
        public PeerGroup(IBlockStore blockStore, NetworkParameters @params, BlockChain chain, int connectionDelayMillis)
        {
            _blockStore = blockStore;
            _params = @params;
            _chain = chain;
            _connectionDelayMillis = connectionDelayMillis;

            _inactives = new LinkedBlockingQueue<PeerAddress>();
            _peers = new SynchronizedHashSet<Peer>();
            _peerDiscoverers = new SynchronizedHashSet<IPeerDiscovery>();
            _peerPool = new ThreadPoolExecutor(_coreThreads, _defaultConnections,
                                               TimeSpan.FromSeconds(_threadKeepAliveSeconds),
                                               new LinkedBlockingQueue<IRunnable>(1),
                                               new PeerGroupThreadFactory());
        }
 ResultSynchronizationContext()
 {
     _queue = new BlockingQueue<ResultExecutionTask>();
     _worker = new ResultExecutionThread(_queue);
     _worker.Start();
 }
Example #44
0
 private static void StartServices_Helper(IBlockingQueue<ServiceBE> services) {
     foreach(ServiceBE service in services) {
         try {
             StartService(service, false, false);
         } catch {
             //Services started on deki startup do not get disabled if they fail to start
         }
     }
 }
 /// <summary>
 /// Create a channel with the specified queue.
 /// </summary>
 public QueueChannel(IBlockingQueue<IMessage> queue)
 {
     AssertUtils.ArgumentNotNull(queue, "queue", "must not be null");
     _queue = queue;
 }