ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-MP/MP.pm
(Generate patch)

Comparing AnyEvent-MP/MP.pm (file contents):
Revision 1.130 by root, Fri Mar 9 17:05:26 2012 UTC vs.
Revision 1.132 by root, Sat Mar 10 20:34:11 2012 UTC

398 398
399=cut 399=cut
400 400
401sub rcv($@); 401sub rcv($@);
402 402
403sub _kilme { 403my $KILME = sub {
404 die "received message on port without callback"; 404 die "received message on port without callback";
405} 405};
406 406
407sub port(;&) { 407sub port(;&) {
408 my $id = $UNIQ . ++$ID; 408 my $id = $UNIQ . ++$ID;
409 my $port = "$NODE#$id"; 409 my $port = "$NODE#$id";
410 410
411 rcv $port, shift || \&_kilme; 411 rcv $port, shift || $KILME;
412 412
413 $port 413 $port
414} 414}
415 415
416=item rcv $local_port, $callback->(@msg) 416=item rcv $local_port, $callback->(@msg)
894=back 894=back
895 895
896=head1 DISTRIBUTED DATABASE 896=head1 DISTRIBUTED DATABASE
897 897
898AnyEvent::MP comes with a simple distributed database. The database will 898AnyEvent::MP comes with a simple distributed database. The database will
899be mirrored asynchronously at all global nodes. Other nodes bind to one of 899be mirrored asynchronously on all global nodes. Other nodes bind to one
900the global nodes for their needs. 900of the global nodes for their needs. Every node has a "local database"
901which contains all the values that are set locally. All local databases
902are merged together to form the global database, which can be queried.
901 903
902The database consists of a two-level hash - a hash contains a hash which 904The database structure is that of a two-level hash - the database hash
903contains values. 905contains hashes which contain values, similarly to a perl hash of hashes,
906i.e.:
907
908 $DATABASE{$family}{$subkey} = $value
904 909
905The top level hash key is called "family", and the second-level hash key 910The top level hash key is called "family", and the second-level hash key
906is called "subkey" or simply "key". 911is called "subkey" or simply "key".
907 912
908The family must be alphanumeric, i.e. start with a letter and consist 913The family must be alphanumeric, i.e. start with a letter and consist
913with the name of the application or module using it. 918with the name of the application or module using it.
914 919
915The subkeys must be non-empty strings, with no further restrictions. 920The subkeys must be non-empty strings, with no further restrictions.
916 921
917The values should preferably be strings, but other perl scalars should 922The values should preferably be strings, but other perl scalars should
918work as well (such as undef, arrays and hashes). 923work as well (such as C<undef>, arrays and hashes).
919 924
920Every database entry is owned by one node - adding the same family/subkey 925Every database entry is owned by one node - adding the same family/subkey
921combination on multiple nodes will not cause discomfort for AnyEvent::MP, 926combination on multiple nodes will not cause discomfort for AnyEvent::MP,
922but the result might be nondeterministic, i.e. the key might have 927but the result might be nondeterministic, i.e. the key might have
923different values on different nodes. 928different values on different nodes.
985Creates a monitor on the given database family. Each time a key is set 990Creates a monitor on the given database family. Each time a key is set
986or or is deleted the callback is called with a hash containing the 991or or is deleted the callback is called with a hash containing the
987database family and three lists of added, changed and deleted subkeys, 992database family and three lists of added, changed and deleted subkeys,
988respectively. If no keys have changed then the array reference might be 993respectively. If no keys have changed then the array reference might be
989C<undef> or even missing. 994C<undef> or even missing.
995
996If not called in void context, a guard object is returned that, when
997destroyed, stops the monitor.
990 998
991The family hash reference and the key arrays belong to AnyEvent::MP and 999The family hash reference and the key arrays belong to AnyEvent::MP and
992B<must not be modified or stored> by the callback. When in doubt, make a 1000B<must not be modified or stored> by the callback. When in doubt, make a
993copy. 1001copy.
994 1002

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines