1 package Tak::ConnectorService;
7 use Tak::ConnectionService;
11 with 'Tak::Role::Service';
13 has connections => (is => 'ro', default => sub { Tak::Router->new });
15 has ssh => (is => 'ro', default => sub { {} });
18 my ($self, $on, %args) = @_;
19 my $log_level = $args{log_level}||'info';
20 my ($kid_in, $kid_out, $kid_pid) = $self->_open($on, $log_level);
21 $kid_in->print(io('maint/mk-fat |')->all, "__END__\n");
23 die [ failure => "Garbled response from child: $up" ]
25 my $connection = Tak::ConnectionService->new(
26 read_fh => $kid_out, write_fh => $kid_in,
27 listening_service => Tak::Router->new
29 my $client = Tak::Client->new(service => $connection);
30 # actually, we should register with a monotonic id and
31 # stash the pid elsewhere. but meh for now.
32 my $pid = $client->do(meta => 'pid');
33 my $name = ($on||'|').':'.$pid;
34 my $conn_router = Tak::Router->new;
35 $conn_router->register(local => $connection->receiver->service);
36 $conn_router->register(remote => $connection);
37 $self->connections->register($name, $conn_router);
42 my ($self, $on, @args) = @_;
44 my $kid_pid = IPC::Open2::open2(my $kid_out, my $kid_in, $^X, '-', '-', @args)
45 or die "Couldn't open2 child: $!";
46 return ($kid_in, $kid_out, $kid_pid);
48 my $ssh = $self->ssh->{$on} ||= Net::OpenSSH->new($on);
50 die "Couldn't establish ssh connection: ".$ssh->error;
51 return $ssh->open2('perl','-', $on, @args);
54 sub start_connection_request {
55 my ($self, $req, @payload) = @_;;
56 $self->connections->start_request($req, @payload);
59 sub receive_connection {
60 my ($self, @payload) = @_;
61 $self->connections->receive(@payload);