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