IEnumerator Start()
        {
            this.executor = new ThreadExecutor();

            IAsyncResult r1 = this.executor.Execute(Task1);

            yield return(r1.WaitForDone());

            IAsyncResult r2 = this.executor.Execute(promise => Task2(promise));

            yield return(r2.WaitForDone());

            IAsyncResult <string> r3 = this.executor.Execute <string> (promise => Task3(promise));

            yield return(new WaitForSeconds(0.5f));

            r3.Cancel();
            yield return(r3.WaitForDone());

            Debug.LogFormat("Task3 IsCalcelled:{0}", r3.IsCancelled);

            IProgressResult <float, string> r4 = this.executor.Execute <float, string> (promise => Task4(promise));

            while (!r4.IsDone)
            {
                yield return(null);

                Debug.LogFormat("Task4 Progress:{0}%", Mathf.FloorToInt(r4.Progress * 100));
            }

            Debug.LogFormat("Task4 Result:{0}", r4.Result);
        }
Esempio n. 2
0
    public RewardRepository()
    {
        executor = new ThreadExecutor();

        money = 5;
        Award award1 = new Award();

        award1.Name    = "海底捞免单券";
        award1.Count   = 1;
        award1.Quality = (int)QualityType.Orange;
        Award award2 = new Award();

        award2.Name    = "肯德基全家桶";
        award2.Count   = 1;
        award2.Quality = (int)QualityType.Purple;
        Award award3 = new Award();

        award3.Name    = "小豆面馆油条";
        award3.Count   = 5;
        award3.Quality = (int)QualityType.Blue;

        awardCache.Add(award1);
        awardCache.Add(award2);
        awardCache.Add(award3);


        //测试数据
        for (int i = 0; i < 12; i++)
        {
            idxs.Add(i);
        }
        qrCode = "";
    }
Esempio n. 3
0
        public AccountRepository()
        {
            executor = new ThreadExecutor();
            Account account = new Account()
            {
                Username = "******", Password = "******", Created = DateTime.Now
            };

            cache.Add(account.Username, account);
        }
 /// <summary>
 /// Creates a scheduler using the specified thread pool and job store and
 /// binds it for remote access.
 /// </summary>
 /// <param name="schedulerName">The name for the scheduler.</param>
 /// <param name="schedulerInstanceId">The instance ID for the scheduler.</param>
 /// <param name="threadPool">The thread pool for executing jobs</param>
 /// <param name="threadExecutor">Thread executor.</param>
 /// <param name="jobStore">The type of job store</param>
 /// <param name="schedulerPluginMap"></param>
 /// <param name="idleWaitTime">The idle wait time. You can specify TimeSpan.Zero for
 ///     the default value, which is currently 30000 ms.</param>
 /// <param name="maxBatchSize">The maximum batch size of triggers, when acquiring them</param>
 /// <param name="batchTimeWindow">The time window for which it is allowed to "pre-acquire" triggers to fire</param>
 public virtual void CreateScheduler(
     string schedulerName,
     string schedulerInstanceId,
     IThreadPool threadPool,
     IThreadExecutor threadExecutor,
     IJobStore jobStore,
     IDictionary <string, ISchedulerPlugin> schedulerPluginMap,
     TimeSpan idleWaitTime,
     int maxBatchSize,
     TimeSpan batchTimeWindow)
 {
     CreateScheduler(schedulerName, schedulerInstanceId, threadPool, threadExecutor, jobStore, schedulerPluginMap, idleWaitTime, maxBatchSize, batchTimeWindow, null);
 }
Esempio n. 5
0
        public void ForEachThread(IThreadExecutor threadExecutor)
        {
            var tasks = new List <Task>();

            for (int i = 0; i < threadCount; i++)
            {
                tasks.Add(Task.Factory.StartNew(() => threadExecutor.OnThread()));
            }
            foreach (var task in tasks)
            {
                task.Wait();
            }
        }
        /// <summary>
        /// Creates a scheduler using the specified thread pool and job store and
        /// binds it for remote access.
        /// </summary>
        /// <param name="schedulerName">The name for the scheduler.</param>
        /// <param name="schedulerInstanceId">The instance ID for the scheduler.</param>
        /// <param name="threadPool">The thread pool for executing jobs</param>
        /// <param name="threadExecutor">Thread executor.</param>
        /// <param name="jobStore">The type of job store</param>
        /// <param name="schedulerPluginMap"></param>
        /// <param name="idleWaitTime">The idle wait time. You can specify TimeSpan.Zero for
        /// the default value, which is currently 30000 ms.</param>
        /// <param name="dbFailureRetryInterval">The db failure retry interval.</param>
        /// <param name="maxBatchSize">The maximum batch size of triggers, when acquiring them</param>
        /// <param name="batchTimeWindow">The time window for which it is allowed to "pre-acquire" triggers to fire</param>
        public virtual void CreateScheduler(string schedulerName, string schedulerInstanceId, IThreadPool threadPool, IThreadExecutor threadExecutor,
                                            IJobStore jobStore, IDictionary<string, ISchedulerPlugin> schedulerPluginMap, TimeSpan idleWaitTime,
                                            TimeSpan dbFailureRetryInterval, int maxBatchSize, TimeSpan batchTimeWindow)
        {
            // Currently only one run-shell factory is available...
            IJobRunShellFactory jrsf = new StdJobRunShellFactory();

            // Fire everything u
            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            threadPool.Initialize();

            QuartzSchedulerResources qrs = new QuartzSchedulerResources();

            qrs.Name = schedulerName;
            qrs.InstanceId = schedulerInstanceId;

            SchedulerDetailsSetter.SetDetails(threadPool, schedulerName, schedulerInstanceId);

            qrs.JobRunShellFactory = jrsf;
            qrs.ThreadPool = threadPool;
            qrs.ThreadExecutor= threadExecutor;
            qrs.JobStore = jobStore;
            qrs.MaxBatchSize = maxBatchSize;
            qrs.BatchTimeWindow = batchTimeWindow;

            // add plugins
            if (schedulerPluginMap != null)
            {
                foreach (ISchedulerPlugin plugin in schedulerPluginMap.Values)
                {
                    qrs.AddSchedulerPlugin(plugin);
                }
            }

            QuartzScheduler qs = new QuartzScheduler(qrs, idleWaitTime, dbFailureRetryInterval);

            ITypeLoadHelper cch = new SimpleTypeLoadHelper();
            cch.Initialize();

            SchedulerDetailsSetter.SetDetails(jobStore, schedulerName, schedulerInstanceId);
            jobStore.Initialize(cch, qs.SchedulerSignaler);

            IScheduler scheduler = new StdScheduler(qs);

            jrsf.Initialize(scheduler);

            qs.Initialize();

            // Initialize plugins now that we have a Scheduler instance.
            if (schedulerPluginMap != null)
            {
                foreach (var pluginEntry in schedulerPluginMap)
                {
                    pluginEntry.Value.Initialize(pluginEntry.Key, scheduler);
                }
            }

            Log.Info(string.Format(CultureInfo.InvariantCulture, "Quartz scheduler '{0}", scheduler.SchedulerName));

            Log.Info(string.Format(CultureInfo.InvariantCulture, "Quartz scheduler version: {0}", qs.Version));

            SchedulerRepository schedRep = SchedulerRepository.Instance;

            qs.AddNoGCObject(schedRep); // prevents the repository from being
            // garbage collected

            schedRep.Bind(scheduler);

            initialized = true;
        }
 /// <summary>
 /// Creates a scheduler using the specified thread pool and job store and
 /// binds it for remote access.
 /// </summary>
 /// <param name="schedulerName">The name for the scheduler.</param>
 /// <param name="schedulerInstanceId">The instance ID for the scheduler.</param>
 /// <param name="threadPool">The thread pool for executing jobs</param>
 /// <param name="threadExecutor">Thread executor.</param>
 /// <param name="jobStore">The type of job store</param>
 /// <param name="schedulerPluginMap"></param>
 /// <param name="idleWaitTime">The idle wait time. You can specify TimeSpan.Zero for
 /// the default value, which is currently 30000 ms.</param>
 /// <param name="dbFailureRetryInterval">The db failure retry interval.</param>
 public virtual void CreateScheduler(string schedulerName, string schedulerInstanceId, IThreadPool threadPool, IThreadExecutor threadExecutor,
                                     IJobStore jobStore, IDictionary<string, ISchedulerPlugin> schedulerPluginMap, TimeSpan idleWaitTime,
                                     TimeSpan dbFailureRetryInterval)
 {
     CreateScheduler(schedulerName, schedulerInstanceId, threadPool, threadExecutor, jobStore, schedulerPluginMap, idleWaitTime, dbFailureRetryInterval, DefaultBatchMaxSize, DefaultBatchTimeWindow);
 }
Esempio n. 8
0
        /// <summary>
        /// Creates a scheduler using the specified thread pool and job store and
        /// binds it for remote access.
        /// </summary>
        /// <param name="schedulerName">The name for the scheduler.</param>
        /// <param name="schedulerInstanceId">The instance ID for the scheduler.</param>
        /// <param name="threadPool">The thread pool for executing jobs</param>
        /// <param name="threadExecutor">Thread executor.</param>
        /// <param name="jobStore">The type of job store</param>
        /// <param name="schedulerPluginMap"></param>
        /// <param name="idleWaitTime">The idle wait time. You can specify TimeSpan.Zero for
        /// the default value, which is currently 30000 ms.</param>
        /// <param name="dbFailureRetryInterval">The db failure retry interval.</param>
        /// <param name="maxBatchSize">The maximum batch size of triggers, when acquiring them</param>
        /// <param name="batchTimeWindow">The time window for which it is allowed to "pre-acquire" triggers to fire</param>
        public virtual void CreateScheduler(string schedulerName, string schedulerInstanceId, IThreadPool threadPool, IThreadExecutor threadExecutor,
                                            IJobStore jobStore, IDictionary <string, ISchedulerPlugin> schedulerPluginMap, TimeSpan idleWaitTime,
                                            TimeSpan dbFailureRetryInterval, int maxBatchSize, TimeSpan batchTimeWindow)
        {
            // Currently only one run-shell factory is available...
            IJobRunShellFactory jrsf = new StdJobRunShellFactory();

            // Fire everything u
            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            threadPool.Initialize();

            QuartzSchedulerResources qrs = new QuartzSchedulerResources();

            qrs.Name       = schedulerName;
            qrs.InstanceId = schedulerInstanceId;

            SchedulerDetailsSetter.SetDetails(threadPool, schedulerName, schedulerInstanceId);

            qrs.JobRunShellFactory = jrsf;
            qrs.ThreadPool         = threadPool;
            qrs.ThreadExecutor     = threadExecutor;
            qrs.JobStore           = jobStore;
            qrs.MaxBatchSize       = maxBatchSize;
            qrs.BatchTimeWindow    = batchTimeWindow;

            // add plugins
            if (schedulerPluginMap != null)
            {
                foreach (ISchedulerPlugin plugin in schedulerPluginMap.Values)
                {
                    qrs.AddSchedulerPlugin(plugin);
                }
            }

            QuartzScheduler qs = new QuartzScheduler(qrs, idleWaitTime);

            ITypeLoadHelper cch = new SimpleTypeLoadHelper();

            cch.Initialize();

            SchedulerDetailsSetter.SetDetails(jobStore, schedulerName, schedulerInstanceId);
            jobStore.Initialize(cch, qs.SchedulerSignaler);

            IScheduler scheduler = new StdScheduler(qs);

            jrsf.Initialize(scheduler);

            qs.Initialize();

            // Initialize plugins now that we have a Scheduler instance.
            if (schedulerPluginMap != null)
            {
                foreach (var pluginEntry in schedulerPluginMap)
                {
                    pluginEntry.Value.Initialize(pluginEntry.Key, scheduler);
                }
            }

            Log.Info(string.Format(CultureInfo.InvariantCulture, "Quartz scheduler '{0}", scheduler.SchedulerName));

            Log.Info(string.Format(CultureInfo.InvariantCulture, "Quartz scheduler version: {0}", qs.Version));

            SchedulerRepository schedRep = SchedulerRepository.Instance;

            qs.AddNoGCObject(schedRep); // prevents the repository from being
            // garbage collected

            schedRep.Bind(scheduler);

            initialized = true;
        }
Esempio n. 9
0
 /// <summary>
 /// Creates a scheduler using the specified thread pool and job store and
 /// binds it for remote access.
 /// </summary>
 /// <param name="schedulerName">The name for the scheduler.</param>
 /// <param name="schedulerInstanceId">The instance ID for the scheduler.</param>
 /// <param name="threadPool">The thread pool for executing jobs</param>
 /// <param name="threadExecutor">Thread executor.</param>
 /// <param name="jobStore">The type of job store</param>
 /// <param name="schedulerPluginMap"></param>
 /// <param name="idleWaitTime">The idle wait time. You can specify TimeSpan.Zero for
 /// the default value, which is currently 30000 ms.</param>
 /// <param name="dbFailureRetryInterval">The db failure retry interval.</param>
 public virtual void CreateScheduler(string schedulerName, string schedulerInstanceId, IThreadPool threadPool, IThreadExecutor threadExecutor,
                                     IJobStore jobStore, IDictionary <string, ISchedulerPlugin> schedulerPluginMap, TimeSpan idleWaitTime,
                                     TimeSpan dbFailureRetryInterval)
 {
     CreateScheduler(schedulerName, schedulerInstanceId, threadPool, threadExecutor, jobStore, schedulerPluginMap, idleWaitTime, dbFailureRetryInterval, DefaultBatchMaxSize, DefaultBatchTimeWindow);
 }
Esempio n. 10
0
 public AccountService(IAccountRepository repository)
 {
     this.repository = repository;
     this.executor   = new ThreadExecutor();
 }
	    /// <summary>
	    /// Creates a scheduler using the specified thread pool and job store and
	    /// binds it for remote access.
	    /// </summary>
	    /// <param name="schedulerName">The name for the scheduler.</param>
	    /// <param name="schedulerInstanceId">The instance ID for the scheduler.</param>
	    /// <param name="threadPool">The thread pool for executing jobs</param>
	    /// <param name="threadExecutor">Thread executor.</param>
	    /// <param name="jobStore">The type of job store</param>
	    /// <param name="schedulerPluginMap"></param>
	    /// <param name="idleWaitTime">The idle wait time. You can specify TimeSpan.Zero for
	    ///     the default value, which is currently 30000 ms.</param>
	    /// <param name="maxBatchSize">The maximum batch size of triggers, when acquiring them</param>
	    /// <param name="batchTimeWindow">The time window for which it is allowed to "pre-acquire" triggers to fire</param>
	    public virtual void CreateScheduler(
	        string schedulerName,
	        string schedulerInstanceId,
	        IThreadPool threadPool,
	        IThreadExecutor threadExecutor,
	        IJobStore jobStore,
	        IDictionary<string, ISchedulerPlugin> schedulerPluginMap,
	        TimeSpan idleWaitTime,
	        int maxBatchSize,
	        TimeSpan batchTimeWindow)
	    {
	        CreateScheduler(schedulerName, schedulerInstanceId, threadPool, threadExecutor, jobStore, schedulerPluginMap, idleWaitTime, maxBatchSize, batchTimeWindow, null);
	    }