09 Nov 2013 05:08:58 UTC
- Distribution: Padre
- Module version: 1.00
- Source (raw)
- Browse (raw)
- How to Contribute
- Clone repository
- Testers (31 / 43 / 71)
- KwaliteeBus factor: 3
- % Coverage
- License: perl_5
- Perl: v5.11.0
- Activity24 month
- Download (1.88MB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest version++ed by:16 non-PAUSE usersPLAVEN Peter Lavenderand 46 contributors
- Gabor Szabo
- Aaron Trevena (TEEJAY)
- Adam Kennedy (ADAMK)
- Ahmad Zawawi أحمد محمد زواوي (AZAWAWI)
- Andrew Shitov
- Alexandr Ciornii (CHORNY)
- Amir E. Aharoni - אמיר א. אהרוני
- Blake Willmarth (BLAKEW)
- BlueT - Matthew Lien - 練喆明 (BLUET)
- Breno G. de Oliveira (GARU)
- Brian Cassidy (BRICAS)
- Burak Gürsoy (BURAK)
- Cezary Morga (THEREK)
- Chris Dolan (CHRISDOLAN)
- Claudio Ramirez (NXADM)
- Dirk De Nijs (ddn123456)
- Enrique Nell (ENELL)
- Fayland Lam (FAYLAND)
- Gabriel Vieira (GABRIELMAD)
- Gábor Szabó - גאבור סבו (SZABGAB)
- György Pásztor (GYU)
- Heiko Jansen (HJANSEN)
- Jérôme Quelin (JQUELIN)
- Kaare Rasmussen (KAARE)
- Keedi Kim - 김도형 (KEEDI)
- Kenichi Ishigaki - 石垣憲一 (ISHIGAKI)
- Kevin Dawson (BOWTIE)
- Kjetil Skotheim (KJETIL)
- Marcela Mašláňová (mmaslano)
- Marek Roszkowski (EviL)
- Mark Grimes
- Max Maischein (CORION)
- Olivier MenguE<eacute> (DOLMEN)
- Omer Zak - עומר זק
- Paco Alguacil (PacoLinux)
- Patrick Donelan (PDONELAN)
- Paweł Murias (PMURIAS)
- Petar Shangov (PSHANGOV)
- Peter Lavender (PLAVEN)
- Ryan Niebur (RSN)
- Sebastian Willing (SEWI)
- Shlomi Fish - שלומי פיש (SHLOMIF)
- Simone Blandino (SBLANDIN)
- Steffen Müller (TSEE)
- Zeno Gantner (ZENOG)
- Chuanren Wu
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
- COPYRIGHT & LICENSE
Padre::TaskManager - Padre Background Task and Service Manager
The Padre Task Manager is responsible for scheduling, queueing and executing all operations that do not occur in the main application thead.
While there is rarely any need for code elsewhere in Padre or a plugin to make calls to this API, documentation is included for maintenance purposes.
It spawns and manages a pool of workers which act as containers for the execution of standalone serialisable tasks. This execution model is based loosely on the CPAN Process API, and involves the parent process creating Padre::Task objects representing the work to do. These tasks are serialised to a bytestream, passed down a shared queue to an appropriate worker, deserialised back into an object, executed, and then reserialised for transmission back to the parent thread.
Tasks operate on a shared-nothing basis. Each worker is required to reload any modules needed by the task, and the task cannot access any of the data structures. To compensate for these limits, tasks are able to send messages back and forth between the instance of the task object in the parent and the instance of the same task in the child.
Using this messaging channel, a task object in the child can send status message or incremental results up to the parent, and the task object in the parent can make changes to the GUI based on these messages.
The same messaging channel allows a background task to be cancelled elegantly by the parent, although support for the "cancel" message is voluntary on the part of the background task.
The main difference between a task and a service is that a service will be allocated a private, unused and dedicated worker that has never been used by a task. Further, workers allocated to services will also not be counted against the "maximum workers" limit.
my $manager = Padre::TaskManager->new( conduit => $message_conduit, );
newconstructor creates a new Task Manager instance. While it is theoretically possible to create more than one instance, in practice this is never likely to occur.
The constructor has a single compulsory parameter, which is an object that implements the "message conduit" role Padre::Wx::Role::Conduit.
Because the message conduit is provided to the constructor, the Task Manager itself is able to function with no Wx-specific code whatsoever. This simplifies implementation, allows sophisticated test rigs to be created, and makes it easier for us to spin off the Task Manager as a some notional standalone CPAN module.
activeaccessor returns true if the task manager is currently running, or false if not. Generally task manager startup will occur relatively early in the Padre startup sequence, and task manager shutdown will occur relatively early in the shutdown sequence (to prevent accidental task execution during shutdown).
maximumaccessor returns the maximum quantity of worker threads that the task manager will use for running ordinary finite-length tasks. Once the number of active workers reaches the
maximumlimit, futher tasks will be pushed onto a queue to wait for a free worker.
startmethod bootstraps the task manager, creating the master thread.
stopmethod shuts down the task manager, signalling active workers that they should do an elegant shutdown.
schedulemethod is used to give a task to the task manager and indicate it should be run as soon as possible.
This may be immediately (with the task sent to a worker before the method returns) or it may be delayed until some time in the future if all workers are busy.
As a convenience, this method returns true if the task could be dispatched immediately, or false if it was queued for future execution.
$manager->cancelled( $owner );
cancelledmethod is used with the "task ownership" feature of the Padre::Task 3.0 API to signal tasks running in the background that were created by a particular object that they should voluntarily abort as their results are no longer wanted.
my $worker = $manager->start_worker;
start_workerstarts and returns a new registered Padre::TaskWorker object, ready to execute a task or service in.
You generally should never need to call this method from outside Padre::TaskManager.
stop_workermethod shuts down a single worker, which (unfortunately) at this time is indicated via the internal index position in the workers array.
kill_workermethod forcefully and immediately terminates a worker, and like
stop_workerthe worker to kill is indicated by the internal index position within the workers array.
This method is not yet in use, the Task Manager does not current have the ability to forcefully terminate workers.
runmethod tells the Task Manager to sweep the queue of pending tasks and dispatch as many as possible to worker threads.
Generally you should never need to call this method directly, as it will be called whenever you schedule a task or when a worker becomes available.
Returns true if all pending tasks were dispatched, or false if any tasks remain on the queue.
my $ok = $manager->good_task($task);
good_taskmethod takes a Padre::Task object and determines if the task can be executed, given the resources available to the task manager.
Returns a Padre::Task object, or
undefif there is no task to execute.
my $worker = $manager->best_worker( $task_object );
best_workermethod is used to find the best worker from the worker pool for the execution of a particular task object.
This method makes use of a number of different strategies for optimising the way in which workers are used, such as maximising worker reuse for the same type of task, and "specialising" workers for particular types of tasks.
If all existing workers are in use this method may also spawn new workers, up to the
maximumworker limit. Without the slave master logic enabled this will result in the editor blocking in the foreground briefly, this is something we can live with until the slave master feature is working again.
Returns a Padre::TaskWorker object, or
undefif there is no worker in which the task can be run.
$manager->on_signal( \@message );
on_signalmethod is called from the conduit object and acts as a central distribution mechanism for messages coming from all child workers.
Messages arrive as a list of elements in an
ARRAYwith their first element being the handle identifier of the Padre::TaskHandle for the task.
This "envelope" element is stripped from the front of the message, and the remainder of the message is passed down into the handle (and the task within the handle).
Certain special messages, such as "STARTED" and "STOPPED" are emitted not by the task but by the surrounding handle, and indicate to the task manager the state of the child worker.
Copyright 2008-2013 The Padre development team as listed in Padre.pm.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.