<commit_before>package brooklyn.launcher

import org.slf4j.Logger
import org.slf4j.LoggerFactory

import brooklyn.entity.basic.AbstractApplication
import brooklyn.launcher.WebAppRunner
import brooklyn.management.internal.AbstractManagementContext

class BrooklynLauncher {
    protected static final Logger LOG = LoggerFactory.getLogger(BrooklynLauncher.class)
    
    public static void manage(AbstractApplication app, int port=8081) {
        // Locate the management context
        AbstractManagementContext context = app.getManagementContext()
        context.manage(app)

        // Start the web console service
        WebAppRunner web
        try {
            web = new WebAppRunner(context, port)
            web.start()
        } catch (Exception e) {
            LOG.warn("Failed to start Brooklyn web-console", e)
        }

        addShutdownHook {
            LOG.info("Brooklyn launcher's shutdown-hook invoked: shutting down application")
            app?.stop()
        }
        //do these in parallel on shutdown; whilst it would be nice to watch the application closing
        //in the browser, spring is also listening to the shutdown hook so leaving the server up just
        //causes lots of stack trace messages if a browser is trying to hit it!
        addShutdownHook {
            LOG.info("Brooklyn launcher's shutdown-hook invoked: shutting down web-console")
            web?.stop()
        }
    }
}<commit_msg>BrooklynLauncher's shutdown hook: make configurable whether to shutdown app<commit_after>package brooklyn.launcher

import org.slf4j.Logger
import org.slf4j.LoggerFactory

import brooklyn.entity.basic.AbstractApplication
import brooklyn.launcher.WebAppRunner
import brooklyn.management.internal.AbstractManagementContext

class BrooklynLauncher {
    protected static final Logger LOG = LoggerFactory.getLogger(BrooklynLauncher.class)
    
    public static void manage(AbstractApplication app, int port=8081, shutdownApp=true) {
        // Locate the management context
        AbstractManagementContext context = app.getManagementContext()
        context.manage(app)

        // Start the web console service
        WebAppRunner web
        try {
            web = new WebAppRunner(context, port)
            web.start()
        } catch (Exception e) {
            LOG.warn("Failed to start Brooklyn web-console", e)
        }

		if (shutdownApp) {
	        addShutdownHook {
	            LOG.info("Brooklyn launcher's shutdown-hook invoked: shutting down application")
	            app?.stop()
	        }
		}
		
        //do these in parallel on shutdown; whilst it would be nice to watch the application closing
        //in the browser, spring is also listening to the shutdown hook so leaving the server up just
        //causes lots of stack trace messages if a browser is trying to hit it!
        addShutdownHook {
            LOG.info("Brooklyn launcher's shutdown-hook invoked: shutting down web-console")
            web?.stop()
        }
    }
}
{'fraction_non_alphanumeric': 0.0678191489361702, 'fraction_numerical': 0.003989361702127659, 'mean_word_length': 2.6384522370012093, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6347405', 'n_tokens_mistral': 794, 'n_tokens_neox': 750, 'n_words': 255}