Added "register_death_callback()" interface to run code at the begining of
authormiker <miker@9efc2488-bf62-4759-914b-345cdb29e865>
Tue, 22 Feb 2005 13:44:46 +0000 (13:44 +0000)
committermiker <miker@9efc2488-bf62-4759-914b-345cdb29e865>
Tue, 22 Feb 2005 13:44:46 +0000 (13:44 +0000)
"kill_me()".  This is the first thing needed to provide a transparent transaction
interface somewhere down the line.  It is added now to support database transactions
that span multiple requests.  We need this in order to send a ROLLBACK to the DB
in the case of a session killing error during a DB transaction.  We don't want
to leave locks or failed transactions lying around in the DB, right?

git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@94 9efc2488-bf62-4759-914b-345cdb29e865

src/perlmods/OpenSRF/AppSession.pm

index 230e3a1..b25dcc4 100644 (file)
@@ -125,6 +125,7 @@ sub server_build {
        my $self = bless { recv_queue  => [],
                           request_queue  => [],
                           requests  => 0,
+                          death_callbacks  => [],
                           endpoint    => SERVER,
                           state       => CONNECTING, 
                           session_id  => $sess_id,
@@ -323,9 +324,21 @@ sub finish {
        }
 }
 
+sub register_death_callback {
+       my $self = shift;
+       my $cb = shift;
+       push @{ $self->{death_callbacks} }, $cb;
+}
+
 sub kill_me {
        my $self = shift;
        if( ! $self->session_id ) { return 0; }
+
+       # run each 'kill_me' callback;
+       for my $sub (@{$self->{death_callbacks}}) {
+               $sub->($self);
+       }
+
        $self->disconnect;
        $logger->transport( "AppSession killing self: " . $self->session_id(), DEBUG );
        my @a;
@@ -840,6 +853,11 @@ sub respond_complete {
 
 }
 
+sub register_death_callback {
+       my $self = shift;
+       my $cb = shift;
+       $self->session->register_death_callback( $cb );
+}
 
 package OpenSRF::AppSubrequest;