Commit | Line | Data |
eee9a548 |
1 | package Object::Remote::Node; |
2 | |
3 | use strictures 1; |
4 | use Object::Remote::Connector::STDIO; |
07105aca |
5 | use Object::Remote::Logging qw(:log :dlog); |
69aaad21 |
6 | use Object::Remote::WatchDog; |
eee9a548 |
7 | use Object::Remote; |
8 | use CPS::Future; |
9 | |
10 | sub run { |
69aaad21 |
11 | my ($class, %args) = @_; |
07105aca |
12 | log_trace { "run() has been invoked on remote node" }; |
2dc23780 |
13 | |
eee9a548 |
14 | my $c = Object::Remote::Connector::STDIO->new->connect; |
69aaad21 |
15 | |
eee9a548 |
16 | $c->register_class_call_handler; |
17 | |
eee9a548 |
18 | my $loop = Object::Remote->current_loop; |
69aaad21 |
19 | |
2d81cf18 |
20 | $c->on_close->on_ready(sub { |
81444b66 |
21 | log_debug { "Node connection with call handler has closed" }; |
2d81cf18 |
22 | $loop->want_stop |
23 | }); |
eee9a548 |
24 | |
07105aca |
25 | Dlog_trace { "Node is sending 'Shere' to $_" } $c->send_to_fh; |
eee9a548 |
26 | print { $c->send_to_fh } "Shere\n"; |
27 | |
2d81cf18 |
28 | log_debug { "Node is going to start the run loop" }; |
81444b66 |
29 | #TODO the alarm should be reset after the run loop starts |
30 | #at a minimum - the remote side node should probably send |
31 | #a command that clears the alarm in all instances - even |
32 | #if the Object::Remote::Watchdog is not being used |
2dc23780 |
33 | if ($args{watchdog_timeout}) { |
34 | Object::Remote::WatchDog->new(timeout => $args{watchdog_timeout}); |
35 | } else { |
36 | #reset connection watchdog from the fatnode |
37 | alarm(0); |
38 | } |
eee9a548 |
39 | $loop->want_run; |
40 | $loop->run_while_wanted; |
2d81cf18 |
41 | log_debug { "Run loop invocation in node has completed" }; |
eee9a548 |
42 | } |
43 | |
44 | 1; |