本文整理了Java中org.springframework.context.ConfigurableApplicationContext.isActive()
方法的一些代码示例,展示了ConfigurableApplicationContext.isActive()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ConfigurableApplicationContext.isActive()
方法的具体详情如下:
包路径:org.springframework.context.ConfigurableApplicationContext
类名称:ConfigurableApplicationContext
方法名:isActive
[英]Determine whether this application context is active, that is, whether it has been refreshed at least once and has not been closed yet.
[中]确定此应用程序上下文是否处于活动状态,即它是否已至少刷新一次且尚未关闭。
代码示例来源:origin: spring-projects/spring-framework
/**
* Refresh the given application context, if necessary.
*/
protected void refreshApplicationContext(ApplicationContext context) {
if (context instanceof ConfigurableApplicationContext) {
ConfigurableApplicationContext cac = (ConfigurableApplicationContext) context;
if (!cac.isActive()) {
cac.refresh();
}
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Get the {@linkplain ApplicationContext application context} for this
* test context.
* <p>The default implementation delegates to the {@link CacheAwareContextLoaderDelegate}
* that was supplied when this {@code TestContext} was constructed.
* @throws IllegalStateException if the context returned by the context
* loader delegate is not <em>active</em> (i.e., has been closed).
* @see CacheAwareContextLoaderDelegate#loadContext
*/
public ApplicationContext getApplicationContext() {
ApplicationContext context = this.cacheAwareContextLoaderDelegate.loadContext(this.mergedContextConfiguration);
if (context instanceof ConfigurableApplicationContext) {
@SuppressWarnings("resource")
ConfigurableApplicationContext cac = (ConfigurableApplicationContext) context;
Assert.state(cac.isActive(), () ->
"The ApplicationContext loaded for [" + this.mergedContextConfiguration +
"] is not active. This may be due to one of the following reasons: " +
"1) the context was closed programmatically by user code; " +
"2) the context was closed during parallel test execution either " +
"according to @DirtiesContext semantics or due to automatic eviction " +
"from the ContextCache due to a maximum cache size policy.");
}
return context;
}
代码示例来源:origin: org.springframework/spring-web
/**
* Refresh the given application context, if necessary.
*/
protected void refreshApplicationContext(ApplicationContext context) {
if (context instanceof ConfigurableApplicationContext) {
ConfigurableApplicationContext cac = (ConfigurableApplicationContext) context;
if (!cac.isActive()) {
cac.refresh();
}
}
}
代码示例来源:origin: org.springframework.boot/spring-boot
@Override
public void onApplicationEvent(ContextClosedEvent event) {
ConfigurableApplicationContext context = this.childContext.get();
if ((context != null)
&& (event.getApplicationContext() == context.getParent())
&& context.isActive()) {
context.close();
}
}
代码示例来源:origin: ctripcorp/apollo
logger.info(commonContext.getId() + " isActive: " + commonContext.isActive());
new SpringApplicationBuilder(ConfigServiceApplication.class).parent(commonContext)
.sources(RefreshScope.class).run(args);
logger.info(configContext.getId() + " isActive: " + configContext.isActive());
new SpringApplicationBuilder(AdminServiceApplication.class).parent(commonContext)
.sources(RefreshScope.class).run(args);
logger.info(adminContext.getId() + " isActive: " + adminContext.isActive());
new SpringApplicationBuilder(PortalApplication.class).parent(commonContext)
.sources(RefreshScope.class).run(args);
logger.info(portalContext.getId() + " isActive: " + portalContext.isActive());
代码示例来源:origin: spring-projects/spring-batch
/**
* Unregister all the jobs and close all the contexts created by this
* loader.
*
* @see JobLoader#clear()
*/
@Override
public void clear() {
for (ConfigurableApplicationContext context : contexts.values()) {
if (context.isActive()) {
context.close();
}
}
for (String jobName : jobRegistry.getJobNames()) {
doUnregister(jobName);
}
contexts.clear();
contextToJobNames.clear();
}
代码示例来源:origin: spring-projects/spring-framework
if (!cac.isActive()) {
代码示例来源:origin: org.springframework.boot/spring-boot
private int getExitCodeFromMappedException(ConfigurableApplicationContext context,
Throwable exception) {
if (context == null || !context.isActive()) {
return 0;
}
ExitCodeGenerators generators = new ExitCodeGenerators();
Collection<ExitCodeExceptionMapper> beans = context
.getBeansOfType(ExitCodeExceptionMapper.class).values();
generators.addAll(exception, beans);
return generators.getExitCode();
}
代码示例来源:origin: spring-projects/spring-framework
private void performAssertions(int expectedContextCreationCount) throws Exception {
assertNotNull("context must not be null", this.context);
assertTrue("context must be active", this.context.isActive());
assertNotNull("count must not be null", this.count);
assertEquals("count: ", expectedContextCreationCount, this.count.intValue());
assertEquals("context creation count: ", expectedContextCreationCount, contextCount.get());
}
代码示例来源:origin: org.springframework/spring-web
if (!cac.isActive()) {
代码示例来源:origin: spring-projects/spring-framework
private void runTestAndVerifyHierarchies(Class<? extends FooTestCase> testClass, boolean isFooContextActive,
boolean isBarContextActive, boolean isBazContextActive) {
JUnitCore jUnitCore = new JUnitCore();
Result result = jUnitCore.run(testClass);
assertTrue("all tests passed", result.wasSuccessful());
assertThat(ContextHierarchyDirtiesContextTests.context, notNullValue());
ConfigurableApplicationContext bazContext = (ConfigurableApplicationContext) ContextHierarchyDirtiesContextTests.context;
assertEquals("baz", ContextHierarchyDirtiesContextTests.baz);
assertThat("bazContext#isActive()", bazContext.isActive(), is(isBazContextActive));
ConfigurableApplicationContext barContext = (ConfigurableApplicationContext) bazContext.getParent();
assertThat(barContext, notNullValue());
assertEquals("bar", ContextHierarchyDirtiesContextTests.bar);
assertThat("barContext#isActive()", barContext.isActive(), is(isBarContextActive));
ConfigurableApplicationContext fooContext = (ConfigurableApplicationContext) barContext.getParent();
assertThat(fooContext, notNullValue());
assertEquals("foo", ContextHierarchyDirtiesContextTests.foo);
assertThat("fooContext#isActive()", fooContext.isActive(), is(isFooContextActive));
}
代码示例来源:origin: org.springframework.boot/spring-boot
@Override
public void failed(ConfigurableApplicationContext context, Throwable exception) {
ApplicationFailedEvent event = new ApplicationFailedEvent(this.application,
this.args, context, exception);
if (context != null && context.isActive()) {
// Listeners have been registered to the application context so we should
// use it at this point if we can
context.publishEvent(event);
}
else {
// An inactive context may not have a multicaster so we use our multicaster to
// call all of the context's listeners instead
if (context instanceof AbstractApplicationContext) {
for (ApplicationListener<?> listener : ((AbstractApplicationContext) context)
.getApplicationListeners()) {
this.initialMulticaster.addApplicationListener(listener);
}
}
this.initialMulticaster.setErrorHandler(new LoggingErrorHandler());
this.initialMulticaster.multicastEvent(event);
}
}
代码示例来源:origin: mulesoft/mule
@Override
public void doDispose() {
// check we aren't trying to close a context which has never been started,
// spring's appContext.isActive() isn't working for this case
if (!springContextInitialised.get()) {
return;
}
if (!isReadOnly() && ((ConfigurableApplicationContext) applicationContext).isActive()) {
((ConfigurableApplicationContext) applicationContext).close();
}
// release the circular implicit ref to MuleContext
applicationContext = null;
this.springContextInitialised.set(false);
}
代码示例来源:origin: org.graniteds/granite-client-java-advanced
private boolean isInactive() {
return (
applicationContext instanceof ConfigurableApplicationContext &&
!((ConfigurableApplicationContext)applicationContext).isActive()
);
}
}
代码示例来源:origin: com.consol.citrus/citrus-core
/**
* Closing Citrus and its application context.
*/
public void close() {
if (applicationContext instanceof ConfigurableApplicationContext) {
if (((ConfigurableApplicationContext) applicationContext).isActive()) {
((ConfigurableApplicationContext) applicationContext).close();
}
}
}
}
代码示例来源:origin: NationalSecurityAgency/datawave
@Override
public boolean isActive() {
lock.readLock().lock();
try {
return configurableApplicationContext.isActive();
} finally {
lock.readLock().unlock();
}
}
代码示例来源:origin: org.springframework.xd/spring-xd-module
@Override
public <T> T getComponent(String componentName, Class<T> requiredType) {
if (this.context.isActive() && this.context.containsBean(componentName)) {
return context.getBean(componentName, requiredType);
}
return null;
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-web
/**
* Refresh the given application context, if necessary.
*/
protected void refreshApplicationContext(ApplicationContext context) {
if (context instanceof ConfigurableApplicationContext) {
ConfigurableApplicationContext cac = (ConfigurableApplicationContext) context;
if (!cac.isActive()) {
cac.refresh();
}
}
}
代码示例来源:origin: org.springframework.xd/spring-xd-module
@Override
public void stop() {
if (context.isActive()) {
context.stop(); // Shouldn't need to close() as well?
}
}
代码示例来源:origin: org.echocat.jomon.spring/common
@Override
public void init() {
synchronized (this) {
if (!_applicationContext.isActive()) {
_applicationContext.refresh();
_stopWatch = new StopWatch();
}
}
}
内容来源于网络,如有侵权,请联系作者删除!