NAME

XAS::Lib::Services - A class to interact with Services

SYNOPSIS

use POE;
use XAS::Lib::Service;
use XAS::Lib::Services;

my $service = XAS::Lib::Services->new(
   -alias             => 'service',
   -poll_interval     => 2,
   -shutdown_interval => 25
);

my $task = XAS::Lib::Service->new(
    -alias => 'task'
);

$service->register('task');
$poe_kernel->run();

DESCRIPTION

This module provides a generic interface to "Services". A Service is a managed background process. It responds to external events. On Windows this would be responding to commands from the Service Control Manager. On Unix this would be responding to a special set of signals. This module provides an event loop that can interact those external events.

When an external event happens this module will trap it and generate a POE event. This event is then sent to all interested modules. The following POE events have been defined:

session_startup

This is fired when your process starts up and is used to initialize what ever processing you are going to do. On a network server, this may be opening a port to listen on.

session_shutdown

This is fired when your process is shutting down.

session_pause

This is fired when your process needs to "pause".

session_resume

This is fired when your process needs to "resume".

session_idle

This is fired at every poll_interval.

These events follow closely the model defined by the Windows Service Control Manager interface. To use these events it is best to inherit from XAS::Lib::Service.

METHODS

new()

This method is used to initialize the service. It takes the following parameters:

-alias

The name of this POE session.

-poll_interval

This is the interval were the SCM sends SERVICE_RUNNING message. The default is every 2 seconds.

-shutdown_interval

This is the interval to pause the system shutdown so that the service can cleanup after itself. The default is 25 seconds.

It also use parameters from XAS::Lib::Session.

register($session)

This allows your process to register whatever modules you want events sent too.

$session

This can be an array reference or a text string. The text string may be delimited with commas.

SEE ALSO

XAS

AUTHOR

Kevin L. Esteb, <kevin@kesteb.us>

COPYRIGHT AND LICENSE

Copyright (C) 2014 Kevin L. Esteb

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.

See http://dev.perl.org/licenses/ for more information.