NAME

IPC::Manager::Service::Peer - Peer connection class for IPC::Manager services

DESCRIPTION

This class represents a connection to another service in the IPC system. It provides methods to send requests and get responses through the parent service's client connection.

SYNOPSIS

my $peer = IPC::Manager::Service::Peer->new(
    name    => 'other-service',
    service => $service_obj,
);

# Check if peer is ready
if ($peer->ready) {
    # Send a request
    my $id = $peer->send_request({action => 'do_something'});

    # Get a response (non-blocking)
    if (my $response = $peer->get_response($id)) {
        ...
    }
}

ATTRIBUTES

name

The name of the peer service (required).

service

The parent service object (required). Must be running in the current process.

child_pid

The pid that fork returned in ipcm_service's parent branch (the "first-fork" pid). Populated only when the peer was produced by ipcm_service spawning a nested service; undef otherwise.

Caveat: this is ipcm_service's own fork pid, not necessarily the pid the service loop ends up running in. See "child_pid" in IPC::Manager::Service::Handle for the full caveat.

METHODS

$bool = $self->ready()
$bool = $self->ready($timeout)

Check if the peer is ready for requests.

With no argument (or undef), ready returns the current state immediately (one-shot, backwards-compatible).

With $timeout, ready blocks until the peer becomes active or the timeout elapses, whichever comes first. A $timeout of 0 blocks indefinitely until the peer is ready.

When the underlying client protocol exposes a peer-change file descriptor (have_handles_for_peer_change, e.g. inotify on the FS-based protocols), ready waits on that descriptor via IO::Select; otherwise it falls back to a short sub-second sleep and retry.

$id = $self->send_request($req)
$self->send_request($req, $cb)

Sends a request to the peer. $req is the request data, $cb is an optional callback for async responses.

Returns the request ID.

$res = $self->get_response($id)

Gets a response for a previously sent request.

If the response is ready it is returned, otherwise undef is returned.

Exceptions will be thrown if the $id is invalid, or if the response has already been fetched.

SOURCE

The source code repository for IPC::Manager can be found at https://github.com/exodist/IPC-Manager.

MAINTAINERS

Chad Granum <exodist@cpan.org>

AUTHORS

Chad Granum <exodist@cpan.org>

COPYRIGHT

Copyright Chad Granum <exodist7@gmail.com>.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See https://dev.perl.org/licenses/