@@ -401,6 +401,175 @@ The javadoc:Jooby[mvc, javax.inject.Provider] does the same job, might or might
401401instantiation to a dependency injection framework but most important let you control lifecycle of
402402MVC routes (Singleton vs Non-Singleton routes).
403403
404+ === Execution model
405+
406+ The MVC routes follows the execution model described in <<Execution Model>>. To run application
407+ logic in the javadoc:ExecutionMode[EVENT_LOOP]:
408+
409+ .EventLoop MVC route
410+ [source, java, role = "primary"]
411+ ----
412+
413+ public class App extends Jooby {
414+ {
415+ mvc(new MyController());
416+ }
417+
418+ public static void main(String[] args) {
419+ runApp(args, EVENT_LOOP, App::new); <1>
420+ }
421+ }
422+ ----
423+
424+ .Kotlin
425+ [source, kotlin, role = "secondary"]
426+ ----
427+ import io.jooby.*
428+
429+ fun main(args: Array<String>) {
430+ runApp(args, EVENT_LOOP) { <1>
431+ mvc(MyController())
432+ }
433+ }
434+ ----
435+
436+ <1> Start the application in the EVENT_LOOP execution mode
437+
438+ Similarly, if you need to run all mvc routes in the javadoc:ExecutionMode[WORKER] execution mode:
439+
440+ .Worker mode MVC route
441+ [source, java, role = "primary"]
442+ ----
443+
444+ public class App extends Jooby {
445+ {
446+ dispatch(() -> {
447+ mvc(new MyBlockingController()); <1>
448+ });
449+ }
450+
451+ public static void main(String[] args) {
452+ runApp(args, EVENT_LOOP, App::new);
453+ }
454+ }
455+ ----
456+
457+ .Kotlin
458+ [source, kotlin, role = "secondary"]
459+ ----
460+ import io.jooby.*
461+
462+ fun main(args: Array<String>) {
463+ runApp(args, EVENT_LOOP) {
464+ dispatch {
465+ mvc(MyBlockingController()) <1>
466+ }
467+ }
468+ }
469+ ----
470+
471+ <1> Wrap the controller using the dispatch operator
472+
473+ One drawback with this approach is that the entire controller is now going to be executed in the worker or custom executor.
474+ For more fine grain control use the javadoc:annotations.Dispatch[] annotation:
475+
476+ .Dispatch annotation
477+ [source, java, role = "primary"]
478+ ----
479+
480+ public class MyController {
481+ @GET("/nonblocking")
482+ public String nonblocking() { <1>
483+ return "I'm nonblocking";
484+ }
485+
486+ @GET("/blocking")
487+ @Dispatch
488+ public String blocking() { <2>
489+ return "I'm blocking";
490+ }
491+ }
492+ ----
493+
494+ .Kotlin
495+ [source, kotlin, role = "secondary"]
496+ ----
497+ import io.jooby.annotations.*
498+
499+ class MyController {
500+
501+ @GET("/nonblocking")
502+ fun nonblocking() : String { <1>
503+ return "I'm nonblocking";
504+ }
505+
506+ @GET("/blocking")
507+ @Dispatch
508+ fun blocking() : String { <2>
509+ return "I'm blocking";
510+ }
511+ }
512+ ----
513+
514+ <1> MVC route run in EVENT_LOOP mode. Blocking is NOT allowed it.
515+ <2> MVC route run in WORKER mode. Blocking is allowed it.
516+
517+ The javadoc:annotations.Dispatch[] annotation supports custom executor using an executor name.
518+
519+ .Dispatch to custom executor
520+ [source, java, role = "primary"]
521+ ----
522+
523+ public class MyController {
524+ @GET("/blocking")
525+ @Dispatch("single") <1>
526+ public String blocking() {
527+ return "I'm blocking";
528+ }
529+ }
530+ ----
531+
532+ .Kotlin
533+ [source, kotlin, role = "secondary"]
534+ ----
535+ import io.jooby.annotations.*
536+
537+ class MyController {
538+
539+ @GET("/blocking")
540+ @Dispatch("single") <1>
541+ fun blocking() : String {
542+ return "I'm blocking";
543+ }
544+ }
545+ ----
546+
547+ <1> Dispatch to an executor named it `single`
548+
549+ Executor must be registered using via services or executor utility method:
550+
551+ .Custom executor registration
552+ [source, java, role = "primary"]
553+ ----
554+ {
555+ executor("single", Executors.newSingleThreadExecutor());
556+
557+ mvc(new MyController());
558+ }
559+ ----
560+
561+ .Kotlin
562+ [source, kotlin, role = "secondary"]
563+ ----
564+ {
565+ executor("single", Executors.newSingleThreadExecutor())
566+
567+ mvc(MyController())
568+ }
569+ ----
570+
571+ The executor must be registered before the MVC route/controller.
572+
404573=== Suspend functions
405574
406575For Kotlin users MVC routes are allowed to use suspend functions
0 commit comments