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.142 by root, Fri Mar 23 13:44:01 2012 UTC vs.
Revision 1.144 by root, Fri Mar 23 21:16:25 2012 UTC

46 46
47 # execute callbacks in $SELF port context 47 # execute callbacks in $SELF port context
48 my $timer = AE::timer 1, 0, psub { 48 my $timer = AE::timer 1, 0, psub {
49 die "kill the port, delayed"; 49 die "kill the port, delayed";
50 }; 50 };
51
52 # distributed database - modification
53 db_set $family => $subkey [=> $value] # add a subkey
54 db_del $family => $subkey... # delete one or more subkeys
55 db_reg $family => $port [=> $value] # register a port
56
57 # distributed database - queries
58 db_family $family => $cb->(\%familyhash)
59 db_keys $family => $cb->(\@keys)
60 db_values $family => $cb->(\@values)
61
62 # distributed database - monitoring a family
63 db_mon $family => $cb->(\%familyhash, \@added, \@changed, \@deleted)
51 64
52=head1 DESCRIPTION 65=head1 DESCRIPTION
53 66
54This module (-family) implements a simple message passing framework. 67This module (-family) implements a simple message passing framework.
55 68
170 183
171package AnyEvent::MP; 184package AnyEvent::MP;
172 185
173use AnyEvent::MP::Config (); 186use AnyEvent::MP::Config ();
174use AnyEvent::MP::Kernel; 187use AnyEvent::MP::Kernel;
175use AnyEvent::MP::Kernel qw(%NODE %PORT %PORT_DATA $UNIQ $RUNIQ $ID); 188use AnyEvent::MP::Kernel qw(
189 %NODE %PORT %PORT_DATA $UNIQ $RUNIQ $ID
190 add_node load_func
191
192 NODE $NODE
193 configure
194 node_of port_is_local
195 snd kil
196 db_set db_del
197 db_mon db_family db_keys db_values
198);
176 199
177use common::sense; 200use common::sense;
178 201
179use Carp (); 202use Carp ();
180 203
184use base "Exporter"; 207use base "Exporter";
185 208
186our $VERSION = $AnyEvent::MP::Config::VERSION; 209our $VERSION = $AnyEvent::MP::Config::VERSION;
187 210
188our @EXPORT = qw( 211our @EXPORT = qw(
189 NODE $NODE *SELF node_of after 212 NODE $NODE
190 configure 213 configure
214 node_of port_is_local
215 snd kil
216 db_set db_del
217 db_mon db_family db_keys db_values
218
219 *SELF
220
191 snd rcv mon mon_guard kil psub peval spawn cal 221 port rcv mon mon_guard psub peval spawn cal
192 port
193 db_set db_del db_reg 222 db_set db_del db_reg
194 db_mon db_family db_keys db_values 223 db_mon db_family db_keys db_values
224
225 after
195); 226);
196 227
197our $SELF; 228our $SELF;
198 229
199sub _self_die() { 230sub _self_die() {
209a call to C<configure>. 240a call to C<configure>.
210 241
211=item $nodeid = node_of $port 242=item $nodeid = node_of $port
212 243
213Extracts and returns the node ID from a port ID or a node ID. 244Extracts and returns the node ID from a port ID or a node ID.
245
246=item $is_local = port_is_local $port
247
248Returns true iff the port is a local port.
214 249
215=item configure $profile, key => value... 250=item configure $profile, key => value...
216 251
217=item configure key => value... 252=item configure key => value...
218 253
451 486
452sub rcv($@) { 487sub rcv($@) {
453 my $port = shift; 488 my $port = shift;
454 my ($nodeid, $portid) = split /#/, $port, 2; 489 my ($nodeid, $portid) = split /#/, $port, 2;
455 490
456 $NODE{$nodeid} == $NODE{""} 491 $nodeid eq $NODE
457 or Carp::croak "$port: rcv can only be called on local ports, caught"; 492 or Carp::croak "$port: rcv can only be called on local ports, caught";
458 493
459 while (@_) { 494 while (@_) {
460 if (ref $_[0]) { 495 if (ref $_[0]) {
461 if (my $self = $PORT_DATA{$portid}) { 496 if (my $self = $PORT_DATA{$portid}) {
1020=item db_values $family => $cb->(\@values) 1055=item db_values $family => $cb->(\@values)
1021 1056
1022Same as C<db_family>, except it only queries the family I<values> and passes them 1057Same as C<db_family>, except it only queries the family I<values> and passes them
1023as array reference to the callback. 1058as array reference to the callback.
1024 1059
1025=item $guard = db_mon $family => $cb->($familyhash, \@added, \@changed, \@deleted) 1060=item $guard = db_mon $family => $cb->(\%familyhash, \@added, \@changed, \@deleted)
1026 1061
1027Creates a monitor on the given database family. Each time a key is set 1062Creates a monitor on the given database family. Each time a key is set
1028or or is deleted the callback is called with a hash containing the 1063or or is deleted the callback is called with a hash containing the
1029database family and three lists of added, changed and deleted subkeys, 1064database family and three lists of added, changed and deleted subkeys,
1030respectively. If no keys have changed then the array reference might be 1065respectively. If no keys have changed then the array reference might be

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines