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

NAME

Siebel::Srvrmgr::Daemon::Heavy - "heavier' implementation of Siebel::Srvrmgr::Daemon

SYNOPSIS

    use Siebel::Srvrmgr::Daemon;

    my $daemon = Siebel::Srvrmgr::Daemon->new(
        {
            server      => 'servername',
            gateway     => 'gateway',
            enterprise  => 'enterprise',
            user        => 'user',
            password    => 'password',
            bin         => 'c:\\siebel\\client\\bin\\srvrmgr.exe',
            is_infinite => 1,
                        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]
                    )
                ]
        }
    );

DESCRIPTION

This class is the "heavier" version of Siebel::Srvmrgr::Daemon. By heavier, understand more complex code to be able to deal with a heavier usage of srvrmgr.

This class is indicated to be used in cenarios 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.

This module is based on IPC::Open3::Callback from Lucas Theisen (see SEE ALSO section) implemented in Siebel::Srvrmgr::Daemon::IPC.

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.

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 3 seconds.

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.

BUILD

This methods calls clear_pid just to have a sane setting on child_pid 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).

cmd_stack

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

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.

alarm_timeout

The an integer value that will raise an ALARM signal generated by alarm. The default value is 30 seconds.

Besides read_timeout, this will raise an exception and exit the read loop from srvrmgr in cases were an output cannot be retrieved.

This attribute will be reset every time a read can be done from the STDOUT or STDERR from srvrmgr.

ipc_buffer_size

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

It defaults to 5120 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

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.

is_infinite

Returns the content of the attribute is_infinite, returning true or false depending on this value.

get_last_cmd

Returns the content of the attribute last_cmd as a string.

get_cmd_stack

Returns the content of the attribute cmd_stack.

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.

Beware that Siebel::Srvrmgr::Daemon uses a single instance of a Siebel::Srvrmgr::ListParser class to process the parsing requests, so it is not possible to execute Siebel::Srvrmgr::Daemon::Command instances in parallel.

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 succesfully, this method returns true. If there is no PID associated with the Daemon instance, this method will return false.

Accepts as an optional parameter an instance of a Log::Log4perl for logging messages.

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/.