org.springframework.context.LifecycleProcessor Java Examples

The following examples show how to use org.springframework.context.LifecycleProcessor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractApplicationContext.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Initialize the LifecycleProcessor.
 * Uses DefaultLifecycleProcessor if none defined in the context.
 * @see org.springframework.context.support.DefaultLifecycleProcessor
 */
protected void initLifecycleProcessor() {
	ConfigurableListableBeanFactory beanFactory = getBeanFactory();
	if (beanFactory.containsLocalBean(LIFECYCLE_PROCESSOR_BEAN_NAME)) {
		this.lifecycleProcessor =
				beanFactory.getBean(LIFECYCLE_PROCESSOR_BEAN_NAME, LifecycleProcessor.class);
		if (logger.isTraceEnabled()) {
			logger.trace("Using LifecycleProcessor [" + this.lifecycleProcessor + "]");
		}
	}
	else {
		DefaultLifecycleProcessor defaultProcessor = new DefaultLifecycleProcessor();
		defaultProcessor.setBeanFactory(beanFactory);
		this.lifecycleProcessor = defaultProcessor;
		beanFactory.registerSingleton(LIFECYCLE_PROCESSOR_BEAN_NAME, this.lifecycleProcessor);
		if (logger.isTraceEnabled()) {
			logger.trace("No '" + LIFECYCLE_PROCESSOR_BEAN_NAME + "' bean, using " +
					"[" + this.lifecycleProcessor.getClass().getSimpleName() + "]");
		}
	}
}
 
Example #2
Source File: AbstractApplicationContext.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Initialize the LifecycleProcessor.
 * Uses DefaultLifecycleProcessor if none defined in the context.
 * @see org.springframework.context.support.DefaultLifecycleProcessor
 */
protected void initLifecycleProcessor() {
	ConfigurableListableBeanFactory beanFactory = getBeanFactory();
	if (beanFactory.containsLocalBean(LIFECYCLE_PROCESSOR_BEAN_NAME)) {
		this.lifecycleProcessor =
				beanFactory.getBean(LIFECYCLE_PROCESSOR_BEAN_NAME, LifecycleProcessor.class);
		if (logger.isTraceEnabled()) {
			logger.trace("Using LifecycleProcessor [" + this.lifecycleProcessor + "]");
		}
	}
	else {
		DefaultLifecycleProcessor defaultProcessor = new DefaultLifecycleProcessor();
		defaultProcessor.setBeanFactory(beanFactory);
		this.lifecycleProcessor = defaultProcessor;
		beanFactory.registerSingleton(LIFECYCLE_PROCESSOR_BEAN_NAME, this.lifecycleProcessor);
		if (logger.isTraceEnabled()) {
			logger.trace("No '" + LIFECYCLE_PROCESSOR_BEAN_NAME + "' bean, using " +
					"[" + this.lifecycleProcessor.getClass().getSimpleName() + "]");
		}
	}
}
 
Example #3
Source File: AbstractApplicationContext.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Initialize the LifecycleProcessor.
 * Uses DefaultLifecycleProcessor if none defined in the context.
 * @see org.springframework.context.support.DefaultLifecycleProcessor
 */
protected void initLifecycleProcessor() {
	ConfigurableListableBeanFactory beanFactory = getBeanFactory();
	if (beanFactory.containsLocalBean(LIFECYCLE_PROCESSOR_BEAN_NAME)) {
		this.lifecycleProcessor =
				beanFactory.getBean(LIFECYCLE_PROCESSOR_BEAN_NAME, LifecycleProcessor.class);
		if (logger.isDebugEnabled()) {
			logger.debug("Using LifecycleProcessor [" + this.lifecycleProcessor + "]");
		}
	}
	else {
		DefaultLifecycleProcessor defaultProcessor = new DefaultLifecycleProcessor();
		defaultProcessor.setBeanFactory(beanFactory);
		this.lifecycleProcessor = defaultProcessor;
		beanFactory.registerSingleton(LIFECYCLE_PROCESSOR_BEAN_NAME, this.lifecycleProcessor);
		if (logger.isDebugEnabled()) {
			logger.debug("Unable to locate LifecycleProcessor with name '" +
					LIFECYCLE_PROCESSOR_BEAN_NAME +
					"': using default [" + this.lifecycleProcessor + "]");
		}
	}
}
 
Example #4
Source File: AbstractApplicationContext.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize the LifecycleProcessor.
 * Uses DefaultLifecycleProcessor if none defined in the context.
 * @see org.springframework.context.support.DefaultLifecycleProcessor
 */
protected void initLifecycleProcessor() {
	ConfigurableListableBeanFactory beanFactory = getBeanFactory();
	if (beanFactory.containsLocalBean(LIFECYCLE_PROCESSOR_BEAN_NAME)) {
		this.lifecycleProcessor =
				beanFactory.getBean(LIFECYCLE_PROCESSOR_BEAN_NAME, LifecycleProcessor.class);
		if (logger.isDebugEnabled()) {
			logger.debug("Using LifecycleProcessor [" + this.lifecycleProcessor + "]");
		}
	}
	else {
		DefaultLifecycleProcessor defaultProcessor = new DefaultLifecycleProcessor();
		defaultProcessor.setBeanFactory(beanFactory);
		this.lifecycleProcessor = defaultProcessor;
		beanFactory.registerSingleton(LIFECYCLE_PROCESSOR_BEAN_NAME, this.lifecycleProcessor);
		if (logger.isDebugEnabled()) {
			logger.debug("Unable to locate LifecycleProcessor with name '" +
					LIFECYCLE_PROCESSOR_BEAN_NAME +
					"': using default [" + this.lifecycleProcessor + "]");
		}
	}
}
 
Example #5
Source File: AbstractApplicationContext.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Return the internal LifecycleProcessor used by the context.
 * @return the internal LifecycleProcessor (never {@code null})
 * @throws IllegalStateException if the context has not been initialized yet
 */
LifecycleProcessor getLifecycleProcessor() throws IllegalStateException {
	if (this.lifecycleProcessor == null) {
		throw new IllegalStateException("LifecycleProcessor not initialized - " +
				"call 'refresh' before invoking lifecycle methods via the context: " + this);
	}
	return this.lifecycleProcessor;
}
 
Example #6
Source File: DefaultLifecycleProcessorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void customLifecycleProcessorInstance() {
	BeanDefinition beanDefinition = new RootBeanDefinition(DefaultLifecycleProcessor.class);
	beanDefinition.getPropertyValues().addPropertyValue("timeoutPerShutdownPhase", 1000);
	StaticApplicationContext context = new StaticApplicationContext();
	context.registerBeanDefinition("lifecycleProcessor", beanDefinition);
	context.refresh();
	LifecycleProcessor bean = context.getBean("lifecycleProcessor", LifecycleProcessor.class);
	Object contextLifecycleProcessor = new DirectFieldAccessor(context).getPropertyValue("lifecycleProcessor");
	assertNotNull(contextLifecycleProcessor);
	assertSame(bean, contextLifecycleProcessor);
	assertEquals(1000L, new DirectFieldAccessor(contextLifecycleProcessor).getPropertyValue(
			"timeoutPerShutdownPhase"));
}
 
Example #7
Source File: AbstractApplicationContext.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Return the internal LifecycleProcessor used by the context.
 * @return the internal LifecycleProcessor (never {@code null})
 * @throws IllegalStateException if the context has not been initialized yet
 */
LifecycleProcessor getLifecycleProcessor() throws IllegalStateException {
	if (this.lifecycleProcessor == null) {
		throw new IllegalStateException("LifecycleProcessor not initialized - " +
				"call 'refresh' before invoking lifecycle methods via the context: " + this);
	}
	return this.lifecycleProcessor;
}
 
Example #8
Source File: DefaultLifecycleProcessorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void customLifecycleProcessorInstance() {
	BeanDefinition beanDefinition = new RootBeanDefinition(DefaultLifecycleProcessor.class);
	beanDefinition.getPropertyValues().addPropertyValue("timeoutPerShutdownPhase", 1000);
	StaticApplicationContext context = new StaticApplicationContext();
	context.registerBeanDefinition("lifecycleProcessor", beanDefinition);
	context.refresh();
	LifecycleProcessor bean = context.getBean("lifecycleProcessor", LifecycleProcessor.class);
	Object contextLifecycleProcessor = new DirectFieldAccessor(context).getPropertyValue("lifecycleProcessor");
	assertNotNull(contextLifecycleProcessor);
	assertSame(bean, contextLifecycleProcessor);
	assertEquals(1000L, new DirectFieldAccessor(contextLifecycleProcessor).getPropertyValue(
			"timeoutPerShutdownPhase"));
}
 
Example #9
Source File: AbstractApplicationContext.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the internal LifecycleProcessor used by the context.
 * @return the internal LifecycleProcessor (never {@code null})
 * @throws IllegalStateException if the context has not been initialized yet
 */
LifecycleProcessor getLifecycleProcessor() throws IllegalStateException {
	if (this.lifecycleProcessor == null) {
		throw new IllegalStateException("LifecycleProcessor not initialized - " +
				"call 'refresh' before invoking lifecycle methods via the context: " + this);
	}
	return this.lifecycleProcessor;
}
 
Example #10
Source File: AbstractApplicationContext.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Return the internal LifecycleProcessor used by the context.
 * @return the internal LifecycleProcessor (never {@code null})
 * @throws IllegalStateException if the context has not been initialized yet
 */
LifecycleProcessor getLifecycleProcessor() throws IllegalStateException {
	if (this.lifecycleProcessor == null) {
		throw new IllegalStateException("LifecycleProcessor not initialized - " +
				"call 'refresh' before invoking lifecycle methods via the context: " + this);
	}
	return this.lifecycleProcessor;
}
 
Example #11
Source File: DefaultLifecycleProcessorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void customLifecycleProcessorInstance() {
	BeanDefinition beanDefinition = new RootBeanDefinition(DefaultLifecycleProcessor.class);
	beanDefinition.getPropertyValues().addPropertyValue("timeoutPerShutdownPhase", 1000);
	StaticApplicationContext context = new StaticApplicationContext();
	context.registerBeanDefinition("lifecycleProcessor", beanDefinition);
	context.refresh();
	LifecycleProcessor bean = context.getBean("lifecycleProcessor", LifecycleProcessor.class);
	Object contextLifecycleProcessor = new DirectFieldAccessor(context).getPropertyValue("lifecycleProcessor");
	assertNotNull(contextLifecycleProcessor);
	assertSame(bean, contextLifecycleProcessor);
	assertEquals(1000L, new DirectFieldAccessor(contextLifecycleProcessor).getPropertyValue(
			"timeoutPerShutdownPhase"));
}