Skip to content

Commit

Permalink
fixing chicken egg issues with app only for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lmajano committed Jun 5, 2024
1 parent d56d512 commit 3aebcd8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
26 changes: 20 additions & 6 deletions src/main/java/ortus/boxlang/runtime/application/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public class Application {
/**
* Application cache key filter
*/
private final ICacheKeyFilter cacheFilter;
private ICacheKeyFilter cacheFilter;

/**
* Static strings for comparison
Expand Down Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand Down Expand Up @@ -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 ) );
}

/**
Expand Down

0 comments on commit 3aebcd8

Please sign in to comment.