On Tue, Dec 04, 2001 at 12:39:22PM -0700, Chris Fedde wrote:
> The below is admittedly cargo cult code.  I'm trying to understand
> how the parts all fit together.  Let's say that I have a dozen other
> sessions running. Each doing important things like balancing the
> national debt or negotiating peace in the middle east. I don't want
> to just whack them. Is there a way to tell all the running sessions
> to close themselves down rather than just calling exit?

[...]

The only built-in way to broadcast a message to every session is by
sending a signal to POE::Kernel:

  $kernel->signal( $kernel => 'GO_AWAY_NOW' );

You could write some sort of session database and have every session
register themselves with it, but that's a lot more work.

Either way, each session needs some code to gracefully shut itself
down.  Using signals, that code would be tied to the fictitious
GO_AWAY_NOW signal:

  POE::Session->create(
    inline_states => {
      _start => \&start_the_peace_process,
      ...,
      my_personal_shutdown_event => \&halt_the_peace_process,
    }
  );

  sub start_the_peace_process {
    my ($kernel, $heap) = @_[KERNEL, HEAP];

    $heap->{peace_wheel} = POE::Wheel::Peace->new(
      Where => "Middle East"
    );

    $kernel->sig( GO_AWAY_NOW => 'my_personal_shutdown_event' );
  }

  sub halt_the_peace_process {
    my $heap = $_[HEAP];
    delete $heap->{peace_wheel};
  }

You would probably want to do something more graceful like send a
goodbye message before deleting the peace wheel, but that's the gist
of things.

-- Rocco Caputo / [EMAIL PROTECTED] / poe.perl.org / poe.sourceforge.net

Reply via email to