| AEAE documentation | Contained in the AEAE distribution. |
AEAE::Service - Exposes all service availables for managing an AEAE::Command
jerome@eteve.net
This module requires Data::UUID, Carp
my $ticket = AEAE::Service->launchCommand('AEAE::Command', 'param1', 'param2');
print "\nTicket : ".$ticket."\n";
while(1){ sleep(1); my $r = AEAE::Service->checkTicket($ticket);
print "Check : ".$r."\n";
if( $r >= 100 ){ last ; }
}
my $std = AEAE::Service->getSTDOUT($ticket);
print "STDOUT: ".$std;
AEAE::Service->cleanTicket($ticket);
Launch the given command and return a ticket.
Usage:
my $cmd = 'AEAE::Command' ; # or any subclass of this.
my $ticket = AEAE::Service->launchCommand($cmd, $arg1 , $arg2 ...);
$arg1, $arg2 ... are given to the command as arguments.
Given a ticket, return the pc of advancement of the corresponding command.
If pc >= 100, that means the command is over !
Usage:
my $ticket = ... ; # A valid ticket
my $pc = AEAE::Service->checkTicket($ticket);
Returns the STDOUT of the command. Wait the command to end to have the real STDOUT :)
Usage: my $ticket = ... ; my $stdout = AEAE::Service->getSTDOUT($ticket);
Same as getSTDOUT but for STDERR :)
If an error occured in the execution of the command, returns the error string. Else return an empty string.
Gets only the message associated with the error (without the call stack). Returns empty string if no error occured.
Abort the command corresponding to the ticket.
Usage :
my $ticket = ... ;
AEAE::Service->killTicket($ticket);
Returns: the STDOUT of the killed command.
Clean the ressources associated with the ticket. Use it before throwing ticket to rubbish to avoid ressource starvation.
my $ticket = ... ; # A valid ticket
AEAE::Service->cleanTicket($ticket);
$ticket = undef ; # Ticket is not valid anymore.
| AEAE documentation | Contained in the AEAE distribution. |
package AEAE::Service ;
use Carp ; use POSIX qw(setsid);
sub launchCommand{ my ($class, $cmdClass , @cmdArgs ) = @_ ; eval "require $cmdClass" ; if( $@ ){ #confess("Cannot load command $cmdClass: $@"); # Never make mistakes (normally). return $class->launchCommand('AEAE::CommandErroneous',"Cannot load $cmdClass:". $@); } require Data::UUID; my $ug = new Data::UUID ; $uid = $sessId = $ug->create_str() ; if( $pid = fork() ){ #print STDERR "In father . Returning ticket\n"; return $cmdClass."/".$uid ; } else{ #print STDERR "In son. Doing actual command\n"; setsid(); close STDIN ; close STDERR; close STDOUT; my $cmd = $cmdClass->new($uid); $cmd->doIt(@cmdArgs); exit(0); } }
sub checkTicket{ #return "toto"; my ($pack, $ticket) = @_ ; my ($class,$pid) = split "/" , $ticket ; #return $class ; #confess("Class: ".$class." Id: ".$id); eval "require $class" ; if( $@ ){ confess( "Cannot load class $class : $@"); } my $cmd = $class->new($pid); #return $cmd ; return $cmd->checkStep(); }
sub getSTDOUT{ my ($pack, $ticket) = @_ ; my ($class,$pid) = split "/" , $ticket ; #return $class ; #confess("Class: ".$class." Id: ".$id); eval "require $class" ; if( $@ ){ confess( "Cannot load class $class : $@"); } my $cmd = $class->new($pid); return $cmd->getSTDOUT(); }
sub getSTDERR{ my ($pack, $ticket) = @_ ; my ($class,$pid) = split "/" , $ticket ; #return $class ; #confess("Class: ".$class." Id: ".$id); eval "require $class" ; if( $@ ){ confess( "Cannot load class $class : $@"); } my $cmd = $class->new($pid); return $cmd->getSTDERR(); }
sub getError{ my ($pack, $ticket) = @_ ; my ($class,$pid) = split "/" , $ticket ; #return $class ; #confess("Class: ".$class." Id: ".$id); eval "require $class" ; if( $@ ){ confess( "Cannot load class $class : $@"); } my $cmd = $class->new($pid); return $cmd->getError() ; }
sub getErrorMessage{ my ($pack , $ticket) = @_; my ($class,$pid) = split "/" , $ticket ; eval "require $class" ; if( $@ ){ confess( "Cannot load class $class : $@"); } my $cmd = $class->new($pid); my $error = $cmd->getError() ; return ( $error || '' ) ; }
sub killTicket{ my ($self, $ticket) = @_ ; my ($class,$pid) = split "/" , $ticket ; eval "require $class" ; if( $@ ){ confess( "Cannot load class $class : $@"); } my $cmd = $class->new($pid); my $res= $cmd->suicide() ; return $res; }
sub cleanTicket{ my ($self, $ticket ) = @_ ; my ($class,$pid) = split "/" , $ticket ; eval "require $class" ; if( $@ ){ confess( "Cannot load class $class : $@"); } my $cmd = $class->new($pid); return $cmd->clean(); } 1;