From 8bb8460b3e430a55ca7840029fa53fd7f4beba7f Mon Sep 17 00:00:00 2001 From: miker Date: Thu, 10 Mar 2005 00:32:12 +0000 Subject: [PATCH] transactions are working now ... some cleanup is needed git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@207 9efc2488-bf62-4759-914b-345cdb29e865 --- src/perlmods/OpenSRF/AppSession.pm | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/perlmods/OpenSRF/AppSession.pm b/src/perlmods/OpenSRF/AppSession.pm index 487e207..5c9bff0 100644 --- a/src/perlmods/OpenSRF/AppSession.pm +++ b/src/perlmods/OpenSRF/AppSession.pm @@ -126,7 +126,7 @@ sub server_build { request_queue => [], requests => 0, session_data => {}, - callbacks => { death => [], disconnect => [] }, + callbacks => {}, endpoint => SERVER, state => CONNECTING, session_id => $sess_id, @@ -336,20 +336,35 @@ sub finish { } } +sub unregister_callback { + my $self = shift; + my $type = shift; + my $cb = shift; + if (exists $self->{callbacks}{$type}) { + delete $self->{callbacks}{$type}{$cb}; + return $cb; + } + return undef; +} + sub register_callback { my $self = shift; my $type = shift; my $cb = shift; - push @{ $self->{callbacks}{$type} }, $cb; + my $cb_key = "$cb"; + $self->{callbacks}{$type}{$cb_key} = $cb; + return $cb_key; } sub kill_me { my $self = shift; if( ! $self->session_id ) { return 0; } - # run each 'kill_me' callback; - for my $sub (@{$self->{callbacks}{death}}) { - $sub->($self); + # run each 'death' callback; + if (exists $self->{callbacks}{death}) { + for my $sub (values %{$self->{callbacks}{death}}) { + $sub->($self); + } } $self->disconnect; @@ -371,8 +386,10 @@ sub disconnect { $self->state( DISCONNECTED ); } # run each 'disconnect' callback; - for my $sub (@{$self->{callbacks}{disconnect}}) { - $sub->($self); + if (exists $self->{callbacks}{disconnect}) { + for my $sub (values %{$self->{callbacks}{disconnect}}) { + $sub->($self); + } } $self->reset; -- 2.11.0