Example usage for org.springframework.context ConfigurableApplicationContext getDisplayName

List of usage examples for org.springframework.context ConfigurableApplicationContext getDisplayName

Introduction

In this page you can find the example usage for org.springframework.context ConfigurableApplicationContext getDisplayName.

Prototype

String getDisplayName();

Source Link

Document

Return a friendly name for this context.

Usage

From source file:org.codehaus.groovy.grails.web.context.GrailsContextLoader.java

@Override
public void closeWebApplicationContext(ServletContext servletContext) {
    // clean up in war mode, in run-app these references may be needed again
    if (application == null || !application.isWarDeployed()) {
        return;//from   w  w w.  j  a  v a  2 s .  co m
    }

    WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext);
    ConfigurableApplicationContext parent = ctx != null ? (ConfigurableApplicationContext) ctx.getParent()
            : null;

    try {
        super.closeWebApplicationContext(servletContext);
    } finally {
        ShutdownOperations.runOperations();
    }

    if (parent != null) {
        LOG.info("Destroying Spring parent WebApplicationContext " + parent.getDisplayName());
        parent.close();
    }
    try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
    } catch (AccessControlException e) {
        // container doesn't allow, probably related to WAR deployment on AppEngine. proceed.
    }

    application = null;
}

From source file:org.springframework.batch.core.configuration.support.DefaultJobLoader.java

@Override
public Collection<Job> reload(ApplicationContextFactory factory) {

    // If the same factory is loaded twice the context can be closed
    if (contexts.containsKey(factory)) {
        ConfigurableApplicationContext context = contexts.get(factory);
        for (String name : contextToJobNames.get(context)) {
            if (logger.isDebugEnabled()) {
                logger.debug("Unregistering job: " + name + " from context: " + context.getDisplayName());
            }/*from w  w w  .j a v  a2  s . c  o m*/
            doUnregister(name);
        }
        context.close();
    }

    try {
        return doLoad(factory, true);
    } catch (DuplicateJobException e) {
        throw new IllegalStateException("Found duplicate job in reload (it should have been unregistered "
                + "if it was previously registered in this loader)", e);
    }
}

From source file:org.springframework.batch.core.configuration.support.DefaultJobLoader.java

@SuppressWarnings("resource")
private Collection<Job> doLoad(ApplicationContextFactory factory, boolean unregister)
        throws DuplicateJobException {

    Collection<String> jobNamesBefore = jobRegistry.getJobNames();
    ConfigurableApplicationContext context = factory.createApplicationContext();
    Collection<String> jobNamesAfter = jobRegistry.getJobNames();
    // Try to detect auto-registration (e.g. through a bean post processor)
    boolean autoRegistrationDetected = jobNamesAfter.size() > jobNamesBefore.size();

    Collection<String> jobsRegistered = new HashSet<String>();
    if (autoRegistrationDetected) {
        for (String name : jobNamesAfter) {
            if (!jobNamesBefore.contains(name)) {
                jobsRegistered.add(name);
            }//from  www .j  a  va  2  s  .c o  m
        }
    }

    contexts.put(factory, context);
    String[] names = context.getBeanNamesForType(Job.class);

    for (String name : names) {

        if (!autoRegistrationDetected) {

            Job job = (Job) context.getBean(name);
            String jobName = job.getName();

            // On reload try to unregister first
            if (unregister) {
                if (logger.isDebugEnabled()) {
                    logger.debug(
                            "Unregistering job: " + jobName + " from context: " + context.getDisplayName());
                }
                doUnregister(jobName);
            }

            if (logger.isDebugEnabled()) {
                logger.debug("Registering job: " + jobName + " from context: " + context.getDisplayName());
            }
            doRegister(context, job);
            jobsRegistered.add(jobName);
        }

    }

    Collection<Job> result = new ArrayList<Job>();
    for (String name : jobsRegistered) {
        try {
            result.add(jobRegistry.getJob(name));
        } catch (NoSuchJobException e) {
            // should not happen;
            throw new IllegalStateException("Could not retrieve job that was should have been registered", e);
        }

    }

    contextToJobNames.put(context, jobsRegistered);

    return result;

}