module HeartBeat

this file is part of manqod manqod is distributed under the CDDL licence the author of manqod is Dobai-Pataky Balint(dpblnt@gmail.com)

Public Instance Methods

init_HeartBeat() click to toggle source
# File lib/HeartBeat.rb, line 6
def init_HeartBeat
        @heartbeat_thread=Thread.new{
                lalive_clients=-1
                lalive_client_lists=-1
                loop do
                        begin
                                sleep 10
                                to_remove=Array.new
                                alive_clients=0
                                @connected_clients.delete_if{|client_id,cdb|
                                        begin
                                                Timeout.timeout(30){
                                                        #ecode("#{cc}.alive?:#{cc.alive?}")
                                                        cdb[:object].alive?
                                                        alive_clients+=1
                                                        false
                                                }
                                        rescue Timeout::Error
                                                ewarn("client timed out, removing a dead client #{client_id}")
                                                true
                                        rescue => err
                                                ewarn("removing a dead client #{client_id}")
                                                @dbs.each_value{|db|
                                                        db.remove_client(client_id) unless db.serving?
                                                }
                                                true
                                        end
                                }

                                alive_client_lists=0
                                @dbs.each_value{|db|
                                        next unless db.serving?
                                        #keep the conenction to the cache alive
                                        db.cache.set("alive",Time.new)
                                        #check for alive client list subscriptions
                                        alive_client_lists+=db.remove_dead_clients
                                }
                                einfo("#{alive_clients} clients, #{alive_client_lists} subscriptions") unless alive_clients==lalive_clients && alive_client_lists==lalive_client_lists

                                lalive_clients=alive_clients
                                lalive_client_lists=alive_client_lists
                        rescue ECONNREFUSED => err
                                eerror("HeartBeat: #{err}")
                        rescue =>err
                                eexception(err)
                        end
                end
        }
        einfo("HeartBeat started")
end
stop_HeartBeat() click to toggle source
# File lib/HeartBeat.rb, line 56
def stop_HeartBeat
        @heartbeat_thread.kill if @heartbeat_thread
        einfo("HeartBeat stopped")
end