For Programmers: Free Programming Magazines  


Home > Archive > PERL POE > December 2007 > on_exit type of callback in POE::Component::Generic









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author on_exit type of callback in POE::Component::Generic
Daisuke Maki

2007-12-14, 4:45 am

Hi,

I might just be missing something obvious, is there anyway to tell if an
object being accessed via POE::Component::Generic is dead?

Basically, I'd like to wrap things like DBI access and such underneath
PoCo::Generic, but at the same time I'd like to detect when, for
example, a DBI connection is lost, or perhaps the child process that is
wrapping DBI is killed.

In such cases, I'd like to spawn a new instance of so that it takes over
the dead one.

Is there a way to do this?

--d
Philip Gwyn

2007-12-14, 8:27 am


On 14-Dec-2007 Daisuke Maki wrote:
> Hi,
>
> I might just be missing something obvious, is there anyway to tell if an
> object being accessed via POE::Component::Generic is dead?


Short answer : your code should never die!

Looking at my code, it seems that POE::Component::Generic doesn't handle dead
child processes very well.

Unless you wish to modify PoCo::Generic (patches welcome!), you could you'll
have to overload the __wheel_close(). Roughly :

package My::Generic;
use base qw( POE::Component::Generic );
sub __wheel_close {
my( $self, $wheel_id ) = @_[ OBJECT, ARG0 ];
# your code here
$_[KERNEL]->post( $your_session, 'respawn_event', ... )

$self->SUPER::__wheel_close( @_ );
}

> Basically, I'd like to wrap things like DBI access and such underneath
> PoCo::Generic, but at the same time I'd like to detect when, for
> example, a DBI connection is lost, or perhaps the child process that is
> wrapping DBI is killed.


You might want to look at POE::Component::EasyDBI, from which
POE::Component::Generic is a philosophical descendent. It handles gracefully
restarting the child process if it dies, something that POE::Component::Generic
never will.

-Philip
ty

2007-12-14, 7:35 pm

I agree the EasyDBI is the way to go for this. I ended up hacking
EasyDBI SubProcess to ensure that all the statements are finished and
the disconnect is called so that resources on the database side are
not consumed.

On Dec 14, 6:51 am, li...@artware.qc.ca (Philip Gwyn) wrote:
> On 14-Dec-2007 Daisuke Maki wrote:
>
>
>
> Short answer : your code should never die!
>
> Looking at my code, it seems that POE::Component::Generic doesn't handle dead
> child processes very well.
>
> Unless you wish to modify PoCo::Generic (patches welcome!), you could you'll
> have to overload the __wheel_close(). Roughly :
>
> package My::Generic;
> use base qw( POE::Component::Generic );
> sub __wheel_close {
> my( $self, $wheel_id ) = @_[ OBJECT, ARG0 ];
> # your code here
> $_[KERNEL]->post( $your_session, 'respawn_event', ... )
>
> $self->SUPER::__wheel_close( @_ );
> }
>
>
> You might want to look at POE::Component::EasyDBI, from which
> POE::Component::Generic is a philosophical descendent. It handles gracefully
> restarting the child process if it dies, something that POE::Component::Generic
> never will.
>
> -Philip


Daisuke Maki

2007-12-15, 8:27 am




>
> Short answer : your code should never die!


Ah well, yeah ;P


> Unless you wish to modify PoCo::Generic (patches welcome!), you could you'll
> have to overload the __wheel_close(). Roughly :
>
> package My::Generic;
> use base qw( POE::Component::Generic );
> sub __wheel_close {
> my( $self, $wheel_id ) = @_[ OBJECT, ARG0 ];
> # your code here
> $_[KERNEL]->post( $your_session, 'respawn_event', ... )
>
> $self->SUPER::__wheel_close( @_ );
> }


seems reasonable, I think I'll try this approach.
Thanks!
(BTW, if there's a repository available, I might try to patch
PoCo::Generic as well)

> You might want to look at POE::Component::EasyDBI, from which
> POE::Component::Generic is a philosophical descendent. It handles gracefully
> restarting the child process if it dies, something that POE::Component::Generic
> never will.


Hmm, I'd rather not use EasyDBI, as I wanted to group several SQL
queries that affect each other as one atomic operation.

Thanks,
--d


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com