NAME
Distributed::Process::Client - a class to run a client in a Distributed::Process cluster.
SYNOPSIS
use Distributed::Process;
use Distributed::Process::Client;
use MyTest;
$c = new Distributed::Process::Client
-worker_class => 'MyTest',
-port => 8147,
-host => 'localhost',
;
$c->run();
DESCRIPTION
This class handles the client part of the cluster. It derives its handling of the network connection from Distributed::Process::Interface
, simply overloading command_handlers() to handle more commands.
A D::P::Worker
object must be associated to the Client, by means of the worker() or worker_class() methods, so that the client can run methods from it when requested to do so by the server.
Commands
A D::P::Client
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 as a list of words, i.e., the original command string is splitted on whitespace.
- /run NAME, LIST
-
Calls the method called NAME with LIST as arguments.
- /reset
-
Calls the worker's reset_result() method to flush its list of results.
- /time NAME, LIST
-
Calls the worker's time() method, resulting in calling the worker's method called NAME with LIST as arguments while measuring its run time. The time is appended to the result() (see Distributed::Process::BaseWorker).
- /synchro TOKEN
-
Returns the same line as the one received (i.e.,
/run TOKEN
) after a small delay. The delay seems necessary to avoid the server receiving replies to a/synchro
message before it starts expecting them. - /quit
-
Exits the program.
- /get_result
-
Returns the results from the worker. The results are preceded with the line
/begin_results
and followed by the wordok
. Each result line gets prefixed with the client's id() and a tab character (0x09).The worker itself returns its result line prefixed with a timestamp. An example of output could thus be:
/begin_results client1 20050316-152519 Running method __test1 client1 20050316-152522 Time for running __test1: 2.1234 seconds ok
Methods
- run
-
Reads line coming in from handle() and processes them using the handle_line() method inherited from
D::P::Interface
.Each line is first
chomp
ed andsplit
on whitespace. The words are sent as a list to handle_line(). When a regular expression from the list returned by command_handlers() matches the first word, the corresponding callback is invoked with the full list of words as arguments.The callbacks are expected to return a list of strings, which will be immediately sent back to the server. If they return an empty list, the single line "ok" is sent instead.
Normally, callbacks should return an empty list and store their results using the result() method, which makes it possible for the server to retrieve the results later, when the work is done.
- handle
- in_handle
- out_handle
-
These three are synonyms for the handle() method that returns the
IO::Socket::INET
object implementing the connection to the server.The first call to handle() creates this object, effectively establishing the connection to port port() on host host().
- worker OBJECT
- worker
-
Sets or returns the current worker object. OBJECT should be an instance of
Distributed::Process::Worker
or, most probably, of a subclass of it. If OBJECT is not provided, the fist call to worker() will instanciate an object of the class returned by worker_class(), passing to its constructor the arguments returned by worker_args(). - 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.
- id
-
A unique identifier for the client. This will be prepended to the lines sent back to the server as a response to the
/get_result
command. The process id ($$
) is returned if id() is not set. - worker_class
-
The name of the class to use when instanciating a
D::P::Worker
object. - host
- port
-
The host and port where to connect to the server.
SEE ALSO
Distributed::Process::Interface, Distributed::Process::Worker,
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.
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 286:
Non-ASCII character seen before =encoding in 'Cédric'. Assuming CP1252