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
-id => 'client1',
-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
.
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().
- /run
-
Calls the worker's run() method. This is method should be overloaded by subclasses of
D::P::Worker
to perform the real job that is to be distributed on the cluster. - /reset
-
Calls the worker's reset_result() method to flush its list of results.
- /quit
-
Exits the program.
- /get_result
-
Returns the results from the worker. The results are preceeded with the line
/begin_results
and followed by the wordok
. Each result line gets prefixed with the client's id() and a tab character ("\t
", ASCII 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.
Each line is first
chomp
ed andsplit
on whitespace, and an action is performed depending on the first word on the line. See the list of known commands above. - 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 268:
Non-ASCII character seen before =encoding in 'Cédric'. Assuming CP1252