Java 类org.springframework.context.Phased 实例源码
项目:spring4-understanding
文件:JmsNamespaceHandlerTests.java
private int getPhase(String containerBeanName) {
Object container = this.context.getBean(containerBeanName);
if (!(container instanceof Phased)) {
throw new IllegalStateException("Container '" + containerBeanName + "' does not implement Phased.");
}
return ((Phased) container).getPhase();
}
项目:FinanceAnalytics
文件:ComponentRepository.java
/**
* Examines an object and sets up a {@code Lifecycle} instance if it can be closed.
* If it implements {@code Phased} then the phase is used.
*
* @param instance the object to examine, not null
*/
private void findAndRegisterLifeCycle(final Object instance) {
if (ReflectionUtils.isCloseable(instance.getClass())) {
registerLifecycle0(new PhasedLifecycle() {
@Override
public void stop() {
ReflectionUtils.close(instance);
}
@Override
public void start() {
}
@Override
public boolean isRunning() {
return false;
}
@Override
public int getPhase() {
if (instance instanceof Phased) {
return ((Phased) instance).getPhase();
}
return 0;
}
@Override
public String toString() {
return instance.getClass().getSimpleName() + ":" + instance.toString();
}
});
}
}
项目:FinanceAnalytics
文件:ComponentRepository.java
/**
* Registers a non-component object that requires closing or shutdown when
* the repository stops.
* <p>
* Certain interfaces are automatically detected.
* If it implements {@code InitializingBean}, then it will be initialized
* as though using {@link #initialize(InitializingBean)}.
* If it implements {@code Phased} then the phase is used.
*
* @param obj the object to close/shutdown, not null
* @param methodName the method name to call, not null
*/
public void registerLifecycleStop(final Object obj, final String methodName) {
ArgumentChecker.notNull(obj, "object");
ArgumentChecker.notNull(methodName, "methodName");
checkStatus(Status.CREATING);
initialize0(obj);
registerLifecycle0(new PhasedLifecycle() {
@Override
public void stop() {
ReflectionUtils.invokeNoArgsNoException(obj, methodName);
}
@Override
public void start() {
}
@Override
public boolean isRunning() {
return false;
}
@Override
public int getPhase() {
if (obj instanceof Phased) {
return ((Phased) obj).getPhase();
}
return 0;
}
@Override
public String toString() {
return obj.getClass().getSimpleName() + ":" + obj.toString();
}
});
_logger.logDebug(" Registered lifecycle-stop: " + obj);
}
项目:FinanceAnalytics
文件:ComponentRepository.java
/**
* Registers a {@code Lifecycle} instance.
*
* @param lifecycleObject the object that has a lifecycle, not null
*/
private void registerLifecycle0(Lifecycle lifecycleObject) {
Integer phase = 0;
if (lifecycleObject instanceof Phased) {
phase = ((Phased) lifecycleObject).getPhase();
}
List<Lifecycle> list = _lifecycles.get(phase);
if (list == null) {
list = new ArrayList<>();
_lifecycles.put(phase, list);
}
list.add(lifecycleObject);
}
项目:class-guard
文件:JmsNamespaceHandlerTests.java
public int getPhase(String containerBeanName) {
Object container = this.context.getBean(containerBeanName);
if (!(container instanceof Phased)) {
throw new IllegalStateException("Container '" + containerBeanName + "' does not implement Phased.");
}
return ((Phased) container).getPhase();
}
项目:lams
文件:DefaultLifecycleProcessor.java
/**
* Determine the lifecycle phase of the given bean.
* <p>The default implementation checks for the {@link Phased} interface.
* Can be overridden to apply other/further policies.
* @param bean the bean to introspect
* @return the phase an an integer value. The suggested default is 0.
* @see Phased
* @see SmartLifecycle
*/
protected int getPhase(Lifecycle bean) {
return (bean instanceof Phased ? ((Phased) bean).getPhase() : 0);
}
项目:spring4-understanding
文件:DefaultLifecycleProcessor.java
/**
* Determine the lifecycle phase of the given bean.
* <p>The default implementation checks for the {@link Phased} interface.
* Can be overridden to apply other/further policies.
* @param bean the bean to introspect
* @return the phase an an integer value. The suggested default is 0.
* @see Phased
* @see SmartLifecycle
*/
protected int getPhase(Lifecycle bean) {
return (bean instanceof Phased ? ((Phased) bean).getPhase() : 0);
}
项目:my-spring-cache-redis
文件:DefaultLifecycleProcessor.java
/**
* Determine the lifecycle phase of the given bean.
* <p>The default implementation checks for the {@link Phased} interface.
* Can be overridden to apply other/further policies.
* @param bean the bean to introspect
* @return the phase an an integer value. The suggested default is 0.
* @see Phased
* @see SmartLifecycle
*/
protected int getPhase(Lifecycle bean) {
return (bean instanceof Phased ? ((Phased) bean).getPhase() : 0);
}
项目:spring
文件:DefaultLifecycleProcessor.java
/**
* Determine the lifecycle phase of the given bean.
* <p>The default implementation checks for the {@link Phased} interface.
* Can be overridden to apply other/further policies.
* @param bean the bean to introspect
* @return the phase an integer value. The suggested default is 0.
* @see Phased
* @see SmartLifecycle
*/
protected int getPhase(Lifecycle bean) {
return (bean instanceof Phased ? ((Phased) bean).getPhase() : 0);
}
项目:class-guard
文件:DefaultLifecycleProcessor.java
/**
* Determine the lifecycle phase of the given bean.
* <p>The default implementation checks for the {@link Phased} interface.
* Can be overridden to apply other/further policies.
* @param bean the bean to introspect
* @return the phase an an integer value. The suggested default is 0.
* @see Phased
* @see SmartLifecycle
*/
protected int getPhase(Lifecycle bean) {
return (bean instanceof Phased ? ((Phased) bean).getPhase() : 0);
}