Exemplo n.º 1
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="Spring.Threading.IRunnable"/> task requested to be executed</param>
 /// <param name="executor">the <see cref="Spring.Threading.Execution.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);
 }
Exemplo n.º 2
0
        /// <summary>
        /// The constructor.
        /// </summary>
        /// <param name="cacheHostInformationPoller">The cache host information poller.</param>
        /// <param name="memCache">The mem cache to use for storing objects.</param>
        /// <param name="clientToCacheServiceHost">The client to cache service host.</param>
        /// <param name="cacheManagerClient">The cache manager client.</param>
        public CacheHostEngine(IRunnable cacheHostInformationPoller, MemCache memCache, ServiceHost clientToCacheServiceHost)
        {
            // Sanitize
            if (cacheHostInformationPoller == null)
            {
                throw new ArgumentNullException("cacheHostInformationPoller");
            }
            if (memCache == null)
            {
                throw new ArgumentNullException("memCache");
            }
            if (clientToCacheServiceHost == null)
            {
                throw new ArgumentNullException("clientToCacheServiceHost");
            }

            // Set the cache host information poller
            _cacheHostInformationPoller = cacheHostInformationPoller;

            // Set the mem cache container instance
            MemCacheContainer.Instance = memCache;

            // Initialize the service hosts
            _clientToCacheServiceHost = clientToCacheServiceHost;
        }
		public override View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
		{
			mCountdownRunnable = new Runnable(() => {
				int remainingSec = (int) Math.Max(0,(UIUtils.CONFERENCE_START_MILLIS - JavaSystem.CurrentTimeMillis()) / 1000);
	            bool conferenceStarted = remainingSec == 0;
	
	            if (conferenceStarted) 
				{
	                // Conference started while in countdown mode, switch modes and
	                // bail on future countdown updates.
	                messageHandler.PostDelayed(() => {
						Refresh();
					}, 100);
	                return;
	            }
	
	            int secs = remainingSec % 86400;
	            int days = remainingSec / 86400;
	            string str = Resources.GetQuantityString(
	                    Resource.Plurals.whats_on_countdown_title, days, days,
	                    DateUtils.FormatElapsedTime(secs));
	            countdownTextView.Text = str;
	
	            // Repost ourselves to keep updating countdown
	            messageHandler.PostDelayed(mCountdownRunnable, 1000);	
			});
			
			rootView = (ViewGroup) inflater.Inflate (Resource.Layout.FragmentWhatsOn, container);
			Refresh();
			return rootView;
		}
 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);
 }
Exemplo n.º 5
0
 private Object consume(IRunnable runnable, Object parameter)
 {
     var consumers = runnableManager.GetConsumers(runnable);
     var converter = consumers.FirstOrDefault(c => c.IsConvertable(parameter));
     if (converter == null) return ExecuteRunnable(runnable, parameter);
     return converter.Convert(parameter, param => ExecuteRunnable(runnable, param));
 }
Exemplo n.º 6
0
		public override void Sync(IRunnable runnable)
		{
			lock (_bin)
			{
				base.Sync(runnable);
			}
		}
	public static void postOnAnimation(View view, IRunnable runnable) {
		if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.JellyBean) {
			SDK16.postOnAnimation(view, runnable);
		} else {
			view.PostDelayed(runnable, 16);
		}
	}
Exemplo n.º 8
0
 private Object produce(IRunnable runnable, Object result)
 {
     var producers = runnableManager.GetProducers(runnable);
     var converter = producers.FirstOrDefault(c => c.IsConvertable(result));
     if (converter == null) return result;
     return converter.Convert(result);
 }
 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);
 }
Exemplo n.º 10
0
        /**
         * Builds the task.
         * 
         * @param runnable
         *            The wrapped Runnable object.
         * @throws InvalidPatternException
         *             If the supplied pattern is not valid.
         */
        public RunnableTask(IRunnable runnable)
        {
            if (runnable == null)
                throw new ArgumentNullException("runnable", "runnable is null.");

            this._runnable = runnable;
        }
Exemplo n.º 11
0
        public void Run()
        {
            Buffer buf = new Buffer(300); // ??
            Packet packet = new Packet(buf);
            thread = this;
            try
            {
                while (thread != null)
                {
                    Socket socket = ss.Accept();
                    socket.setTcpNoDelay(true);
                    Stream In = socket.getInputStream();
                    Stream Out = socket.getOutputStream();
                    ChannelDirectTCPIP channel = new ChannelDirectTCPIP();
                    channel.Init();
                    channel.setInputStream(In);
                    channel.setOutputStream(Out);
                    session.addChannel(channel);
                    ((ChannelDirectTCPIP)channel).Host = host;
                    ((ChannelDirectTCPIP)channel).Port = rport;
                    ((ChannelDirectTCPIP)channel).OrgIPAddress = socket.getInetAddress().getHostAddress();
                    ((ChannelDirectTCPIP)channel).OrgPort = socket.Port;
                    channel.connect();
                    if (channel.ExitStatus != -1)
                    {
                    }
                }
            }
            catch { }

            delete();
        }
Exemplo n.º 12
0
 public override void Queue(IRunnable runnable)
 {
     using (RWLock.AsReader(_lock))
       {
     SelectQueue(_lock, _queues, runnable).Enqueue(runnable);
       }
 }
Exemplo n.º 13
0
		public Thread NewThread (IRunnable r)
		{
			Thread t = new Thread (r);
			t.SetDaemon (true);
			t.Start ();
			return t;
		}
Exemplo n.º 14
0
        // ===========================================================
        // Methods
        // ===========================================================

        public void PostRunnable(/* final */ IRunnable pRunnable)
        {
            lock (_methodLock)
            {
                this.mRunnables.Add(pRunnable);
            }
        }
Exemplo n.º 15
0
        public static void RunRunnable(IRunnable runnable)
        {
            Thread thread = new Thread(runnable.Run);
            thread.IsBackground = true;
            thread.Priority = ThreadPriority.Lowest;

            thread.Start();
        }
Exemplo n.º 16
0
 public static void PostOnAnimation(View view, IRunnable runnable)
 {
     if ((int)Android.OS.Build.VERSION.SdkInt >= (int)Android.OS.Build.VERSION_CODES.JellyBean) {
         PostOnAnimationJellyBean(view, runnable);
     } else {
         view.PostDelayed(runnable, SIXTY_FPS_INTERVAL);
     }
 }
Exemplo n.º 17
0
        Thread(IRunnable runnable, ThreadGroup grp, string name)
        {
            _thread = new System.Threading.Tasks.Task(InternalRun);

            this._runnable = runnable ?? this;
            _tgroup = grp ?? _defaultGroup;
            _tgroup.Add (this);
        }
Exemplo n.º 18
0
 /// <summary> Returns wrapped runnable that ensures that if an exception occurs
 /// during the execution, the specified exception handler is invoked.
 /// </summary>
 /// <param name="runnable">runnable for which exceptions are to be intercepted
 /// </param>
 /// <param name="handler">the exception handler to call when exception occurs
 /// during execution of the given runnable
 /// </param>
 /// <returns> wrapped runnable
 /// </returns>
 /// <exception cref="System.ArgumentNullException">If either parameter is <c>null</c></exception>
 public static IRunnable AssignExceptionHandler(IRunnable runnable, UncaughtExceptionHandlerDelegate handler)
 {
     if ( runnable == null )
         throw new ArgumentNullException("runnable", "Runnable cannot be null");
     if ( handler == null )
         throw new ArgumentNullException("handler", "Handler cannot be null");
     return new AnonymousClassRunnable(runnable, handler);
 }
 public void Execute(IRunnable command)
 {
     if (!this.IsAcceptingNewTasks)
     {
         throw new RejectedExecutionException();
     }
     this.Unwrap().Execute(command);
 }
Exemplo n.º 20
0
 public override void Execute(IRunnable command)
 {
     if (command == null)
     {
         throw new NullReferenceException("command");
     }
     this.tasks.Enqueue(command);
 }
        /// <summary>
        /// Role Service Constructor
        /// </summary>
        /// <param name="run">Task Manager</param>
        public TaskService(IRunnable run)
        {
            if (null == run)
            {
                throw new ArgumentNullException("run");
            }

            this.run = run;
        }
        public override IDisposable ScheduleDirect(IRunnable run, TimeSpan delay)
        {
            ScheduledRunnable sr = new ScheduledRunnable(run, null);

            IDisposable d = Task.Delay(delay).ContinueWith(t => sr.Run());
            sr.SetFuture(d);

            return sr;
        }
Exemplo n.º 23
0
 public static Thread ExecuteAfter(string threadName, long timeInMillis, IRunnable
     runnable)
 {
     Thread t = new _Thread_96(timeInMillis, runnable);
     t.SetName(threadName);
     t.SetDaemon(true);
     t.Start();
     return t;
 }
        public override IDisposable ScheduleDirect(IRunnable run)
        {
            ScheduledRunnable sr = new ScheduledRunnable(run, null);

            IDisposable d = Task.Run(() => sr.Run());
            sr.SetFuture(d);

            return sr;
        }
Exemplo n.º 25
0
        /// <summary> 
        /// Execute the given command in a new thread.
        /// </summary>
        public virtual void Execute(IRunnable runnable)
        {
            lock (this)
            {
                Utils.FailFastIfInterrupted();

                Thread thread = ThreadFactory.NewThread(runnable);
                thread.Start();
            }
        }
Exemplo n.º 26
0
		Thread (IRunnable runnable, ThreadGroup grp, string name)
		{
			_thread = new System.Threading.Thread (InternalRun);
			
			this._runnable = runnable ?? this;
			_tgroup = grp ?? _defaultGroup;
			_tgroup.Add (this);
			if (name != null)
				_thread.Name = name;
		}
        /**
         * Creates and executes a one-shot action that becomes enabled
         * after the given delay.
         *
         * @param task  the task to execute
         * @param delay the time from now to delay execution
         * @param unit  the time unit of the delay parameter
         * @return a Future representing pending completion of
         *         the task and whose <tt>get()</tt> method will return
         *         <tt>null</tt> upon completion
         */
        public IFuture<object> schedule(IRunnable task, int delayMs)
        {
            if (!isOpen.get())
            {
                throw new InvalidOperationException("CloseableExecutorService is closed");
            }

            var futureTask = new InternalFutureTask<object>(this, task);
            return _scheduledExecService.schedule(futureTask, delayMs);
        }
Exemplo n.º 28
0
        /// <summary>
        /// The constructor.
        /// </summary>
        /// <param name="cacheHostServer">The cache host server.</param>
        public CacheHostRunner(IRunnable cacheHostServer)
        {
            // Sanitize
            if (cacheHostServer == null)
            {
                throw new ArgumentNullException("cacheHostServer");
            }

            _cacheServer = cacheHostServer;
        }
Exemplo n.º 29
0
		public override void Start()
		{
			base.Start();
			
			if (currentRunnable != null)
				currentRunnable.Stop();

			currentRunnable = null;
			currentIndex = 0;
		}
Exemplo n.º 30
0
 public SliderView(Context paramContext, IAttributeSet paramAtributeSet, int paramint)
     : base(paramContext, paramAtributeSet, paramint)
 {
     this.hideSliderRunnable = new Runnable(() => hideSlider(true));
     LayoutInflater.From(Context).Inflate(Resource.Layout.slider, this);
     slider = (SliderView)FindViewById(Resource.Id.slider_control);
     indeterminateSlider = ((ImageView)FindViewById(Resource.Id.indeterminate_slider));
     hideSlider(false);
     hideIndeterminateSlider(false);
 }
Exemplo n.º 31
0
 public SchedulerRegistration(IRunnable action, ICancelable cancellation)
 {
     Action       = action;
     Cancellation = cancellation;
 }
Exemplo n.º 32
0
 public override bool PostDelayed(IRunnable action, long delayMillis)
 {
     return(base.PostDelayed(action, delayMillis));
 }
Exemplo n.º 33
0
 public override void Sync(IRunnable runnable)
 {
     ++_enclosing._numberOfSyncCalls;
     base.Sync(runnable);
 }
Exemplo n.º 34
0
 /// <summary>
 /// Creates a <see cref="FutureTask{T}"/> that will, upon running, execute the
 /// given <see cref="IRunnable"/>, and arrange that <see cref="GetResult()"/>
 /// will return the given <paramref name="result"/> upon successful completion.
 /// </summary>
 /// <param name="task">The runnable task.</param>
 /// <param name="result">
 /// The result to return on successful completion. If
 /// you don't need a particular result, consider using
 /// constructions of the form:
 /// <code language="c#">
 ///        Future f = new FutureTask(runnable, default(T))
 ///    </code>
 /// </param>
 /// <exception cref="System.ArgumentNullException">
 /// If the <paramref name="task"/> is <c>null</c>.
 /// </exception>
 public FutureTask(IRunnable task, T result)
     : this(Executors.CreateCallable(task, result))
 {
 }
Exemplo n.º 35
0
 public override void Sync(IRunnable runnable)
 {
     FlushAllPages();
     base.Sync(new _IRunnable_119(this, runnable));
 }
Exemplo n.º 36
0
 public Thread()
 {
     _target = this;
 }
Exemplo n.º 37
0
 public abstract void Execute(IRunnable task);
Exemplo n.º 38
0
 public abstract void SyncFiles(IRunnable runnable);
Exemplo n.º 39
0
 public abstract void ClearRun(IRunnable run);
 public Thread NewThread(IRunnable runnable)
 {
     return(_manager.NewManagedThread(runnable.Run, "T" + NextThreadId(false)));
 }
 public void Execute(IRunnable command)
 {
     Execute(command.Run);
 }
Exemplo n.º 42
0
 public _IRunnable_119(CachingBin _enclosing, IRunnable runnable)
 {
     this._enclosing = _enclosing;
     this.runnable   = runnable;
 }
Exemplo n.º 43
0
 public _IRunnable_41(ThreadPool4Impl _enclosing, IRunnable task)
 {
     this._enclosing = _enclosing;
     this.task       = task;
 }
Exemplo n.º 44
0
        public virtual void Start(string taskName, IRunnable task)
        {
            Thread thread = ThreadFor(taskName, task);

            ActivateThread(thread);
        }
Exemplo n.º 45
0
 /// <summary>
 /// Queues or executes (depending on the implementation) the <see cref="IRunnable"/>
 /// </summary>
 /// <param name="run">The asynchronous task to be executed</param>
 /// <exception cref="RejectedExecutionException">Thrown when the service can't accept additional tasks.</exception>
 public abstract void Execute(IRunnable run);
Exemplo n.º 46
0
        public static object Compare(object newPoint, object lastCheckValue, IRunnable rightSide, OperatorType operatorType)
        {
            try
            {
                if (rightSide == null)
                {
                    throw new Exception("I cannot found right side of condition please check if you are using empty parentheses just remove them");
                }
                //if that was first condition
                //if (lastCheckValue == null)
                //    return true;// (bool)rightSide.Run(newPoint);
                object rightValue = rightSide.Run(newPoint);
                Type   leftType   = null;
                if (lastCheckValue != null)
                {
                    leftType = lastCheckValue.GetType();
                }
                switch (operatorType)
                {
                //check 'and' condition
                case OperatorType.And:
                {
                    return((bool)lastCheckValue && (bool)rightValue);
                }

                //check 'or' condition
                case OperatorType.Or:
                {
                    return((bool)lastCheckValue || (bool)rightValue);
                }

                case OperatorType.Equal:
                {
                    return(Equals(lastCheckValue, ConvertType(leftType, rightValue)));
                }

                case OperatorType.NotEqual:
                {
                    return(!Equals(lastCheckValue, ConvertType(leftType, rightValue)));
                }

                case OperatorType.GreaterThan:
                {
                    IComparable leftSideCompare = (IComparable)lastCheckValue;
                    return(leftSideCompare.CompareTo(ConvertType(leftType, rightValue)) == 1);
                }

                case OperatorType.LessThan:
                {
                    IComparable leftSideCompare = (IComparable)lastCheckValue;
                    return(leftSideCompare.CompareTo(ConvertType(leftType, rightValue)) == -1);
                }

                case OperatorType.GreaterThanEqual:
                {
                    IComparable leftSideCompare = (IComparable)lastCheckValue;
                    int         result          = leftSideCompare.CompareTo(ConvertType(leftType, rightValue));
                    return(result >= 0);
                }

                case OperatorType.LessThanEqual:
                {
                    IComparable leftSideCompare = (IComparable)lastCheckValue;
                    int         result          = leftSideCompare.CompareTo(ConvertType(leftType, rightValue));
                    return(result <= 0);
                }

                default:
                    throw new Exception($"I cannot support {operatorType} operator");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 47
0
 protected override void InternalScheduleOnce(TimeSpan delay, IRunnable action, ICancelable cancelable)
 {
     InternalSchedule(delay, TimeSpan.Zero, action, cancelable);
 }
Exemplo n.º 48
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="job"></param>
 public void Add(IRunnable job)
 {
     jobs.Enqueue(job);
     NumJobs++;
     Interlocked.Increment(ref numJobsToRun);
 }
 public PreferenceFragment()
 {
     mHandler      = new MyHandler(this);
     mRequestFocus = new MyRunnable(this);
 }
Exemplo n.º 50
0
 public _IClosure4_85(ThreadedSyncBin _enclosing, IRunnable runnable)
 {
     this._enclosing = _enclosing;
     this.runnable   = runnable;
 }
 /// <summary>
 /// 回调 <see cref="IRunnable.Stop"/> 然后<see cref="IRunnable.WaitToStop"/>.
 /// </summary>
 public static void StopAndWaitToStop(this IRunnable runnable)
 {
     runnable.Stop();
     runnable.WaitToStop();
 }
Exemplo n.º 52
0
 public DummyJob(IRunnable actualJob)
 {
     ActualJob = actualJob;
 }
Exemplo n.º 53
0
 public virtual void Sync(IRunnable runnable)
 {
     _bin.Sync(runnable);
 }
Exemplo n.º 54
0
 protected virtual void WithContent(AbstractBufferContext context, IRunnable runnable
                                    )
 {
     runnable.Run();
 }
Exemplo n.º 55
0
 public _Thread_96(long timeInMillis, IRunnable runnable)
 {
     this.timeInMillis = timeInMillis;
     this.runnable     = runnable;
 }
Exemplo n.º 56
0
 protected override void InternalScheduleRepeatedly(TimeSpan initialDelay, TimeSpan interval, IRunnable action, ICancelable cancelable)
 {
     InternalSchedule(initialDelay, interval, action, cancelable);
 }
Exemplo n.º 57
0
 public override void Execute(IRunnable run)
 {
     run.Run();
 }
Exemplo n.º 58
0
 public override void Sync(IRunnable runnable)
 {
     WaitForPendingSync();
     _lock.Run(new _IClosure4_85(this, runnable));
 }
Exemplo n.º 59
0
 public Thread(IRunnable target, string name)
 {
     _target = target;
     SetName(name);
 }
Exemplo n.º 60
0
 public Thread(IRunnable target)
 {
     _target = target;
 }