Project

General

Profile

« Previous | Next » 

Revision c1757f15

Added by Marc Dequènes over 13 years ago

  • ID c1757f15137796cfb89f7edf68fe63fedf85d88f

[evol] Conversation: ensure idle check timer are ready for asynchronous replies on the same thread

View differences:

lib/cyborghood/cyborg/botnet/conversation.rb
@conv_threads = {}
@conv_threads_index = {}
@conv_threads_timers = {}
@conv_threads_timers_manage = Mutex.new
@conv_threads_closing = []
# thread 0 is reserved
@next_thread_id = 0
......
end
def stop_idle_thread_check(conv_thread)
timer = @conv_threads_timers[conv_thread.id]
EventMachine.cancel_timer(timer) unless timer.nil?
@conv_threads_timers[conv_thread.id] = nil
@conv_threads_timers_manage.synchronize do
timer = @conv_threads_timers[conv_thread.id]
EventMachine.cancel_timer(timer) unless timer.nil?
@conv_threads_timers[conv_thread.id] = nil
end
end
# check for idleness at connection level: not only actions done in a thread,
......
# ignore system thread
return if conv_thread.name == "system"
# if a timer is running, do nothing
return unless @conv_threads_timers[conv_thread.id].nil?
# test for idleness
return unless conv_thread.idle?
logger.debug "Thread '#{conv_thread.name}@#{@peer_name}' is currently idle, doing another check in #{@auto_close_threads}s"
@conv_threads_timers_manage.synchronize do
# if a timer is running, do nothing
return unless @conv_threads_timers[conv_thread.id].nil?
# send notification
@bot.get_channel(@system_notification_name) << {
:topic => 'THREAD IDLE',
:thread => conv_thread.name
}
# set timer for closing
@conv_threads_timers[conv_thread.id] = EventMachine.add_timer(@auto_close_threads) do
@conv_threads_timers[conv_thread.id] = nil
# if it is not idle, then do nothing, wait for another call to check_idle_thread
# test for idleness
if conv_thread.idle?
logger.debug "Thread '#{conv_thread.name}@#{@peer_name}' is still idle, closing"
close_thread(conv_thread.name)
else
logger.debug "Thread '#{conv_thread.name}@#{@peer_name}' is no more idle"
end
end
logger.debug "Thread '#{conv_thread.name}@#{@peer_name}' is currently idle, doing another check in #{@auto_close_threads}s"
# send notification
@bot.get_channel(@system_notification_name) << {
:topic => 'THREAD IDLE',
:thread => conv_thread.name
}
# set timer for closing
@conv_threads_timers[conv_thread.id] = EventMachine.add_timer(@auto_close_threads) do
@conv_threads_timers[conv_thread.id] = nil
# if it is not idle, then do nothing, wait for another call to check_idle_thread
if conv_thread.idle?
logger.debug "Thread '#{conv_thread.name}@#{@peer_name}' is still idle, closing"
close_thread(conv_thread.name)
else
logger.debug "Thread '#{conv_thread.name}@#{@peer_name}' is no more idle"
end
end
end # if idle
end # sync
end
end
end #Conversation
end

Also available in: Unified diff