Ejemplo n.º 1
0
 /// <summary>
 /// Default Constructor
 /// </summary>
 /// <param name="firstTask">Task to run before entering run loop.</param>
 /// <param name="parentThreadPoolExecutor"><see cref="ThreadPoolExecutor"/> that controls this worker</param>
 internal Worker(ThreadPoolExecutor parentThreadPoolExecutor, IRunnable firstTask)
 {
     FirstTask = firstTask;
     _parentThreadPoolExecutor = parentThreadPoolExecutor;
     Thread = parentThreadPoolExecutor.ThreadFactory.NewThread(this);
 }
Ejemplo n.º 2
0
 /// <summary> 
 /// Obtains and ignores the next task that the <paramref name="executor"/>
 /// would otherwise execute, if one is immediately available,
 /// and then retries execution of task <paramref name="runnable"/>,
 /// unless the <paramref name="executor"/> is shut down, in which
 /// case task <paramref name="runnable"/> is instead discarded.
 /// </summary>
 /// <param name="runnable">
 /// The <see cref="IRunnable"/> task requested to be executed.
 /// </param>
 /// <param name="executor">
 /// The <see cref="ThreadPoolExecutor"/> attempting to execute this
 /// task.
 /// </param>
 public virtual void RejectedExecution(IRunnable runnable, ThreadPoolExecutor executor)
 {
     if (executor.IsShutdown) return;
     IRunnable head;
     executor.Queue.Poll(out head);
     executor.Execute(runnable);
 }
Ejemplo n.º 3
0
 /// <summary> 
 /// Does nothing, which has the effect of discarding task
 /// <paramref name="runnable"/>.
 /// </summary>
 /// <param name="runnable">
 /// The <see cref="IRunnable"/> task requested to be executed.
 /// </param>
 /// <param name="executor">
 /// The <see cref="ThreadPoolExecutor"/> attempting to execute this
 /// task.
 /// </param>
 public virtual void RejectedExecution(IRunnable runnable, ThreadPoolExecutor executor)
 {
 }
Ejemplo n.º 4
0
 /// <summary> 
 /// Always throws <see cref="RejectedExecutionException"/>.
 /// </summary>
 /// <param name="runnable">
 /// The <see cref="IRunnable"/> task requested to be executed.
 /// </param>
 /// <param name="executor">
 /// The <see cref="ThreadPoolExecutor"/> attempting to execute this task.
 /// </param>
 /// <exception cref="RejectedExecutionException">
 /// Always thrown upon execution.
 /// </exception>
 public virtual void RejectedExecution(IRunnable runnable, ThreadPoolExecutor executor)
 {
     throw new RejectedExecutionException("IRunnable: " + runnable +
                                          " rejected from execution by ThreadPoolExecutor: " + executor);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Executes task <paramref name="runnable"/> in the caller's
 /// thread, unless <paramref name="executor"/> has been shut down,
 /// in which case the task is discarded.
 /// <param name="executor">the executor attempting to execute this task</param>
 /// <param name="runnable">the runnable task requested to be executed</param>
 /// </summary>
 public void RejectedExecution(IRunnable runnable, ThreadPoolExecutor executor)
 {
     if (executor.IsShutdown) return;
     runnable.Run();
 }
Ejemplo n.º 6
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());
        }