NAME
IPC::Manager::Service - Base class for creating IPC services
DESCRIPTION
This class provides a concrete implementation of the IPC::Manager::Role::Service role for creating IPC services. It handles message handling, peer management, signal handling, and the main event loop.
SYNOPSIS
use IPC::Manager::Service;
my $service = IPC::Manager::Service->new(
name => 'my-service',
ipcm_info => $ipcm_info,
handle_request => sub {
my ($self, $request, $msg) = @_;
return {result => 'ok'};
},
);
$service->run;
CONSTRUCTOR ARGUMENTS
- name
-
The service name (required).
- orig_io
-
Hashref with optional
stdoutandstderrfilehandles for debug output. - ipcm_info
-
Connection information for the IPC system.
- redirect
-
Boolean indicating whether to redirect I/O.
- pid
-
The process ID.
- use_posix_exit
-
Boolean indicating whether to use POSIX exit codes.
- intercept_errors
-
Boolean indicating whether to intercept and log errors.
- watch_pids
-
Arrayref of PIDs to watch. If any terminates, the service exits.
- interval
-
Interval for
run_on_intervalcallbacks (default: 0.2 seconds). - cycle
-
Select cycle time (default: 0.2 seconds).
- on_sig => {\%hash}
-
Hash of signal names to callback(s) for signal handling.
- handle_request => \&callback
-
Callback for handling requests. Required unless
on_allis provided. - handle_response => \&callback
-
Callback for handling responses. Defaults to confessing if not provided.
- on_all => \&callback
-
Callback called for every activity cycle. If provided,
handle_requestandhandle_responsedefault to no-ops. - on_cleanup => \&callback
-
Callback called when the service is shutting down.
- on_general_message => \&callback
-
Callback for messages that are not requests or responses.
- on_interval => \&callback
-
Callback called at regular intervals.
- on_peer_delta => \&callback
-
Callback called when peer connections change.
- on_start => \&callback
-
Callback called on startup before the main loop.
- on_unhandled => \&callback
-
Callback called when activity remains unhandled. Dies by default.
- should_end => \&callback
-
Callback called to determine if the service should exit.
METHODS
- @signal_names = $self->signals_to_grab()
-
Returns a list of signals to intercept.
- ($resp) = $self->handle_request($request, $msg)
-
Calls the configured request handler. The handler should return a single item (scalar, undef, reference) when if the response is ready. Should return an empty list if the request needs further processing.
- $self->handle_response($resp, $msg)
-
Calls the configured response handler.
- $self->clear_on_sig($sig)
-
Clears all handlers for a signal.
- $self->push_on_sig($sig, $cb)
-
Adds a callback to the signal handlers.
- $self->unshift_on_sig($sig, $cb)
-
Prepends a callback to the signal handlers.
- $self->run_on_sig($sig, @args)
-
Runs all callbacks for a signal.
- $self->remove_on_sig($sig, $cb)
-
Removes a specific callback from signal handlers.
- $self->clear_on_all()
-
Clears the array of callbacks for
on_all. - $self->push_on_all($cb)
-
Adds a callback to the
on_allcallback array. - $self->unshift_on_all($cb)
-
Prepends a callback to the
on_allcallback array. - $self->run_on_all(@args)
-
Runs all callbacks for
on_all. - $self->remove_on_all($cb)
-
Removes a specific callback from the
on_allcallback array. - $self->clear_on_cleanup()
-
Clears the array of callbacks for
on_cleanup. - $self->push_on_cleanup($cb)
-
Adds a callback to the
on_cleanupcallback array. - $self->unshift_on_cleanup($cb)
-
Prepends a callback to the
on_cleanupcallback array. - $self->run_on_cleanup(@args)
-
Runs all callbacks for
on_cleanup. - $self->remove_on_cleanup($cb)
-
Removes a specific callback from the
on_cleanupcallback array. - $self->clear_on_general_message()
-
Clears the array of callbacks for
on_general_message. - $self->push_on_general_message($cb)
-
Adds a callback to the
on_general_messagecallback array. - $self->unshift_on_general_message($cb)
-
Prepends a callback to the
on_general_messagecallback array. - $self->run_on_general_message(@args)
-
Runs all callbacks for
on_general_message. - $self->remove_on_general_message($cb)
-
Removes a specific callback from the
on_general_messagecallback array. - $self->clear_on_interval()
-
Clears the array of callbacks for
on_interval. - $self->push_on_interval($cb)
-
Adds a callback to the
on_intervalcallback array. - $self->unshift_on_interval($cb)
-
Prepends a callback to the
on_intervalcallback array. - $self->run_on_interval(@args)
-
Runs all callbacks for
on_interval. - $self->remove_on_interval($cb)
-
Removes a specific callback from the
on_intervalcallback array. - $self->clear_on_peer_delta()
-
Clears the array of callbacks for
on_peer_delta. - $self->push_on_peer_delta($cb)
-
Adds a callback to the
on_peer_deltacallback array. - $self->unshift_on_peer_delta($cb)
-
Prepends a callback to the
on_peer_deltacallback array. - $self->run_on_peer_delta(@args)
-
Runs all callbacks for
on_peer_delta. - $self->remove_on_peer_delta($cb)
-
Removes a specific callback from the
on_peer_deltacallback array. - $self->clear_on_start()
-
Clears the array of callbacks for
on_start. - $self->push_on_start($cb)
-
Adds a callback to the
on_startcallback array. - $self->unshift_on_start($cb)
-
Prepends a callback to the
on_startcallback array. - $self->run_on_start(@args)
-
Runs all callbacks for
on_start. - $self->remove_on_start($cb)
-
Removes a specific callback from the
on_startcallback array. - $self->clear_on_unhandled()
-
Clears the array of callbacks for
on_unhandled. - $self->push_on_unhandled($cb)
-
Adds a callback to the
on_unhandledcallback array. - $self->unshift_on_unhandled($cb)
-
Prepends a callback to the
on_unhandledcallback array. - $self->run_on_unhandled(@args)
-
Runs all callbacks for
on_unhandled. - $self->remove_on_unhandled($cb)
-
Removes a specific callback from the
on_unhandledcallback array. - $self->clear_should_end()
-
Clears the array of callbacks for
should_end. - $self->push_should_end($cb)
-
Adds a callback to the
should_endcallback array. - $self->unshift_should_end($cb)
-
Prepends a callback to the
should_endcallback array. - $self->run_should_end(@args)
-
Runs all callbacks for
should_end. Returns true if any callback returns true. - $self->remove_should_end($cb)
-
Removes a specific callback from the
should_endcallback array.
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.