Example usage for org.springframework.context.event ContextRefreshedEvent getApplicationContext

List of usage examples for org.springframework.context.event ContextRefreshedEvent getApplicationContext

Introduction

In this page you can find the example usage for org.springframework.context.event ContextRefreshedEvent getApplicationContext.

Prototype

public final ApplicationContext getApplicationContext() 

Source Link

Document

Get the ApplicationContext that the event was raised for.

Usage

From source file:tomekkup.helenos.context.PostConfiguringClusterListener.java

@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
    if (isReady(event)) {
        ApplicationContext applicationContext = event.getApplicationContext();
        ClusterConfiguration configuration = clusterConfigDao.getActive();

        propagadeConfigChanges(applicationContext.getParent(), configuration.createCluster());
    }/*from  www.ja  va2  s . c  o  m*/
}

From source file:com.liferay.analytics.internal.osgi.SpringOsgiBridge.java

@Override
public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {

    MessageBusUtil.sendMessage(AnalyticsServiceActivator.DESTINATION_NAME,
            contextRefreshedEvent.getApplicationContext());
}

From source file:com.liferay.contenttargeting.internal.osgi.SpringOsgiBridge.java

@Override
public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {

    MessageBusUtil.sendMessage(ContentTargetingActivator.DESTINATION_NAME,
            contextRefreshedEvent.getApplicationContext());
}

From source file:com.yqboots.menu.context.MenuItemImportListener.java

/**
 * {@inheritDoc}//w  ww . jav  a2s.  c om
 */
@Override
public void onApplicationEvent(final ContextRefreshedEvent event) {
    final ApplicationContext context = event.getApplicationContext();

    final MenuItemManager manager = context.getBean(MenuItemManager.class);
    final MenuItemProperties properties = context.getBean(MenuItemProperties.class);
    // ignore if importing is disabled
    if (!properties.isImportEnabled()) {
        return;
    }

    // find importing file in the specified location
    final String location = properties.getImportFileLocation();
    if (StringUtils.isEmpty(location)) {
        LOG.warn("Menu Item Importing is enabled, but location was not set");
        return;
    }

    try {
        // get file, may throw FileNotFoundException
        final File file = ResourceUtils.getFile(location);
        try (final InputStream inputStream = new FileInputStream(file)) {
            manager.imports(inputStream);
        }
    } catch (IOException e) {
        LOG.error("Failed to import Menu Items", e);
    }
}

From source file:com.liferay.anonymoususers.internal.osgi.SpringOsgiBridge.java

@Override
public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {

    MessageBusUtil.sendMessage(AnonymousUserServiceActivator.DESTINATION_NAME,
            contextRefreshedEvent.getApplicationContext());
}

From source file:org.togglz.spring.listener.TogglzApplicationContextBinderApplicationListenerTest.java

@Test
public void contextRefreshed() {
    ContextRefreshedEvent contextRefreshedEvent = mock(ContextRefreshedEvent.class);
    when(contextRefreshedEvent.getApplicationContext()).thenReturn(applicationContext);
    // Invoke context refreshed event
    applicationListener.onApplicationEvent(contextRefreshedEvent);
    // Assert application context bound
    assertSame(applicationContext, ContextClassLoaderApplicationContextHolder.get());
}

From source file:org.cloudfoundry.tools.timeout.TimeoutResourceHttpRequestHandler.java

@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
    this.timeoutValues = BeanFactoryUtils.beanOfTypeIncludingAncestors(event.getApplicationContext(),
            TimeoutValues.class);
}

From source file:org.togglz.spring.listener.TogglzApplicationContextBinderApplicationListenerTest.java

@Test
public void contextRefreshedWhileContextAlreadyBound() {
    // Bind application context before context refreshed event invoked
    ContextClassLoaderApplicationContextHolder.bind(mock(ApplicationContext.class));
    applicationContext = mock(ApplicationContext.class);
    ContextRefreshedEvent contextRefreshedEvent = mock(ContextRefreshedEvent.class);
    when(contextRefreshedEvent.getApplicationContext()).thenReturn(applicationContext);
    // Invoke context refreshed application event
    applicationListener.onApplicationEvent(contextRefreshedEvent);
    // Assert application context bound
    assertSame(applicationContext, ContextClassLoaderApplicationContextHolder.get());
}

From source file:org.cleverbus.core.conf.ConfigurationChecker.java

@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
    checkConfiguration(event.getApplicationContext());
}

From source file:org.scrutmydocs.webapp.configuration.AppPostProcessor.java

@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
    // We only inject beans when we start the Root applicationContext, aka there's no parent!
    if (event.getApplicationContext().getParent() == null) {
        try {/*from  w  w  w  .  java2  s  .  c om*/
            logger.warn(
                    "TODO : remove automatic river creation. Just here for example purpose! See org.scrutmydocs.webapp.configuration.AppPostProcessor.");

            // We create the default mapping
            ESHelper.createIndexIfNeeded(client);

            // We are going to create two filesystem rivers
            fsRiverService.start(new FSRiver("myfirstriver", SMDSearchProperties.INDEX_NAME,
                    SMDSearchProperties.INDEX_TYPE_DOC, "Scan tmp dir", "/tmp_es", 30L, "standard", true));
            fsRiverService.start(new FSRiver("mysecondriver", SMDSearchProperties.INDEX_NAME,
                    SMDSearchProperties.INDEX_TYPE_DOC, "Scan second dir", "/tmp_es_second", 30L, "standard",
                    false));

            // Add some sample files
            pushSampleDoc("LICENSE");
            pushSampleDoc("NOTICE");
        } catch (ElasticSearchException e) {
            logger.error("Error while creating rivers", e);
        }
    }
}