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
forkreturned inipcm_service's parent branch (the "first-fork" pid). Populated only when the peer was produced byipcm_servicespawning a nested service;undefotherwise.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),readyreturns the current state immediately (one-shot, backwards-compatible).With
$timeout,readyblocks until the peer becomes active or the timeout elapses, whichever comes first. A$timeoutof0blocks 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),readywaits on that descriptor viaIO::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.
$reqis the request data,$cbis 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
AUTHORS
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.