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.106 by root, Wed Dec 9 14:00:49 2009 UTC vs.
Revision 1.117 by root, Wed Oct 27 06:32:39 2010 UTC

30 rcv $port, pong => sub { warn "pong received\n" }; 30 rcv $port, pong => sub { warn "pong received\n" };
31 31
32 # create a port on another node 32 # create a port on another node
33 my $port = spawn $node, $initfunc, @initdata; 33 my $port = spawn $node, $initfunc, @initdata;
34 34
35 # destroy a prot again 35 # destroy a port again
36 kil $port; # "normal" kill 36 kil $port; # "normal" kill
37 kil $port, my_error => "everything is broken"; # error kill 37 kil $port, my_error => "everything is broken"; # error kill
38 38
39 # monitoring 39 # monitoring
40 mon $localport, $cb->(@msg) # callback is invoked on death 40 mon $localport, $cb->(@msg) # callback is invoked on death
93 93
94Nodes are either public (have one or more listening ports) or private 94Nodes are either public (have one or more listening ports) or private
95(no listening ports). Private nodes cannot talk to other private nodes 95(no listening ports). Private nodes cannot talk to other private nodes
96currently. 96currently.
97 97
98=item node ID - C<[A-Z_][a-zA-Z0-9_\-.:]*> 98=item node ID - C<[A-Za-z0-9_\-.:]*>
99 99
100A node ID is a string that uniquely identifies the node within a 100A node ID is a string that uniquely identifies the node within a
101network. Depending on the configuration used, node IDs can look like a 101network. Depending on the configuration used, node IDs can look like a
102hostname, a hostname and a port, or a random string. AnyEvent::MP itself 102hostname, a hostname and a port, or a random string. AnyEvent::MP itself
103doesn't interpret node IDs in any way. 103doesn't interpret node IDs in any way.
155 155
156use AE (); 156use AE ();
157 157
158use base "Exporter"; 158use base "Exporter";
159 159
160our $VERSION = 1.24; 160our $VERSION = 1.29;
161 161
162our @EXPORT = qw( 162our @EXPORT = qw(
163 NODE $NODE *SELF node_of after 163 NODE $NODE *SELF node_of after
164 configure 164 configure
165 snd rcv mon mon_guard kil psub peval spawn cal 165 snd rcv mon mon_guard kil psub peval spawn cal
190 190
191Before a node can talk to other nodes on the network (i.e. enter 191Before a node can talk to other nodes on the network (i.e. enter
192"distributed mode") it has to configure itself - the minimum a node needs 192"distributed mode") it has to configure itself - the minimum a node needs
193to know is its own name, and optionally it should know the addresses of 193to know is its own name, and optionally it should know the addresses of
194some other nodes in the network to discover other nodes. 194some other nodes in the network to discover other nodes.
195
196The key/value pairs are basically the same ones as documented for the
197F<aemp> command line utility (sans the set/del prefix).
195 198
196This function configures a node - it must be called exactly once (or 199This function configures a node - it must be called exactly once (or
197never) before calling other AnyEvent::MP functions. 200never) before calling other AnyEvent::MP functions.
198 201
199=over 4 202=over 4
492Remembers C<$SELF> and creates a closure out of the BLOCK. When the 495Remembers C<$SELF> and creates a closure out of the BLOCK. When the
493closure is executed, sets up the environment in the same way as in C<rcv> 496closure is executed, sets up the environment in the same way as in C<rcv>
494callbacks, i.e. runtime errors will cause the port to get C<kil>ed. 497callbacks, i.e. runtime errors will cause the port to get C<kil>ed.
495 498
496The effect is basically as if it returned C<< sub { peval $SELF, sub { 499The effect is basically as if it returned C<< sub { peval $SELF, sub {
497BLOCK } } >>. 500BLOCK }, @_ } >>.
498 501
499This is useful when you register callbacks from C<rcv> callbacks: 502This is useful when you register callbacks from C<rcv> callbacks:
500 503
501 rcv delayed_reply => sub { 504 rcv delayed_reply => sub {
502 my ($delay, @reply) = @_; 505 my ($delay, @reply) = @_;
650 653
651=item kil $port[, @reason] 654=item kil $port[, @reason]
652 655
653Kill the specified port with the given C<@reason>. 656Kill the specified port with the given C<@reason>.
654 657
655If no C<@reason> is specified, then the port is killed "normally" (ports 658If no C<@reason> is specified, then the port is killed "normally" -
656monitoring other ports will not necessarily die because a port dies 659monitor callback will be invoked, but the kil will not cause linked ports
657"normally"). 660(C<mon $mport, $lport> form) to get killed.
658 661
659Otherwise, linked ports get killed with the same reason (second form of 662If a C<@reason> is specified, then linked ports (C<mon $mport, $lport>
660C<mon>, see above). 663form) get killed with the same reason.
661 664
662Runtime errors while evaluating C<rcv> callbacks or inside C<psub> blocks 665Runtime errors while evaluating C<rcv> callbacks or inside C<psub> blocks
663will be reported as reason C<< die => $@ >>. 666will be reported as reason C<< die => $@ >>.
664 667
665Transport/communication errors are reported as C<< transport_error => 668Transport/communication errors are reported as C<< transport_error =>
879 882
880Erlang implements few guarantees on messages delivery - messages can get 883Erlang implements few guarantees on messages delivery - messages can get
881lost without any of the processes realising it (i.e. you send messages a, 884lost without any of the processes realising it (i.e. you send messages a,
882b, and c, and the other side only receives messages a and c). 885b, and c, and the other side only receives messages a and c).
883 886
884AEMP guarantees correct ordering, and the guarantee that after one message 887AEMP guarantees (modulo hardware errors) correct ordering, and the
885is lost, all following ones sent to the same port are lost as well, until 888guarantee that after one message is lost, all following ones sent to the
886monitoring raises an error, so there are no silent "holes" in the message 889same port are lost as well, until monitoring raises an error, so there are
887sequence. 890no silent "holes" in the message sequence.
888 891
889=item * Erlang can send messages to the wrong port, AEMP does not. 892=item * Erlang can send messages to the wrong port, AEMP does not.
890 893
891In Erlang it is quite likely that a node that restarts reuses a process ID 894In Erlang it is quite likely that a node that restarts reuses a process ID
892known to other nodes for a completely different process, causing messages 895known to other nodes for a completely different process, causing messages
949overhead, as well as having to keep a proxy object everywhere. 952overhead, as well as having to keep a proxy object everywhere.
950 953
951Strings can easily be printed, easily serialised etc. and need no special 954Strings can easily be printed, easily serialised etc. and need no special
952procedures to be "valid". 955procedures to be "valid".
953 956
954And as a result, a miniport consists of a single closure stored in a 957And as a result, a port with just a default receiver consists of a single
955global hash - it can't become much cheaper. 958code reference stored in a global hash - it can't become much cheaper.
956 959
957=item Why favour JSON, why not a real serialising format such as Storable? 960=item Why favour JSON, why not a real serialising format such as Storable?
958 961
959In fact, any AnyEvent::MP node will happily accept Storable as framing 962In fact, any AnyEvent::MP node will happily accept Storable as framing
960format, but currently there is no way to make a node use Storable by 963format, but currently there is no way to make a node use Storable by
976 979
977L<AnyEvent::MP::Intro> - a gentle introduction. 980L<AnyEvent::MP::Intro> - a gentle introduction.
978 981
979L<AnyEvent::MP::Kernel> - more, lower-level, stuff. 982L<AnyEvent::MP::Kernel> - more, lower-level, stuff.
980 983
981L<AnyEvent::MP::Global> - network maintainance and port groups, to find 984L<AnyEvent::MP::Global> - network maintenance and port groups, to find
982your applications. 985your applications.
983 986
984L<AnyEvent::MP::DataConn> - establish data connections between nodes. 987L<AnyEvent::MP::DataConn> - establish data connections between nodes.
985 988
986L<AnyEvent::MP::LogCatcher> - simple service to display log messages from 989L<AnyEvent::MP::LogCatcher> - simple service to display log messages from

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines