diff --git a/src/main/java/ortus/boxlang/runtime/application/Application.java b/src/main/java/ortus/boxlang/runtime/application/Application.java index 80669f066..5a1d7a242 100644 --- a/src/main/java/ortus/boxlang/runtime/application/Application.java +++ b/src/main/java/ortus/boxlang/runtime/application/Application.java @@ -98,7 +98,7 @@ public class Application { /** * Application cache key filter */ - private final ICacheKeyFilter cacheFilter; + private ICacheKeyFilter cacheFilter; /** * Static strings for comparison @@ -141,11 +141,20 @@ public class Application { * @param name The name of the application */ public Application( Key name ) { - this.name = name; + this.name = name; + prepApplication(); + } + + /** + * Called to prep an application before starting + * Used to encapsulate and to use it from the constructor and restarts + */ + private void prepApplication() { this.cacheFilter = new PrefixFilter( this.name.getName() ); - this.applicationScope = new ApplicationScope(); // Startup the interceptor pool for this application this.interceptorPool = new InterceptorPool( this.name ); + // Create the application scope + this.applicationScope = new ApplicationScope(); } /** @@ -364,14 +373,19 @@ public synchronized void restart( IBoxContext context ) { BoxRuntime.getInstance().getInterceptorService().announce( Key.onApplicationRestart, Struct.of( "application", this ) ); - shutdown(); + shutdown( true ); + // call the constructor + prepApplication(); + // Start the application again start( context ); } /** * Shutdown this application + * + * @param force If true, forces the shutdown of the scheduler */ - public synchronized void shutdown() { + public synchronized void shutdown( boolean force ) { // If the app has already been shutdown, don't do it again4 if ( !hasStarted() ) { logger.debug( "Can't shutdown application [{}] as it's already shutdown", this.name ); @@ -405,10 +419,10 @@ public synchronized void shutdown() { } // Clear out the data + this.started = false; this.sessionsCache.clearAll( cacheFilter ); this.applicationScope = null; this.startTime = null; - this.started = false; this.interceptorPool = null; logger.debug( "Application.shutdown() - {}", this.name ); diff --git a/src/main/java/ortus/boxlang/runtime/context/ApplicationBoxContext.java b/src/main/java/ortus/boxlang/runtime/context/ApplicationBoxContext.java index 77dc172e9..c116ae64d 100644 --- a/src/main/java/ortus/boxlang/runtime/context/ApplicationBoxContext.java +++ b/src/main/java/ortus/boxlang/runtime/context/ApplicationBoxContext.java @@ -147,7 +147,7 @@ public Application getApplication() { public void updateApplication( Application application ) { this.application = application; this.applicationScope = application.getApplicationScope(); - applicationScope.put( Key.applicationName, application.getName() ); + this.applicationScope.put( Key.applicationName, application.getName() ); } } diff --git a/src/main/java/ortus/boxlang/runtime/services/ApplicationService.java b/src/main/java/ortus/boxlang/runtime/services/ApplicationService.java index 299fa354b..a44062be7 100644 --- a/src/main/java/ortus/boxlang/runtime/services/ApplicationService.java +++ b/src/main/java/ortus/boxlang/runtime/services/ApplicationService.java @@ -146,7 +146,7 @@ public void removeApplication( Key name ) { public void shutdownApplication( Key name ) { Application thisApp = this.applications.get( name ); if ( thisApp != null ) { - thisApp.shutdown(); + thisApp.shutdown( false ); this.applications.remove( name ); } @@ -199,7 +199,7 @@ public void onStartup() { @Override public void onShutdown( Boolean force ) { // loop over applications and shutdown as the runtime is going down. - this.applications.values().parallelStream().forEach( Application::shutdown ); + this.applications.values().parallelStream().forEach( app -> app.shutdown( force ) ); } /**