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

NAME

AEAE::Command - a base class for an asynchroneous command.

AUTHOR

jerome@eteve.net

SYNOPSIS

Use this class as a base class when you wand to implement an asynchroneous command usable by AEAE::Service.

You only have to inherit from this class and implement the methods _doItReal and (eventually) _killHandler .

See those methods for more details.

See AEAE::CommandExample for a simple example.

METHODS

new

Always override this method in subclasses in this way:

sub new{ my ($class) = @_ ;

    my $self = $class->SUPER::new(@_);
    bless $self, $class ;
    return $self ;
}

YOU CANNOT DO ANOTHER WAY. Any attempt to make another constructor will fail.

runningpid

Get/Set the pid of the process running this command.

getSTDOUT

Get the standard ouput content of this command.

Usage:

    my $stdout = $cmd->getSTDOUT();

getSTDERR

Same as getSTDOUT but for STDERR

isLocked

Returns true if is locked, false otherwise. Locked means that the process is not finished yet.

isDone

Returns true when it is done.

done

Set to true the done status. Can be used once.

lock

Internal use.

unlock

Internal use.

isFake

Returns false if the command is a real one.

oneStep

Use this to specifie the percentage of advance of this process.

setError

Internal use.

getError

If an error occurred, return the associated message. Otherwise, return an empty string.

checkStep

Returns the step where the command is, between 0 and 100.

suicide

Kill yourself !!

doIt

Safely execute the nested _doItReal method.

_doItReal

Overide this method in subclasses. This is the main method executing the action to be made asynchroneous.

You must implement this method as a regular synchroneous procedure. You cannot return anything.

Within this method, you can (and must) access the current command to indicate the framework where you are in your procedure. For instance, if you are at 50% done, call :

$AEAE::Command::processCommand->oneStep(50);

Example of implementation:

    sub _doItReal{
        my $self = shift ;
        my $arg1 = shift ;
        my $arg2 = shift ;
        # ...
        my $i = 0 ;
        
        print "Ca commence !\n";
        
        while( $i < 101){
            
            $AEAE::Command::processCommand->oneStep($i);
            print "Step ".$i."\n";
            $i += 1 ;
            select(undef, undef, undef, 0.25);  
        }
        print "C'est fini !\n";
    }

_killHandler

Called on myself when this command receive the order to suicide. Implement here release of ressources, termination of other process etc..

This method is called in the same memory space of the launched command. That means it is the same memory space as you are in the _doItReal method. Hence, any values setted in memory (for instance in $self->...) within the _doItReal method will be available here also.

clean

Cleans the system ressources associated with this command. Implieds the command is done. Otherwise do nothing.