RE: Pausing POE::Wheel::FollowTail?

"Votava, Craig M \(Craig\)" <[email protected]>
Newsgroups gmane.comp.lang.perl.poe
Message-ID <EDC714147512684D9BFBE6AB9C53AED101AB3B44@ILEXC1U03.ndc.lucent.com>

Larry-

Thanks again for your thoughts. I agree with you about creating a pause
flag inside the wheel, and figuring out how to handle the exception
conditions. I want to run things past Rocco as well (he replied after
you) to see if things make sense from his view. If so, I'll see what I
can do.

Thanks

-Craig

-----Original Message-----
From: Larry Clapp [mailto:[email protected]] 
Sent: Monday, October 06, 2008 6:11 PM
To: Votava, Craig M (Craig)
Cc: [email protected]
Subject: Re: Pausing POE::Wheel::FollowTail?

[ Top posting corrected ]

On Mon, Oct 06, 2008 at 04:24:40PM -0500, Votava, Craig M (Craig) wrote:
> 
> Thanks for the response! Either of your solutions could be best,
> but I'm not sure about a couple of things:
> 
> 1.) Say I save the current state then destroy the wheel. When I
> start up a new wheel, how do I know whether to use the saved data
> to index back to where I left off or (if the file has been reset)
> to just start from the beginning?

That's a good question, and not one I thought of.  :)

I could think of a couple of strategies (check the inode?), but mostly
I think you'd want to dig into the wheel and either do what it does,
or figure out how to get it to *track* the file without actually
reading the data and sending it to you.

I guess if you go with that strategy, you really would need "pause"
functionality, as you initially started out asking for.

> 2.) If I change PollInterval, what value would I change it to, so
> that it would never fire?

I'd probably go with 32e6 seconds, which is just over a year.  Or
there's always 2**32, which is ~136 years.

But as mentioned above, you probably really do want a "pause"
function.  Also, if you fake a "pause" by setting a long interval, as
I initially suggested, I realize now that a) you'd obviously need some
way to get the ball rolling again, and b) those year-later events
would hang around in the queue, and who wants that?

So I guess I'd recommend:

- dig into the wheel; add a flag that tells the read code to skip the
  actual "read the file" part of what it does, but it continues the
  polling at the normal cycle.
- add methods to the wheel to allow you to set or reset the flag

The wheel has a _define_timer_states function that defines how it
deals with files (as opposed to sockets, which is
_define_select_states).  That function looks kind of like this:

    sub _define_timer_states {
      # ... stuff ...
      $poe_kernel->state(
	  $$state_read,
	  sub {
	    # check the inode, read the file, etc
	  } );

      $poe_kernel->delay($$state_read, 0);
    }

I guess I'd try something vaguely similar to:

    my $running = 1;

    sub pause {
      $running = 0;
    }

    sub unpause {
      $running = 1;
    }

    sub _define_timer_states {
      # ... stuff ...
      $poe_kernel->state(
	  $$state_read,
	  sub {
	    if (!$running) {
	      # ... requeue the $$state_read event for $interval seconds
from now ...
	      return;
	    }

	    # check the inode, read the file, etc
	  } );

      $poe_kernel->delay($$state_read, 0);
    }

... except you'd put the $running flag into the wheel object, of
course, otherwise you've paused *all* the wheels in the system!  :)

This is obviously untested and may make demons fly out your nose.  But
I hope it helped anyway.  :)

-- Larry
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.