On Fri, 2008-01-18 at 09:45 -0600, Craig Votava wrote: > Folks- > > I'm just starting with POE, and have a question on how to prioritize > my event loops (and if I'm logically creating the right number of > event loops). You don't generally have more than one event loop. (not even sure if that is even possible)
> I need to write a program to help the user analyze data coming in > >from a live data feed (incoming UDP or TCP). This means that the > program needs to do the following (in priority order, highest to > lowest): > > 1.) Read in the raw data from the data feed (highest) > 2.) Do any user events in the ptk loop > 3.) Parse the raw data into cooked data whenever there are idle > cycles (lowest) > > I've created loop #1 by tailoring the "TCP server with IO::Select" > example from the cookbook. I've also created loop #2, which handles > the ptk stuff (currently the program will simply put up each raw text > line into a ptk text window for the user to see). As I understand > POE, my current implementation will give both of these loops equal > priority. You can do all of this in one loop. The Tk loop can handle the getting data from the network just fine, no need to have a seperate IO::Select loop for that. > Then I started thinking about parsing the raw data. At first, I > wanted loop #1 to parse the data right after it came in, but then I > realized that because of the sequencing of POE, parsing would be > forced to occur in realtime (possibly delaying the incoming data from > the live data feed). That's when I understood that I needed loop #3, > but I don't know how to create an event loop that only executes when > there are idle cycles. Generally in POE, this is done on the fly. Not sure which cookbook recipe you're referring too, but in the second example of http://poe.perl.org/?POE_Cookbook/TCP_Servers there is a commented out line: # ClientFilter => "POE::Filter::Reference", If you enable that, then instead of giving you raw chunks of data, POE will pass the raw data through Storable (or something else; see its documentation) and hand you Perl references. So, you probably want to write a POE::Filter to go from raw to cooked data. *maybe* this would get problematic if going from raw to cooked is really complex, and you have a lot of data coming in, but wouldn't you then have problems with the GUI keeping up anyway? > Also, is there any way to tell POE I want loop #1 to have higher > priority than loop #2? The default (and currently only implemented one) POE::Queue is a FIFO queue, so there is no prioritizing, no. Martijn