class Qwik::EventListener

Constants

MAX_LISTENER
TIMEOUT

Public Class Methods

new(config) click to toggle source
# File vendor/qwik/lib/qwik/site-event.rb, line 28
def initialize(config)
  @config = config
  @listener = []
end

Public Instance Methods

add_listener(action) click to toggle source
# File vendor/qwik/lib/qwik/site-event.rb, line 33
def add_listener(action)
  check_timeout
  if MAX_LISTENER <= @listener.length
    kickout(@listener[0], 'max_exceed')
    raise ListenerMaxExceed                # failed to add
  end
  @listener << action
end
check_timeout() click to toggle source
# File vendor/qwik/lib/qwik/site-event.rb, line 60
def check_timeout
  now = Time.now
  now = Time.at(0) if $test
  check_timeout_internal(@listener, now)
end
check_timeout_internal(listener, now) click to toggle source
# File vendor/qwik/lib/qwik/site-event.rb, line 66
def check_timeout_internal(listener, now)
  listener.each {|action|
    time = action.get_start_time
    if TIMEOUT < (now - time)
      kickout(action, 'timeout')
    end
  }
end
each_listener(target_sitename) { |action| ... } click to toggle source
# File vendor/qwik/lib/qwik/site-event.rb, line 51
def each_listener(target_sitename)
  check_timeout
  @listener.each {|action|
    if action.get_sitename == target_sitename
      yield(action)
    end
  }
end
kickout(action, reason) click to toggle source
# File vendor/qwik/lib/qwik/site-event.rb, line 42
def kickout(action, reason)
  @listener.delete(action)
  action.event_disconnect(reason)
end
success(action) click to toggle source
# File vendor/qwik/lib/qwik/site-event.rb, line 47
def success(action)
  @listener.delete(action)
end