4141import com .typesafe .config .Config ;
4242import edu .umd .cs .findbugs .annotations .NonNull ;
4343import edu .umd .cs .findbugs .annotations .Nullable ;
44- import io .jooby .buffer .BufferedOutputFactory ;
4544import io .jooby .exception .RegistryException ;
4645import io .jooby .exception .StartupException ;
4746import io .jooby .internal .LocaleUtils ;
4847import io .jooby .internal .MutedServer ;
4948import io .jooby .internal .RegistryRef ;
5049import io .jooby .internal .RouterImpl ;
50+ import io .jooby .output .OutputFactory ;
5151import io .jooby .problem .ProblemDetailsHandler ;
5252import io .jooby .value .ValueFactory ;
5353
@@ -80,18 +80,19 @@ public class Jooby implements Router, Registry {
8080 static final String APP_NAME = "___app_name__" ;
8181
8282 private static final String JOOBY_RUN_HOOK = "___jooby_run_hook__" ;
83+ private static final Logger log = LoggerFactory .getLogger (Jooby .class );
8384
8485 private final transient AtomicBoolean started = new AtomicBoolean (true );
8586
8687 private final transient AtomicBoolean stopped = new AtomicBoolean (false );
8788
8889 private static Jooby owner ;
8990 private static ExecutionMode BOOT_EXECUTION_MODE = ExecutionMode .DEFAULT ;
90- private static BufferedOutputFactory BUFFER_FACTORY ;
91+ private static OutputFactory OUTPUT_FACTORY ;
9192
9293 private RouterImpl router ;
9394
94- private ExecutionMode mode = BOOT_EXECUTION_MODE ;
95+ private ExecutionMode mode ;
9596
9697 private Path tmpdir ;
9798
@@ -125,6 +126,7 @@ public class Jooby implements Router, Registry {
125126 public Jooby () {
126127 if (owner == null ) {
127128 ClassLoader classLoader = getClass ().getClassLoader ();
129+ mode = BOOT_EXECUTION_MODE ;
128130 environmentOptions = new EnvironmentOptions ().setClassLoader (classLoader );
129131 router = new RouterImpl ();
130132 stopCallbacks = new LinkedList <>();
@@ -133,8 +135,7 @@ public Jooby() {
133135 lateExtensions = new ArrayList <>();
134136 // NOTE: fallback to default, this is required for direct instance creation of class
135137 // app bootstrap always ensures server instance.
136- router .setOutputFactory (
137- Optional .ofNullable (BUFFER_FACTORY ).orElseGet (BufferedOutputFactory ::create ));
138+ router .setOutputFactory (Optional .ofNullable (OUTPUT_FACTORY ).orElseGet (OutputFactory ::create ));
138139 } else {
139140 copyState (owner , this );
140141 }
@@ -845,7 +846,7 @@ public Jooby setValueFactory(@NonNull ValueFactory valueFactory) {
845846 }
846847
847848 @ NonNull @ Override
848- public BufferedOutputFactory getOutputFactory () {
849+ public OutputFactory getOutputFactory () {
849850 return router .getOutputFactory ();
850851 }
851852
@@ -903,9 +904,7 @@ public Jooby setStartupSummary(List<StartupSummary> startupSummary) {
903904 Path tmpdir = getTmpdir ();
904905 ensureTmpdir (tmpdir );
905906
906- if (mode == null ) {
907- mode = ExecutionMode .DEFAULT ;
908- }
907+ log .trace ("initialization context static variables {} {}" , Context .RFC1123 , Context .GMT );
909908
910909 if (locales == null ) {
911910 String path = AvailableSettings .LANG ;
@@ -1253,18 +1252,14 @@ public static void runApp(
12531252 var apps = new ArrayList <Jooby >();
12541253 var targetServer = server .getLoggerOff ().isEmpty () ? server : MutedServer .mute (server );
12551254 try {
1255+ // Init context static var
12561256 for (var factory : provider ) {
12571257 var app = createApp (server , executionMode , factory );
12581258 /*
12591259 When running a single app instance, there is no issue with server options, when multiple
12601260 apps set options a warning will be printed
12611261 */
1262- ServerOptions .from (app .getConfig ())
1263- .ifPresent (
1264- options -> {
1265- options .setServer (server .getName ());
1266- server .setOptions (options );
1267- });
1262+ ServerOptions .from (app .getConfig ()).ifPresent (server ::setOptions );
12681263 apps .add (app );
12691264 }
12701265
@@ -1305,12 +1300,12 @@ public static Jooby createApp(
13051300
13061301 Jooby app ;
13071302 try {
1308- Jooby .BUFFER_FACTORY = server .getOutputFactory ();
1303+ Jooby .OUTPUT_FACTORY = server .getOutputFactory ();
13091304 Jooby .BOOT_EXECUTION_MODE = executionMode ;
13101305 app = provider .get ();
13111306 } finally {
13121307 Jooby .BOOT_EXECUTION_MODE = executionMode ;
1313- Jooby .BUFFER_FACTORY = null ;
1308+ Jooby .OUTPUT_FACTORY = null ;
13141309 }
13151310
13161311 return app ;
0 commit comments