module Bio::TogoWS::AccessWait
Internal Use Only.
Bio::TogoWS::AccessWait
is a module to implement a private method for access.
Constants
- TOGOWS_ACCESS_WAIT
common default access wait for
TogoWS
services- TOGOWS_ACCESS_WAIT_MAX
Maximum waiting time to avoid dead lock. When exceeding this value, (max/2) + rand(max) is used, to randomize access. This means real maximum waiting time is (max * 1.5).
Private Instance Methods
reset_togows_access_wait()
click to toggle source
(private) resets last access. Should be used only for debug purpose.
# File lib/bio/io/togows.rb 91 def reset_togows_access_wait 92 @@togows_last_access = nil 93 end
togows_access_wait()
click to toggle source
Sleeping if needed. It sleeps about TOGOWS_ACCESS_WAIT
* (number of waiting processes).
- Returns
-
(Numeric) sleeped time
# File lib/bio/io/togows.rb 45 def togows_access_wait 46 w_min = TOGOWS_ACCESS_WAIT 47 debug = defined?(@debug) && @debug 48 49 # initializing class variable 50 @@togows_last_access ||= nil 51 52 # determines waiting time 53 wait = 0 54 if last = @@togows_last_access then 55 elapsed = Time.now - last 56 if elapsed < w_min then 57 wait = w_min - elapsed 58 end 59 end 60 61 # If wait is too long, truncated to TOGOWS_ACCESS_WAIT_MAX. 62 if wait > TOGOWS_ACCESS_WAIT_MAX then 63 orig_wait = wait 64 wait = TOGOWS_ACCESS_WAIT_MAX 65 wait = wait / 2 + rand(wait) 66 if debug then 67 $stderr.puts "TogoWS: sleeping time #{orig_wait} is too long and set to #{wait} to avoid dead lock." 68 end 69 newlast = Time.now + TOGOWS_ACCESS_WAIT_MAX 70 else 71 newlast = Time.now + wait 72 end 73 74 # put expected end time of sleeping 75 if !@@togows_last_access or @@togows_last_access < newlast then 76 @@togows_last_access = newlast 77 end 78 79 # sleeping if needed 80 if wait > 0 then 81 $stderr.puts "TogoWS: sleeping #{wait} second" if debug 82 sleep(wait) 83 end 84 # returns waited time 85 wait 86 end