class Swee::AppExecutor

Constants

DEFAULT_THTEADS

Public Class Methods

execute_after_filter(controller_intance,route) click to toggle source

执行后置过滤器

# File lib/swee/app_executor.rb, line 50
def execute_after_filter controller_intance,route
  execute_filter :after, controller_intance, route
end
execute_before_filter(controller_intance,route) click to toggle source

执行前置过滤器

# File lib/swee/app_executor.rb, line 45
def execute_before_filter controller_intance,route
  execute_filter :before, controller_intance, route
end
execute_controller(controller_intance,action) click to toggle source

执行控制器

# File lib/swee/app_executor.rb, line 55
def execute_controller controller_intance,action
  result = controller_intance.send(action)
  result.freeze
  result
end
execute_filter(_type, controller_intance,route) click to toggle source

执行过滤器

# File lib/swee/app_executor.rb, line 62
def execute_filter _type, controller_intance,route
  _filter_actions = Controller.find_filter_methods route.controller_name,_type,route.action
  _filter_actions.each do |_action|
    controller_intance.send _action
  end
end
new() click to toggle source
# File lib/swee/app_executor.rb, line 122
def initialize
  @queue = []
  @threadpoll = Array.new
  DEFAULT_THTEADS.times do
    @threadpoll << ExeThread.new
  end
end
path_to_route(env) click to toggle source

app_path转路由 获取 路由结构

# File lib/swee/app_executor.rb, line 22
def path_to_route env
  _path_info = env["PATH_INFO"]
  Routes.tables[_path_info.to_s]
end
rack_responsed?(result) click to toggle source

检测是否为 rack 格式得响应 rack标准格式: [status,headers,]

# File lib/swee/app_executor.rb, line 71
def rack_responsed? result
  if result.is_a?(Array) && result.size == 3
     status =  result[0]
    headers =  result[1]
       body =  result[2]
    if status.is_a?(Integer) && headers.is_a?(Hash) && body.respond_to?(:each)
      return true
    end
  end
  return false
end
render_view(controller_intance, route) click to toggle source

渲染视图 渲染 -> 前置 后置 环绕控制器

# File lib/swee/app_executor.rb, line 37
def render_view controller_intance, route
  execute_before_filter controller_intance, route
  result = execute_controller controller_intance, route.action
  execute_after_filter controller_intance, route
  return !rack_responsed?(result) ? controller_intance.render : result
end
route_to_controller(route, env) click to toggle source

执行 app controller 方法

# File lib/swee/app_executor.rb, line 28
def route_to_controller route, env
  controller = route.controller
  controller_intance = route.create_controller_instance
  controller_intance.warp_request env,route
  controller_intance
end
run(env) click to toggle source

启动 app 渲染器 app_path 转路由 执行 app controller 方法 渲染 filter (:before, :after, :round) 生成 View

# File lib/swee/app_executor.rb, line 10
def run env
  route = path_to_route(env)
  request_method = env["REQUEST_METHOD"].downcase.to_sym
  if route.nil? || !route.request_methods.include?(request_method)
    return View.render_404
  end
  controller_intance = route_to_controller route, env
  render_view controller_intance, route
end

Public Instance Methods

<<() click to toggle source
# File lib/swee/app_executor.rb, line 148
def <<()
  @queue.push()
end
current_thread() click to toggle source
# File lib/swee/app_executor.rb, line 130
def current_thread
  _current_thread = @threadpoll.select { |t| !t.busy? }
end
run() click to toggle source
# File lib/swee/app_executor.rb, line 134
def run
  f = Fiber.new do
    while true
      Fiber.yield
    end
  end
end
wait() click to toggle source
# File lib/swee/app_executor.rb, line 142
def wait
  while exist_alive_thread?
    sleep 0.1
  end
end