Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Signal handlers for POE::Component::*

by pope (Friar)
on Sep 24, 2005 at 11:02 UTC ( [id://494763]=perlquestion: print w/replies, xml ) Need Help??

pope has asked for the wisdom of the Perl Monks concerning the following question:

Dear brother monks, I need some wisdom and enlightenment.

I've just started using POE since my project gets bigger and much more complex to manage. Things go fine until I need to install signal handlers for POE::Component::Server::HTTP.

I think the most logical place to install a signal handler for a POE component is through Started option which I found to be available for POE::Component:Server::TCP and POE::Component::Client::TCP. Since I couldn't find one for PoCo::Server::HTTP, I wrote my own HTTP server component which is much simpler but contains everything I need.

But then again I face the same problem when I want to add logging facility to the HTTP server component. I choose POE::Component::Logger since it looks like the easiest one to use. There is no such thing like Started option. Things are worse since there is no means to pass custom inline_states. I saw InlineStates option to those PoCo::*::TCP components.

My question is, what is the common way / best practice to install a signal handler for a component which doesn't have Started and InlineStates options?

Replies are listed 'Best First'.
Re: Signal handlers for POE::Component::*
by nicholasrperez (Monk) on Sep 25, 2005 at 04:49 UTC
    Well, how about instantiating your own session and install the signal handler there? Who says you need to be able to do it within the confines of the slave component? With end developer POE::Components, it is generally assumed that you will be running it as part of a larger framework with other sessions doing other things, such as receiving events, etc. Remember that all of POE (for the most part, save Wheel::Run and PoCo::Child) runs inside a single perl interpreter. It doesn't really matter where you install the signal handler, so do it outside of the slave component.

    -- NPEREZ

      Yes we can create our own session and install the sig handler there, but then when the sig handler needs to tell the component: "Hey we've just got SIGHUP here, so please close and reopen your log file!", what to do?

      normally we'll do: $kernel->post("logger", "do_rotate"); but since there are no InlineStates and friends, we can't specify "do_rotate" and its callback.

Re: Signal handlers for POE::Component::*
by Ultra (Hermit) on Sep 25, 2005 at 15:37 UTC

    You can "catch" signals, and when a signal is received, you may send an event to whatever session you want.

    You can find more details reading POE::Kernel

    Update: The point is that instead of having components handling signals themselves, the kernel does that, and you by deciding where to send events (if any).

    Dodge This!
Re: Signal handlers for POE::Component::*
by eXile (Priest) on Sep 25, 2005 at 15:14 UTC
    Haven't looked into this into much detail, but using inheritance might be a solution to your problems:
    package POE::Component::Server::MyHTTP;
    use base qw(POE::Component::Server::HTTP);
    
    Then override and/or add methods you need.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://494763]
Approved by ww
Front-paged by planetscape
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-03-28 14:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found