… | |
… | |
185 | use common::sense; |
185 | use common::sense; |
186 | |
186 | |
187 | use Carp (); |
187 | use Carp (); |
188 | |
188 | |
189 | use AE (); |
189 | use AE (); |
|
|
190 | use Guard (); |
190 | |
191 | |
191 | use base "Exporter"; |
192 | use base "Exporter"; |
192 | |
193 | |
193 | our $VERSION = $AnyEvent::MP::Config::VERSION; |
194 | our $VERSION = $AnyEvent::MP::Config::VERSION; |
194 | |
195 | |
195 | our @EXPORT = qw( |
196 | our @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 | |
202 | our $SELF; |
204 | our $SELF; |
203 | |
205 | |
204 | sub _self_die() { |
206 | sub _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 | |
682 | Monitors the given C<$port> and keeps the passed references. When the port |
684 | Monitors 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 | |
|
|
884 | AnyEvent::MP comes with a simple distributed database. The database will |
|
|
885 | be mirrored asynchronously at all global nodes. Other nodes bind to one of |
|
|
886 | the global nodes for their needs. |
|
|
887 | |
|
|
888 | The database consists of a two-level hash - a hash contains a hash which |
|
|
889 | contains values. |
|
|
890 | |
|
|
891 | The top level hash key is called "family", and the second-level hash key |
|
|
892 | is simply called "key". |
|
|
893 | |
|
|
894 | The family and key must be alphanumeric ASCII strings, i.e. start |
|
|
895 | with 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 | |
|
|
898 | As the family namespaceis global, it is recommended to prefix family names |
|
|
899 | with the name of the application or module using it. |
|
|
900 | |
|
|
901 | The values should preferably be strings, but other perl scalars should |
|
|
902 | work as well (such as arrays and hashes). |
|
|
903 | |
|
|
904 | Every database entry is owned by one node - adding the same family/key |
|
|
905 | combination on multiple nodes will not cause discomfort for AnyEvent::MP, |
|
|
906 | but the result might be nondeterministic, i.e. the key might have |
|
|
907 | different values on different nodes. |
|
|
908 | |
|
|
909 | =item db_set $family => $key => $value |
|
|
910 | |
|
|
911 | Sets (or replaces) a key to the database. |
|
|
912 | |
|
|
913 | =item db_del $family => $key |
|
|
914 | |
|
|
915 | Deletes a key from the database. |
|
|
916 | |
|
|
917 | =item $guard = db_reg $family => $key [=> $value] |
|
|
918 | |
|
|
919 | Sets the key on the database and returns a guard. When the guard is |
|
|
920 | destroyed, the key is deleted from the database. If C<$value> is missing, |
|
|
921 | then 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 | |
882 | AnyEvent::MP got lots of its ideas from distributed Erlang (Erlang node |
929 | AnyEvent::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 |
884 | programming techniques employed by Erlang apply to AnyEvent::MP. Here is a |
931 | programming techniques employed by Erlang apply to AnyEvent::MP. Here is a |