The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Siebel::Srvrmgr::Daemon::Heavy - subclass that reuses srvrmgr program instance for long periods

SYNOPSIS

    use Siebel::Srvrmgr::Daemon::Heavy;

    my $daemon = Siebel::Srvrmgr::Daemon::Heavy->new(
        {
            time_zone   => 'America/Sao_Paulo',
            commands    => [
                    Siebel::Srvrmgr::Daemon::Command->new(
                        command => 'load preferences',
                        action  => 'LoadPreferences'
                    ),
                    Siebel::Srvrmgr::Daemon::Command->new(
                        command => 'list comp type',
                        action  => 'ListCompTypes',
                        params  => [$comp_types_file]
                    ),
                    Siebel::Srvrmgr::Daemon::Command->new(
                        command => 'list comp',
                        action  => 'ListComps',
                        params  => [$comps_file]
                    ),
                    Siebel::Srvrmgr::Daemon::Command->new(
                        command => 'list comp def',
                        action  => 'ListCompDef',
                        params  => [$comps_defs_file]
                    )
                ]
        }
    );
    $daemon->run($connection);

DESCRIPTION

This class extends Siebel::Srvmrgr::Daemon. By "Heavy" you should understand as more complex code to be able to deal with a large number of commands of srvrmgr that will be submitted to a Siebel Enterprise with a short time between them.

This class is indicated to be used in scenarios where several commands need to be executed in a short time interval: it will connect to srvrmgr by using IPC for communication between the processes and once connected, the srvrmgr session will be reused as many times as desired instead of following the sequence of connect -> run commands -> disconnect.

The sessions are not "interactive" from the user point of view but the usage of this class enable the adoption of some logic to change how the commands will be executed or even generate commands on the fly.

Since it uses Perl IPC, this class may suffer from good support in OS plataforms that are not UNIX-like. Be sure to check out tests results of the distribution before trying to use it.

ATTRIBUTES

This class has additional attributes besides those from parent class.

maximum_retries

The maximum times this class wil retry to launch a new process of srvrmgr if the previous one failed for any reason. This is intented to implement robustness to the process.

retries

The number of retries of launching a new srvrmgr process. If this value reaches the value defined for maximum_retries, the instance of Siebel::Srvrmgr::Daemon will quit execution returning an error code.

write_fh

A filehandle reference to the srvrmgr STDIN. This is a read-only attribute.

read_fh

A filehandle reference to the srvrmgr STDOUT.

This is a read-only attribute.

error_fh

A filehandle reference to the srvrmgr STDERR.

This is a read-only attribute.

read_timeout

The timeout for trying to read from child process handlers in seconds. It defaults to 0.5 second.

Changing this value may help improving performance, but should be used with care.

child_pid

An integer presenting the process id (PID) of the process created by the OS when the srvrmgr program is executed.

This is a read-only attribute.

last_exec_cmd

This is a string representing the last command submitted to the srvrmgr program. The default value for it is an empty string (meaning that no command was submitted yet).

params_stack

This is an array reference with the stack of params passed to the respective class. It is maintained automatically by the class so the attribute is read-only.

action_stack

This is an array reference with the stack of actions to be taken. It is maintained automatically by the class, so the attribute is read-only.

ipc_buffer_size

A integer describing the size of the buffer used to read output from srvrmgr program by using IPC.

It defaults to 32768 bytes, but it can be adjusted to improve performance (lowering CPU usage by increasing memory utilization).

Increase of this attribute should be considered experimental.

srvrmgr_prompt

An string representing the prompt recovered from srvrmgr program. The value of this attribute is set automatically during srvrmgr execution.

METHODS

BUILD

This methods calls clear_pid just to have a sane setting on child_pid attribute.

get_retries

Getter for the retries attribute.

get_max_retries

Getter for the max_retries attribute.

clear_pid

Clears the defined PID associated with the child process that executes srvrmgr. This is usually associated with calling close_child.

Beware that this is different then removing the child process or even undef the attribute. This just controls a flag that the attribute child_pid is defined or not. See Moose attributes for details.

has_pid

Returns true or false if the child_pid is defined. Beware that this is different then checking if there is an integer associated with child_pid attribute: this method might return false even though the old PID associated with child_pid is still available. See Moose attributes for details.

get_prompt

Returns the content of the attribute srvrmgr_prompt.

get_buffer_size

Returns the value of the attribute ipc_buffer_size.

set_buffer_size

Sets the attribute ipc_buffer_size. Expects an integer as parameter, multiple of 1024.

get_write

Returns the file handle of STDIN from the process executing the srvrmgr program based on the value of the attribute write_fh.

get_read

Returns the file handle of STDOUT from the process executing the srvrmgr program based on the value of the attribute read_fh.

get_error

Returns the file handle of STDERR from the process executing the srvrmgr program based on the value of the attribute error_fh.

get_pid

Returns the content of pid attribute as an integer.

get_last_cmd

Returns the content of the attribute last_cmd as a string.

get_params_stack

Returns the content of the attribute params_stack.

run

This method will try to connect to a Siebel Enterprise through srvrmgr program (if it is the first time the method is invoke) or reuse an already open connection to submit the commands and respective actions defined during object creation. The path to the program is check and if it does not exists the method will issue an warning message and immediatly returns false.

Those operations will be executed in a loop as long the check method from the class Siebel::Srvrmgr::Daemon::Condition returns true.

close_child

Finishes the child process associated with the execution of srvrmgr program, if the child's PID is available. Besides, this automatically calls clear_pid.

First this methods tries to submit the exit command to srvrmgr, hoping to terminate the connection with the Siebel Enterprise. After that, the handles associated with the child will be closed. If after that the PID is still running, the method will call waitpid in non-blocking mode.

For MS Windows OS, this might not be sufficient: the PID will be checked again after waitpid, and if it is still running, this method will try to use kill 9 to eliminate the process.

If the child process is terminated successfully, this method returns true. If there is no PID associated with the Daemon instance, this method will return false.

BACKGROUND EXECUTION

If you're in a UNIX-like OS, you might want to execute some code with this class as a background process. This can be easily done with:

    nohup ~/perl5/perlbrew/perls/perl-5.16.3/bin/perl ~/my_script.pl
    CRTL+Z
    bg 1

In this example, the Perl interpreter was located in ~/perl5/perlbrew/perls/perl-5.16.3/bin/perl but of course you location might be different.

CAVEATS

This class is still considered experimental and should be used with care. Tests with MS Windows (and the nature of doing IPC within the plataform) makes it difficult do use this class in Microsoft OS's.

The srvrmgr program uses buffering, which makes difficult to read the generated output as expected.

SEE ALSO

AUTHOR

Alceu Rodrigues de Freitas Junior, <arfreitas@cpan.org>.

COPYRIGHT AND LICENSE

This software is copyright (c) 2012 of Alceu Rodrigues de Freitas Junior, <arfreitas@cpan.org>

This file is part of Siebel Monitoring Tools.

Siebel Monitoring Tools is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Siebel Monitoring Tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Siebel Monitoring Tools. If not, see http://www.gnu.org/licenses/.