Le 21/11/2011 10:44, Martin Hamant a écrit :
>
>
> Le 19/11/2011 16:27, David Baelde a écrit :
>> Hi Martin,
>>
>> On Wed, Nov 16, 2011 at 9:41 AM, Martin Hamant<[email protected]>  
>> wrote:
>>> the code resides in http://snipt.org/Umll3
>>> This is the piece of code I wrote that contains metadata update 
>>> function for
>>> dynamic source.
>>> It works well as it is when adding source/link, but
>>> there is still something to solve when destroying
>> As you have correctly observed, if you don't stop the poll (which
>> relies on add_timeout) then the sources are still referenced and don't
>> completely go away even though the output has been destroyed.
> I noticed the effect without identified the cause, which is add_timeout
> Thanks !
>>
>> To stop add_timeout, you must make it return a negative value, so it
>> won't be re-scheduled. I would suggest creating a reference to a
>> float, used by add_timeout, initially set to the desired polling
>> delay, and set to -1. when the whole thing is destroyed.
> Understood.
>>
>> To accommodate this into your code I would suggest adopting a more
>> general and flexible system. Instead of keeping a list of active
>> sources, and iterating shutdown on them, maintain a list of functions.
>> The destroy function associated to one playlist could be something
>> like { source.shutdown(s0) ; source.shutdown(output) ; delay := (-1.)
>> }.
>>
> Hmm.hmm :)
>
> Do you mean I should do something like that in create_playlist() 
> telnet handler
>
>     def destroy() =
>         source.shutdown(s0)
>         source.shutdown(output)
>         # delay to implement
>   end
>
>   dyn_f :=
>       list.append( [(uri,destroy())],
>                     !dyn_f )

Ok, seems like I've sorted out the problem somehow with:

# in create_playlist()
(...)
   dyn_sources :=
       list.append( [(uri,{ source.shutdown(s0) ; 
source.shutdown(output) ; delay := (-1.) })],
                     !dyn_sources )

So now dyn_sources contains (uri, <fun>) (so it's more like the variable 
dyn_sources should be renamed to dyn_fun or something like that)

in destroy_playlist()
(... some code to make matching_ and remaining_sources ... then :)
# matching_sources form is [<fun>, <fun> ... ]
   if list.length(matching_sources) == 0 then
     "Error: no matching sources!"
   else
     # We stop all sources
     # this is what I've found to work... is this correct ?
     list.iter(fun(x)->x(), matching_sources)

     # And return
     "Done!"
   end

And in destroy_all_playlist, I had to do like follow:

def destroy_all_playlists(uri) =
     # previous code, when dyn_sources contained active sources
     #list.iter(fun(x)->source.shutdown(snd(x)), !dyn_sources)

     def shut(x) =
         x()
     end
     list.iter(fun(x)->shut(snd(x)), !dyn_sources)
     dyn_sources := []
     print(dyn_sources)
     "Done!"
end

Tell me if ... this is viable... or if there is a "clearer" way to write 
that !?

Thanks !!

------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
Savonet-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/savonet-users

Reply via email to