Beispiel #1
0
        /// <summary>
        /// Submits the specified callable to the thread pool.
        /// </summary>
        /// <param name="callable">The callable.</param>
        /// <returns></returns>
        public IFuture <T> Submit <T>(Func <T> callable)
        {
            if (_isShutdown)
            {
                throw new IllegalStateException("ExecutorService is shutdown");
            }

            Interlocked.Increment(ref _numSubmitted);

            var future = new FutureImpl <T> {
                Callable = callable
            };

            lock (_futuresPending) {
                using (new Tracer(Log, "Submit(lock)")) {
                    _futuresPending.Add(future);

                    if (Log.IsInfoEnabled)
                    {
                        Log.Info(
                            ".Submit - Instance {0} queued user work item: {1} pending",
                            _id,
                            _futuresPending.Count);
                    }
                }
            }

            Task task = _taskFactory.StartNew(() => DispatchFuture(future), TaskCreationOptions.None);

            Log.Info(".Submit - Queued task {0}", task);

            return(future);
        }
Beispiel #2
0
        /// <summary>
        /// Submits the specified runnable to the thread pool.
        /// </summary>
        /// <param name="runnable">The runnable.</param>
        /// <returns></returns>
        public IFuture <object> Submit(Action runnable)
        {
            var future = new FutureImpl <object>();

            Log.Debug("Submit: Instance {0} - enqueuing action", _id);
            _taskQueue.Push(runnable.Invoke);
            return(future);
        }
Beispiel #3
0
        /// <summary>
        /// Submits the specified callable to the thread pool.
        /// </summary>
        /// <param name="callable">The callable.</param>
        /// <returns></returns>
        public IFuture <T> Submit <T>(Func <T> callable)
        {
            var future = new FutureImpl <T>();

            Log.Debug("Submit: Instance {0} - enqueuing function", _id);
            _taskQueue.Push(
                delegate { future.Value = callable.Invoke(); });
            return(future);
        }
Beispiel #4
0
        /// <summary>
        /// Submits the specified callable to the thread pool.
        /// </summary>
        /// <param name="callable">The callable.</param>
        /// <returns></returns>
        public IFuture <T> Submit <T>(ICallable <T> callable)
        {
            var future = new FutureImpl <T>();

            Log.Debug("Submit: Instance {0} - enqueuing callable", _id);
            _taskQueue.Push(
                () => future.Value = callable.Call());
            return(future);
        }