a790ba8d2543af7f0f67e623f1e061224e16dc33
[scpubgit/Object-Remote.git] / lib / Object / Remote / Node.pm
1 package Object::Remote::Node;
2
3 use strictures 1;
4 use Object::Remote::Connector::STDIO;
5 use Object::Remote::Logging qw(:log :dlog);
6 use Object::Remote::WatchDog;
7 use Object::Remote;
8 use CPS::Future;
9
10 sub run {
11   my ($class, %args) = @_; 
12   log_trace { "run() has been invoked on remote node" };
13     
14   my $c = Object::Remote::Connector::STDIO->new->connect;
15   
16   $c->register_class_call_handler;
17
18   my $loop = Object::Remote->current_loop;
19   
20   $c->on_close->on_ready(sub { 
21     log_info { "Node connection with call handler has closed" };
22     $loop->want_stop 
23   });
24
25   Dlog_trace { "Node is sending 'Shere' to $_" } $c->send_to_fh;
26   print { $c->send_to_fh } "Shere\n";
27
28   log_debug { "Node is going to start the run loop" };
29   if ($args{watchdog_timeout}) {
30     Object::Remote::WatchDog->new(timeout => $args{watchdog_timeout});
31   } else {
32     #reset connection watchdog from the fatnode
33     alarm(0);
34   }
35   $loop->want_run;
36   $loop->run_while_wanted;
37   log_debug { "Run loop invocation in node has completed" };
38 }
39
40 1;