private Mediator() { _budget = Convert.ToDouble(ConfigurationManager.AppSettings["TASK_BUDGET"]); _backgroundTaskFactory = new TaskFactory(TaskCreationOptions.LongRunning, TaskContinuationOptions.None); _staTaskFactory = new TaskFactory(new LongRunningTaskScheduler(ApartmentState.STA)); _preemptiveScheduler = new PriorityTaskScheduler(); }
public PdfService(string basepath, StorageService storage, string temporaryDirectory, int cacheDuration, PriorityTaskScheduler longRunningTaskScheduler) { basePath = basepath; this.temporaryDirectory = temporaryDirectory; this.cacheDuration = cacheDuration; this.longRunningTaskScheduler = longRunningTaskScheduler; if (!Directory.Exists(basepath)) { Directory.CreateDirectory(basepath); } lock (globalLock) { if (unoconv == null) { if (!Directory.Exists(basepath + "/unoconv")) { Directory.CreateDirectory(basepath + "/unoconv"); } unoconv = new UnoConv(basepath + "/unoconv"); } } Storage = storage; Storage.FileCreated += OnFileCreated; Storage.FileChanged += OnFileChanged; Storage.FileDeleted += OnFileDeleted; Storage.StorageDeleted += OnStorageDeleted; }
public Mediator(IMediatorAdapter mediatorAdapter, IEventBroker eventAggregator) { _mediatorAdapter = mediatorAdapter; _mediatorAdapter.OnBroadcast += Broadcast; _eventAggregator = eventAggregator;// IoC.Get<IEventAggregator>(); _preemptiveScheduler = new PriorityTaskScheduler(); _backgroundTaskFactory = new TaskFactory(TaskCreationOptions.LongRunning, TaskContinuationOptions.None); }
public AudioService(string basepath, StorageService storage, string temporaryDirectory, int cacheDuration, PriorityTaskScheduler longRunningTaskScheduler) { basePath = basepath; this.temporaryDirectory = temporaryDirectory; this.cacheDuration = cacheDuration; this.longRunningTaskScheduler = longRunningTaskScheduler; Storage = storage; Storage.FileCreated += OnFileCreated; Storage.FileChanged += OnFileChanged; Storage.FileDeleted += OnFileDeleted; Storage.StorageDeleted += OnStorageDeleted; }
public ChannelTaskScheduler(ExtendedActorSystem system) { //config channel-scheduler var config = system.Settings.Config.GetConfig("akka.channel-scheduler"); _maximumConcurrencyLevel = ThreadPoolConfig.ScaledPoolSize( config.GetInt("parallelism-min"), config.GetDouble("parallelism-factor", 1.0D), // the scalar-based factor to scale the threadpool size to config.GetInt("parallelism-max")); _maximumConcurrencyLevel = Math.Max(_maximumConcurrencyLevel, 1); _maxWork = Math.Max(config.GetInt("work-max", _maxWork), 3); //min 3 normal work in work-loop _workInterval = config.GetInt("work-interval", _workInterval); _workStep = config.GetInt("work-step", _workStep); //create task schedulers var channelOptions = new UnboundedChannelOptions() { AllowSynchronousContinuations = true, SingleReader = _maximumConcurrencyLevel == 1, SingleWriter = false }; _highScheduler = new PriorityTaskScheduler(Channel.CreateUnbounded <Task>(channelOptions), TaskSchedulerPriority.AboveNormal); _normalScheduler = new PriorityTaskScheduler(Channel.CreateUnbounded <Task>(channelOptions), TaskSchedulerPriority.Normal); _lowScheduler = new PriorityTaskScheduler(Channel.CreateUnbounded <Task>(channelOptions), TaskSchedulerPriority.Low); _idleScheduler = new PriorityTaskScheduler(Channel.CreateUnbounded <Task>(channelOptions), TaskSchedulerPriority.Idle); //prefill coworker array _coworkers = new Task[_maximumConcurrencyLevel - 1]; for (var i = 0; i < _coworkers.Length; i++) { _coworkers[i] = Task.CompletedTask; } //init paused timer _timer = new Timer(ScheduleCoWorkers, "timer", Timeout.Infinite, Timeout.Infinite); //start main worker _controlTask = Task.Factory.StartNew(ControlAsync, _cts.Token, TaskCreationOptions.DenyChildAttach | TaskCreationOptions.LongRunning, TaskScheduler.Default).Unwrap(); }
public ManageService(PriorityTaskScheduler scheduler) { this.scheduler = scheduler; // API only available to authenticated users BeforeAsync = async(p, c) => await c.EnsureIsSuperAdminAsync(); Get["/"] = (p, c) => { c.Response.StatusCode = 200; c.Response.Headers["cache-control"] = "no-cache, must-revalidate"; JsonValue json = new JsonObject(); c.Response.Content = new JsonContent(json); // get connected HTTP clients json["clients"] = GetClients(c, c.Request.QueryString); // get long running tasks json["tasks"] = GetTasks(c.Request.QueryString); c.Response.Content = json; }; // GET /clients get all connected HTTP clients Get["/clients"] = (p, c) => { c.Response.StatusCode = 200; c.Response.Headers["cache-control"] = "no-cache, must-revalidate"; c.Response.Content = GetClients(c, c.Request.QueryString); }; // DELETE /clients/[address or user] close a client connection Delete["/clients/{id}"] = (p, c) => { CloseClient(c, (string)p["id"]); c.Response.StatusCode = 200; c.Response.Headers["cache-control"] = "no-cache, must-revalidate"; }; // GET /tasks get all long running tasks Get["/tasks"] = (p, c) => { c.Response.StatusCode = 200; c.Response.Headers["cache-control"] = "no-cache, must-revalidate"; c.Response.Content = GetTasks(c.Request.QueryString); }; }
public ManageService(PriorityTaskScheduler scheduler) { this.scheduler = scheduler; Rights = new DummyManageRights(); }
public VideoEncoderService(PriorityTaskScheduler scheduler) { this.scheduler = scheduler; Get["/{id}"] = (p, c) => { var id = (string)p["id"]; VideoEncoder encoder = null; lock (instanceLock) { if (runningEncodersById.ContainsKey(id)) { encoder = runningEncodersById[id]; } } if (encoder != null) { c.Response.StatusCode = 200; c.Response.Content = encoder.ToJson(); } }; PostAsync["/{id}/progress"] = async(p, c) => { var values = new Dictionary <string, string>(); string id = (string)p["id"]; VideoEncoder encoder = null; lock (instanceLock) { if (runningEncodersById.ContainsKey(id)) { encoder = runningEncodersById[id]; } } if (encoder == null) { return; } using (StreamReader sr = new StreamReader(c.Request.InputStream)) { var end = false; while (!sr.EndOfStream && !end) { var line = await sr.ReadLineAsync(); var pos = line.IndexOf('='); if (pos > 0) { var cmd = line.Substring(0, pos); var value = line.Substring(pos + 1); if (cmd == "progress") { end |= value == "end"; // get the total micro secondes position in the video if (values.ContainsKey("out_time_ms") && long.TryParse(values["out_time_ms"], out long outTimeMs)) { encoder.TimeProgress = ((double)outTimeMs) / 1000000.0d; } // get current frame position in the video if (values.ContainsKey("frame") && long.TryParse(values["frame"], out long frame)) { encoder.Frame = frame; } values.Clear(); } else { values[cmd] = value; } } } } }; }
public ScheduledTask(Task task, PriorityTaskScheduler scheduler) { Task = task ?? throw new ArgumentNullException(nameof(task)); Scheduler = scheduler ?? throw new ArgumentNullException(nameof(scheduler)); }