On Mon, Oct 27, 2008 at 07:56:01AM -0700, ty wrote:
> I have a POE server that spawns some sessions that use
> POE::Component::Generic.  Each of these sessions act as a separate
> tool in the server.  From time to time, I have to make changes to a
> module that is used by one of the sessions.  It requires me to
> restart the server now so that the new changes are reflected.  It
> would be nice if there was a way to tell the session to reload the
> module like it is possible in mod_perl with various apache modules.
> I came across a post on this group in 2005 titled Unuse Modules, but
> this was looking at the problem from getting them out of the system
> not reloading.  Module::Refresh seems to be a possible solution.
> However, I wanted to know if anyone has successfully done something
> like this in the context of POE running in a persistent environment?

Haven't tried it and have no experience with Module::Refresh.  (Stop
reading now, if you like.  :)

That said, it seems like it'd be possible, with extreme care.  Some
things that you'd have to be careful with

  - variable reinitialization
  - BEGIN/END/etc blocks
  - class redefinitions

It seems likely to me that reloading a module would only work if
you've written it to expect to be reloaded, and/or if the changes made
affect only certain things.

I looked at the Module::Refresh, Apache::StatINC, and Module::
Reload docs.  The last one mentions this caveat:

  A growing number of pragmas (base, fields, etc.) assume that they
  are loaded once only.  When you reload the same file again, they
  tend to become confused and break.

If you try it and get it to work, I, for one, would be interested in
reading about your experiences.  I haven't done much with POE yet, but
it's on the horizon at work, and one of the things I expect to want to
do is have a long-running server process that can reload code if it
changes.

Hmmm ... which actually brings up another idea.  Have you looked at
PoCo::Generic (or similar ideas)?

  POE::Component::Generic is a POE component that provides a
  non-blocking wrapper around any object. It works by forking a child
  process with POE::Wheel::Run and creating the object in the child
  process. Method calls on the object are then serialised [sic] and
  sent to the child process to be handled by the object there. The
  returned value is serialised [sic] and sent to the parent process,
  where it is posted as a POE event.

If you create the session in a child, then you can update the object
definition, and then throw away the old child and start a new one.

Hope that helps.

-- Larry

Reply via email to