Changeset 198
- Timestamp:
- 03/09/07 17:35:21 (2 years ago)
- Files:
-
- trunk/lib/merb/merb_dispatcher.rb (modified) (2 diffs)
- trunk/lib/merb/merb_handler.rb (modified) (2 diffs)
- trunk/lib/merb/merb_server.rb (modified) (3 diffs)
- trunk/specs/merb/merb_dispatch_spec.rb (modified) (43 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/merb/merb_dispatcher.rb
r193 r198 6 6 attr_accessor :path_prefix 7 7 8 @@mutex = Mutex.new 9 @@use_mutex = ::Merb::Server.use_mutex 8 10 # This is where we grab the incoming request PATH_INFO 9 11 # and use that in the merb routematcher to determine … … 19 21 rest = route.delete(:rest) 20 22 21 controller = instantiate_controller(route[:controller], request.body, request.params, route, response)23 controller = instantiate_controller(route[:controller], request.body, request.params, route, response) 22 24 23 25 if rest 24 26 method = controller.request.method 25 if allowed.keys.include?(method) 26 controller.params[:action] = allowed[method] 27 [controller, allowed[method]] 27 if allowed.keys.include?(method) && action = allowed[method] 28 controller.params[:action] = action 28 29 else 29 30 raise Merb::RestfulMethodNotAllowed.new(method, allowed) 30 31 end 31 32 else 32 [controller, route[:action]]33 action = route[:action] 33 34 end 35 if @@use_mutex 36 @@mutex.synchronize { 37 controller.dispatch(action) 38 } 39 else 40 controller.dispatch(action) 41 end 42 [controller, action] 34 43 end 35 44 trunk/lib/merb/merb_handler.rb
r174 r198 20 20 def initialize(dir, opts = {}) 21 21 @files = Mongrel::DirHandler.new(dir,false) 22 @guard = Mutex.new23 22 end 24 23 … … 64 63 else 65 64 begin 66 # This handles parsing the query string and post/file upload 67 # params and is outside of the synchronize call so that 68 # multiple file uploads can be done at once. 65 # dLet Merb:Dispatcher find the route and call the filter chain and action 69 66 controller = nil 70 67 controller, action = Merb::Dispatcher.handle(request, response) 71 68 72 69 MERB_LOGGER.info("Routing to controller: #{controller.class} action: #{action}\nRoute Recognition & Parsing HTTP Input took: #{Time.now - start} seconds") 73 74 # We need a mutex here because ActiveRecord code can be run75 # in your controller actions. AR performs much better in single76 # threaded mode so we lock here for the shortest amount of time77 # possible. Route recognition and mime parsing has already occured78 # at this point because those processes are thread safe. This79 # gives us the best trade off for multi threaded performance80 # of thread safe code paths, and the smallest lock possible81 # around calls to your controller actions.82 @guard.synchronize {83 controller.dispatch(action)84 }85 70 rescue Object => e 86 71 response.start(500) do |head,out| trunk/lib/merb/merb_server.rb
r197 r198 15 15 :allow_reloading => true, 16 16 :merb_root => Dir.pwd, 17 :cache_templates => false 17 :cache_templates => false, 18 :use_mutex => true 18 19 } 19 20 begin … … 35 36 36 37 opts = OptionParser.new do |opts| 37 opts.banner = "Usage: merb [fdcepghmislu G] [argument]"38 opts.banner = "Usage: merb [fdcepghmisluMG] [argument]" 38 39 opts.define_head "Merb Mongrel+ Erb. Lightweight replacement for ActionPack" 39 40 opts.separator '*'*80 … … 101 102 opts.on("-M", "--merb-config FILENAME", "This flag is for explicitly declaring the merb app's config file") do |config| 102 103 options[:merb_config] = config 104 end 105 106 opts.on("-X", "--mutex on/off", "This flag is for turnhing on and off the mutex lock.") do |mutex| 107 if mutex == 'off' 108 options[:use_mutex] = false 109 else 110 options[:use_mutex] = true 111 end 103 112 end 104 113 trunk/specs/merb/merb_dispatch_spec.rb
r194 r198 220 220 controller.class.should == Foo 221 221 action.should == "bar" 222 controller.dispatch(action)223 222 controller.body.should == "bar" 224 223 end … … 228 227 controller.class.should == Icon 229 228 action.should == "show" 230 controller.dispatch(action)231 229 controller.body.should == :show 232 230 end … … 237 235 action.should == "show" 238 236 controller.params[:format].should == 'xml' 239 controller.dispatch(action)240 237 controller.body.should == :show 241 238 end … … 245 242 controller.class.should == Icon 246 243 action.should == "new" 247 controller.dispatch(action)248 244 controller.body.should == :new 249 245 end … … 253 249 controller.class.should == Icon 254 250 action.should == "edit" 255 controller.dispatch(action)256 251 controller.body.should == :edit 257 252 end … … 261 256 controller.class.should == Icon 262 257 action.should == "create" 263 controller.dispatch(action)264 258 controller.body.should == :create 265 259 end … … 269 263 controller.class.should == Icon 270 264 action.should == "update" 271 controller.dispatch(action)272 265 controller.body.should == :update 273 266 end … … 277 270 controller.class.should == Icon 278 271 action.should == "destroy" 279 controller.dispatch(action)280 272 controller.body.should == :destroy 281 273 end … … 285 277 controller.class.should == Tags 286 278 action.should == "index" 287 controller.dispatch(action)288 279 controller.body.should == :index 289 280 end … … 294 285 action.should == "index" 295 286 controller.params[:format].should == 'xml' 296 controller.dispatch(action)297 287 controller.body.should == :index 298 288 end … … 302 292 controller.class.should == Posts 303 293 action.should == "index" 304 controller.dispatch(action)305 294 controller.body.should == :index 306 295 end … … 310 299 controller.class.should == Posts 311 300 action.should == "filter" 312 controller.dispatch(action)313 301 controller.body.should == :filter 314 302 end … … 318 306 controller.class.should == Comments 319 307 action.should == "index" 320 controller.dispatch(action)321 308 controller.body.should == :index 322 309 end … … 326 313 controller.class.should == Profile 327 314 action.should == "show" 328 controller.dispatch(action)329 315 controller.body.should == :show 330 316 end … … 335 321 controller.params[:format].should == 'xml' 336 322 action.should == "show" 337 controller.dispatch(action)338 323 controller.body.should == :show 339 324 end … … 344 329 controller.params[:format].should == 'xml' 345 330 action.should == "index" 346 controller.dispatch(action)347 331 controller.body.should == :index 348 332 end … … 353 337 action.should == "show" 354 338 controller.params[:id].should == '1' 355 controller.dispatch(action)356 339 controller.body.should == :show 357 340 end … … 363 346 controller.params[:post_id].should == '1' 364 347 action.should == "show" 365 controller.dispatch(action)366 348 controller.body.should == :show 367 349 end … … 373 355 controller.params[:a_id].should == '1' 374 356 action.should == "show" 375 controller.dispatch(action)376 357 controller.body.should == :show 377 358 end … … 383 364 controller.params[:a_id].should == '1' 384 365 action.should == "index" 385 controller.dispatch(action)386 366 controller.body.should == :index 387 367 end … … 394 374 controller.params[:b_id].should == '1' 395 375 action.should == "show" 396 controller.dispatch(action)397 376 controller.body.should == :show 398 377 end … … 404 383 action.should == "show" 405 384 controller.params[:id].should == '1' 406 controller.dispatch(action)407 385 controller.body.should == :show 408 386 end … … 415 393 controller.params[:post_id].should == '1' 416 394 action.should == "show" 417 controller.dispatch(action)418 395 controller.body.should == :show 419 396 end … … 423 400 controller.class.should == Posts 424 401 action.should == "new" 425 controller.dispatch(action)426 402 controller.body.should == :new 427 403 end … … 431 407 controller.class.should == Comments 432 408 action.should == "new" 433 controller.dispatch(action)434 409 controller.body.should == :new 435 410 end … … 440 415 action.should == "edit" 441 416 controller.params[:id].should == '1' 442 controller.dispatch(action)443 417 controller.body.should == :edit 444 418 end … … 450 424 controller.params[:post_id].should == '1' 451 425 action.should == "edit" 452 controller.dispatch(action)453 426 controller.body.should == :edit 454 427 end … … 458 431 controller.class.should == Posts 459 432 action.should == "create" 460 controller.dispatch(action)461 433 controller.body.should == :create 462 434 end … … 466 438 controller.class.should == Comments 467 439 action.should == "create" 468 controller.dispatch(action)469 440 controller.body.should == :create 470 441 end … … 475 446 controller.params[:format].should == 'xml' 476 447 action.should == "create" 477 controller.dispatch(action)478 448 controller.body.should == :create 479 449 end … … 485 455 controller.params[:format].should == 'xml' 486 456 action.should == "create" 487 controller.dispatch(action)488 457 controller.body.should == :create 489 458 end … … 494 463 action.should == "update" 495 464 controller.params[:id].should == '1' 496 controller.dispatch(action)497 465 controller.body.should == :update 498 466 end … … 504 472 controller.params[:post_id].should == '1' 505 473 controller.params[:id].should == '1' 506 controller.dispatch(action)507 474 controller.body.should == :update 508 475 end … … 514 481 controller.params[:id].should == '1' 515 482 action.should == "update" 516 controller.dispatch(action)517 483 controller.body.should == :update 518 484 end … … 525 491 controller.params[:format].should == 'xml' 526 492 controller.params[:id].should == '1' 527 controller.dispatch(action)528 493 controller.body.should == :update 529 494 end … … 534 499 controller.params[:id].should == '1' 535 500 action.should == "destroy" 536 controller.dispatch(action)537 501 controller.body.should == :destroy 538 502 end … … 544 508 controller.params[:post_id].should == '1' 545 509 action.should == "destroy" 546 controller.dispatch(action)547 510 controller.body.should == :destroy 548 511 end … … 554 517 controller.params[:id].should == '1' 555 518 action.should == "destroy" 556 controller.dispatch(action)557 519 controller.body.should == :destroy 558 520 end … … 565 527 controller.params[:post_id].should == '1' 566 528 action.should == "destroy" 567 controller.dispatch(action)568 529 controller.body.should == :destroy 569 530 end … … 574 535 action.should == 'stats' 575 536 controller.params[:id].should == '1' 576 controller.dispatch(action)577 537 controller.body.should == :stats 578 538 end … … 584 544 controller.params[:id].should == '1' 585 545 controller.params[:post_id].should == '1' 586 controller.dispatch(action)587 546 controller.body.should == :stats 588 547 end … … 593 552 action.should == 'stats' 594 553 controller.params[:id].should == '1' 595 controller.dispatch(action)596 554 controller.body.should == :stats 597 555 end … … 603 561 controller.params[:id].should == '1' 604 562 controller.params[:post_id].should == '1' 605 controller.dispatch(action)606 563 controller.body.should == :stats 607 564 end
