… | |
… | |
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 | |
94 | Nodes are either public (have one or more listening ports) or private |
94 | Nodes 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 |
96 | currently. |
96 | currently. |
97 | |
97 | |
98 | =item node ID - C<[A-Z_][a-zA-Z0-9_\-.:]*> |
98 | =item node ID - C<[A-Za-z0-9_\-.:]*> |
99 | |
99 | |
100 | A node ID is a string that uniquely identifies the node within a |
100 | A node ID is a string that uniquely identifies the node within a |
101 | network. Depending on the configuration used, node IDs can look like a |
101 | network. Depending on the configuration used, node IDs can look like a |
102 | hostname, a hostname and a port, or a random string. AnyEvent::MP itself |
102 | hostname, a hostname and a port, or a random string. AnyEvent::MP itself |
103 | doesn't interpret node IDs in any way. |
103 | doesn't interpret node IDs in any way. |
… | |
… | |
155 | |
155 | |
156 | use AE (); |
156 | use AE (); |
157 | |
157 | |
158 | use base "Exporter"; |
158 | use base "Exporter"; |
159 | |
159 | |
160 | our $VERSION = 1.26; |
160 | our $VERSION = 1.29; |
161 | |
161 | |
162 | our @EXPORT = qw( |
162 | our @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 |
… | |
… | |
495 | Remembers C<$SELF> and creates a closure out of the BLOCK. When the |
495 | Remembers C<$SELF> and creates a closure out of the BLOCK. When the |
496 | closure is executed, sets up the environment in the same way as in C<rcv> |
496 | closure is executed, sets up the environment in the same way as in C<rcv> |
497 | callbacks, i.e. runtime errors will cause the port to get C<kil>ed. |
497 | callbacks, i.e. runtime errors will cause the port to get C<kil>ed. |
498 | |
498 | |
499 | The effect is basically as if it returned C<< sub { peval $SELF, sub { |
499 | The effect is basically as if it returned C<< sub { peval $SELF, sub { |
500 | BLOCK } } >>. |
500 | BLOCK }, @_ } >>. |
501 | |
501 | |
502 | This is useful when you register callbacks from C<rcv> callbacks: |
502 | This is useful when you register callbacks from C<rcv> callbacks: |
503 | |
503 | |
504 | rcv delayed_reply => sub { |
504 | rcv delayed_reply => sub { |
505 | my ($delay, @reply) = @_; |
505 | my ($delay, @reply) = @_; |
… | |
… | |
882 | |
882 | |
883 | Erlang implements few guarantees on messages delivery - messages can get |
883 | Erlang implements few guarantees on messages delivery - messages can get |
884 | lost without any of the processes realising it (i.e. you send messages a, |
884 | lost without any of the processes realising it (i.e. you send messages a, |
885 | b, and c, and the other side only receives messages a and c). |
885 | b, and c, and the other side only receives messages a and c). |
886 | |
886 | |
887 | AEMP guarantees correct ordering, and the guarantee that after one message |
887 | AEMP guarantees (modulo hardware errors) correct ordering, and the |
888 | is lost, all following ones sent to the same port are lost as well, until |
888 | guarantee that after one message is lost, all following ones sent to the |
889 | monitoring raises an error, so there are no silent "holes" in the message |
889 | same port are lost as well, until monitoring raises an error, so there are |
890 | sequence. |
890 | no silent "holes" in the message sequence. |
891 | |
891 | |
892 | =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. |
893 | |
893 | |
894 | In Erlang it is quite likely that a node that restarts reuses a process ID |
894 | In Erlang it is quite likely that a node that restarts reuses a process ID |
895 | known to other nodes for a completely different process, causing messages |
895 | known to other nodes for a completely different process, causing messages |
… | |
… | |
952 | overhead, as well as having to keep a proxy object everywhere. |
952 | overhead, as well as having to keep a proxy object everywhere. |
953 | |
953 | |
954 | Strings can easily be printed, easily serialised etc. and need no special |
954 | Strings can easily be printed, easily serialised etc. and need no special |
955 | procedures to be "valid". |
955 | procedures to be "valid". |
956 | |
956 | |
957 | And as a result, a miniport consists of a single closure stored in a |
957 | And as a result, a port with just a default receiver consists of a single |
958 | global hash - it can't become much cheaper. |
958 | code reference stored in a global hash - it can't become much cheaper. |
959 | |
959 | |
960 | =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? |
961 | |
961 | |
962 | In fact, any AnyEvent::MP node will happily accept Storable as framing |
962 | In fact, any AnyEvent::MP node will happily accept Storable as framing |
963 | format, but currently there is no way to make a node use Storable by |
963 | format, but currently there is no way to make a node use Storable by |
… | |
… | |
979 | |
979 | |
980 | L<AnyEvent::MP::Intro> - a gentle introduction. |
980 | L<AnyEvent::MP::Intro> - a gentle introduction. |
981 | |
981 | |
982 | L<AnyEvent::MP::Kernel> - more, lower-level, stuff. |
982 | L<AnyEvent::MP::Kernel> - more, lower-level, stuff. |
983 | |
983 | |
984 | L<AnyEvent::MP::Global> - network maintainance and port groups, to find |
984 | L<AnyEvent::MP::Global> - network maintenance and port groups, to find |
985 | your applications. |
985 | your applications. |
986 | |
986 | |
987 | L<AnyEvent::MP::DataConn> - establish data connections between nodes. |
987 | L<AnyEvent::MP::DataConn> - establish data connections between nodes. |
988 | |
988 | |
989 | L<AnyEvent::MP::LogCatcher> - simple service to display log messages from |
989 | L<AnyEvent::MP::LogCatcher> - simple service to display log messages from |