NAME
Distributed::Process::Master - a class to conduct the chorus of D::P::Workers, under a D::P::Server.
SYNOPSIS
use Distributed::Process::Master;
use Distributed::Process::Server;
use MyWorker; # subclass of Distributed::Process::Worker
$m = new Distributed::Process::Master
-in_handle => \*STDIN,
-out_handle => \*STDOUT,
-worker_class => 'MyWorker',
;
$s = new Distributed::Process::Server
-master => $m,
-port => 8147,
;
$s->listen();
DESCRIPTION
A D::P::Server
manages a number of D::P::Interface
objects, one of which is a Distributed::Process::Master
. The role of the Master is to handle requests from the user, coming in on its in_handle() (usually, the standard input), and act as an interface between the D::P::MasterWorker
and the D::P::Worker
objects.
Commands
A D::P::Master
object will react on the following commands received on its in_handle(). They are implemented as callbacks returned by the command_handlers() method (see Distributed::Process::Interface). The callbacks are given the full command, i.e., one string.
- /run
-
Invokes the run() method (see below).
- /reset
-
Invokes the reset_result() method on the MasterWorker object.
- /freq NUMBER
-
Sets the frequency() to a new value
- /quit
-
Invokes the quit() method on the
P::D::Server
, effectively shutting down the server and the clients.
Methods
- add_worker WORKER
- add_worker LIST
-
Adds a Worker to the list of known workers. If the first argument is a
D::P::Worker
, use this as the new worker. Otherwise, create a new instance of class worker_class(), passing LIST as arguments to the constructor.In any case, the new worker will be passed the parameters defined by worker_args().
Returns the new worker object.
- remove_worker WORKER
-
Removes a WORKER from the list of known
P::D::Worker
objects. Returns the worker object, orundef
if the worker was not part of the known workers. - workers
-
Returns the list of known
P::D::Worker
objects. In scalar context, returns their number. - worker_ready WORKER
-
Workers call this method from their master's when they have received the
/worker
command. The master takes this opportunity to check whether all the expected workers are connected and whether they are all initialized. - master_worker
-
Returns the
P::D::MasterWorker
object.The first time this method gets called, the
P::D::MasterWorker
class is built as a subclass of the worker_class() and all its double-underscore methods are overloaded, so that invoking such a __method() on the MasterWorker will result in invoking the same method on all the known workers(). - synchro_received LIST
- result_received LIST
-
These methods simply invoke the methods by the same name on the
D::P::MasterWorker
. They are called by aD::P::Worker
that receives some signal and must notify the MasterWorker, but can only do so through the Master itself. - result
-
Returns the list of result() from the
D::P::MasterWorker
. Subclasses can overload this method to filter the results before they are sent to the user. - run
-
Spawns a thread to run the work session. The thread will invoke the run() method on the master_worker() object, get its result(), and print the results to the out_handle().
- worker_class
NAME
- worker_class
-
Returns or sets the class to use when instanciating
P::D::Worker
objects to handle incoming connections.When setting the worker_class(), this method will call the go_remote() method on it to alter its inheritance, and make it a subclass of
Distributed::Process::RemoteWorker
. - worker_args LIST
- worker_args ARRAYREF
- worker_args
-
The list of arguments to pass to the worker_class() constructor. If the first argument is an array ref, it will be dereferenced.
Returns the former list of arguments or the current list when invoked without arguments.
Attributes
The following list describes the attributes of this class. They must only be accessed through their accessors. When called with an argument, the accessor methods set their attribute's value to that argument and return its former value. When called without arguments, they return the current value.
- n_workers
-
The number of
P::D::Worker
that are expected to connect on the server. When enough connections are established, the Master will print a "ready to run" message to warn the user. - frequency
-
The frequency at which a method run by postpone() should be invoked, in Hz.
Suppose you want all the workers to run their __method() 0.25 seconds after one another. You'd write your Worker run() method like this:
sub run { my $self = shift; $self->postpone(__method => 'arguments to __method); }
You'd then set the Master's frequency() to 4, to have it launch 4 calls per second, or 1 call every 0.25 second.
See Distributed::Process::Worker for details.
AUTHOR
Cédric Bouvier, <cbouvi@cpan.org>
BUGS
Please report any bugs or feature requests to bug-distributed-process@rt.cpan.org
, or through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
ACKNOWLEDGEMENTS
COPYRIGHT & LICENSE
Copyright 2005 Cédric Bouvier, All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 401:
Non-ASCII character seen before =encoding in 'Cédric'. Assuming CP1252