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.123 by root, Thu Mar 1 19:37:59 2012 UTC vs.
Revision 1.124 by root, Sat Mar 3 11:38:43 2012 UTC

185use common::sense; 185use common::sense;
186 186
187use Carp (); 187use Carp ();
188 188
189use AE (); 189use AE ();
190use Guard ();
190 191
191use base "Exporter"; 192use base "Exporter";
192 193
193our $VERSION = $AnyEvent::MP::Config::VERSION; 194our $VERSION = $AnyEvent::MP::Config::VERSION;
194 195
195our @EXPORT = qw( 196our @EXPORT = qw(
196 NODE $NODE *SELF node_of after 197 NODE $NODE *SELF node_of after
197 configure 198 configure
198 snd rcv mon mon_guard kil psub peval spawn cal 199 snd rcv mon mon_guard kil psub peval spawn cal
199 port 200 port
201 db_set db_del db_reg
200); 202);
201 203
202our $SELF; 204our $SELF;
203 205
204sub _self_die() { 206sub _self_die() {
672 } 674 }
673 675
674 $node->monitor ($port, $cb); 676 $node->monitor ($port, $cb);
675 677
676 defined wantarray 678 defined wantarray
677 and ($cb += 0, AnyEvent::Util::guard { $node->unmonitor ($port, $cb) }) 679 and ($cb += 0, Guard::guard { $node->unmonitor ($port, $cb) })
678} 680}
679 681
680=item $guard = mon_guard $port, $ref, $ref... 682=item $guard = mon_guard $port, $ref, $ref...
681 683
682Monitors the given C<$port> and keeps the passed references. When the port 684Monitors the given C<$port> and keeps the passed references. When the port
875 $port 877 $port
876} 878}
877 879
878=back 880=back
879 881
882=head1 DISTRIBUTED DATABASE
883
884AnyEvent::MP comes with a simple distributed database. The database will
885be mirrored asynchronously at all global nodes. Other nodes bind to one of
886the global nodes for their needs.
887
888The database consists of a two-level hash - a hash contains a hash which
889contains values.
890
891The top level hash key is called "family", and the second-level hash key
892is simply called "key".
893
894The family and key must be alphanumeric ASCII strings, i.e. start
895with a letter and consist of letters, digits, underscores and colons
896(C<[A-Za-z][A-Za-z0-9_:]*>, pretty much like Perl module names.
897
898As the family namespaceis global, it is recommended to prefix family names
899with the name of the application or module using it.
900
901The values should preferably be strings, but other perl scalars should
902work as well (such as arrays and hashes).
903
904Every database entry is owned by one node - adding the same family/key
905combination on multiple nodes will not cause discomfort for AnyEvent::MP,
906but the result might be nondeterministic, i.e. the key might have
907different values on different nodes.
908
909=item db_set $family => $key => $value
910
911Sets (or replaces) a key to the database.
912
913=item db_del $family => $key
914
915Deletes a key from the database.
916
917=item $guard = db_reg $family => $key [=> $value]
918
919Sets the key on the database and returns a guard. When the guard is
920destroyed, the key is deleted from the database. If C<$value> is missing,
921then C<undef> is used.
922
923=cut
924
925=back
926
880=head1 AnyEvent::MP vs. Distributed Erlang 927=head1 AnyEvent::MP vs. Distributed Erlang
881 928
882AnyEvent::MP got lots of its ideas from distributed Erlang (Erlang node 929AnyEvent::MP got lots of its ideas from distributed Erlang (Erlang node
883== aemp node, Erlang process == aemp port), so many of the documents and 930== aemp node, Erlang process == aemp port), so many of the documents and
884programming techniques employed by Erlang apply to AnyEvent::MP. Here is a 931programming techniques employed by Erlang apply to AnyEvent::MP. Here is a

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines