java类org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor的实例源码

DisposableBeanAdapter.java 文件源码 项目:spring 阅读 19 收藏 0 点赞 0 评论 0
/**
 * Search for all DestructionAwareBeanPostProcessors in the List.
 * @param processors the List to search
 * @return the filtered List of DestructionAwareBeanPostProcessors
 */
private List<DestructionAwareBeanPostProcessor> filterPostProcessors(List<BeanPostProcessor> processors, Object bean) {
    List<DestructionAwareBeanPostProcessor> filteredPostProcessors = null;
    if (!CollectionUtils.isEmpty(processors)) {
        filteredPostProcessors = new ArrayList<DestructionAwareBeanPostProcessor>(processors.size());
        for (BeanPostProcessor processor : processors) {
            if (processor instanceof DestructionAwareBeanPostProcessor) {
                DestructionAwareBeanPostProcessor dabpp = (DestructionAwareBeanPostProcessor) processor;
                try {
                    if (dabpp.requiresDestruction(bean)) {
                        filteredPostProcessors.add(dabpp);
                    }
                }
                catch (AbstractMethodError err) {
                    // A pre-4.3 third-party DestructionAwareBeanPostProcessor...
                    // As of 5.0, we can let requiresDestruction be a Java 8 default method which returns true.
                    filteredPostProcessors.add(dabpp);
                }
            }
        }
    }
    return filteredPostProcessors;
}
DisposableBeanAdapter.java 文件源码 项目:spring 阅读 19 收藏 0 点赞 0 评论 0
/**
 * Check whether the given bean has destruction-aware post-processors applying to it.
 * @param bean the bean instance
 * @param postProcessors the post-processor candidates
 */
public static boolean hasApplicableProcessors(Object bean, List<BeanPostProcessor> postProcessors) {
    if (!CollectionUtils.isEmpty(postProcessors)) {
        for (BeanPostProcessor processor : postProcessors) {
            if (processor instanceof DestructionAwareBeanPostProcessor) {
                DestructionAwareBeanPostProcessor dabpp = (DestructionAwareBeanPostProcessor) processor;
                try {
                    if (dabpp.requiresDestruction(bean)) {
                        return true;
                    }
                }
                catch (AbstractMethodError err) {
                    // A pre-4.3 third-party DestructionAwareBeanPostProcessor...
                    // As of 5.0, we can let requiresDestruction be a Java 8 default method which returns true.
                    return true;
                }
            }
        }
    }
    return false;
}
DisposableBeanAdapter.java 文件源码 项目:lams 阅读 21 收藏 0 点赞 0 评论 0
/**
 * Create a new DisposableBeanAdapter for the given bean.
 */
private DisposableBeanAdapter(Object bean, String beanName, boolean invokeDisposableBean,
        boolean nonPublicAccessAllowed, String destroyMethodName,
        List<DestructionAwareBeanPostProcessor> postProcessors) {

    this.bean = bean;
    this.beanName = beanName;
    this.invokeDisposableBean = invokeDisposableBean;
    this.nonPublicAccessAllowed = nonPublicAccessAllowed;
    this.acc = null;
    this.destroyMethodName = destroyMethodName;
    this.beanPostProcessors = postProcessors;
}
DisposableBeanAdapter.java 文件源码 项目:lams 阅读 18 收藏 0 点赞 0 评论 0
/**
 * Search for all DestructionAwareBeanPostProcessors in the List.
 * @param postProcessors the List to search
 * @return the filtered List of DestructionAwareBeanPostProcessors
 */
private List<DestructionAwareBeanPostProcessor> filterPostProcessors(List<BeanPostProcessor> postProcessors) {
    List<DestructionAwareBeanPostProcessor> filteredPostProcessors = null;
    if (postProcessors != null && !postProcessors.isEmpty()) {
        filteredPostProcessors = new ArrayList<DestructionAwareBeanPostProcessor>(postProcessors.size());
        for (BeanPostProcessor postProcessor : postProcessors) {
            if (postProcessor instanceof DestructionAwareBeanPostProcessor) {
                filteredPostProcessors.add((DestructionAwareBeanPostProcessor) postProcessor);
            }
        }
    }
    return filteredPostProcessors;
}
DisposableBeanAdapter.java 文件源码 项目:lams 阅读 26 收藏 0 点赞 0 评论 0
/**
 * Serializes a copy of the state of this class,
 * filtering out non-serializable BeanPostProcessors.
 */
protected Object writeReplace() {
    List<DestructionAwareBeanPostProcessor> serializablePostProcessors = null;
    if (this.beanPostProcessors != null) {
        serializablePostProcessors = new ArrayList<DestructionAwareBeanPostProcessor>();
        for (DestructionAwareBeanPostProcessor postProcessor : this.beanPostProcessors) {
            if (postProcessor instanceof Serializable) {
                serializablePostProcessors.add(postProcessor);
            }
        }
    }
    return new DisposableBeanAdapter(this.bean, this.beanName, this.invokeDisposableBean,
            this.nonPublicAccessAllowed, this.destroyMethodName, serializablePostProcessors);
}
AbstractBeanFactory.java 文件源码 项目:lams 阅读 20 收藏 0 点赞 0 评论 0
@Override
public void addBeanPostProcessor(BeanPostProcessor beanPostProcessor) {
    Assert.notNull(beanPostProcessor, "BeanPostProcessor must not be null");
    this.beanPostProcessors.remove(beanPostProcessor);
    this.beanPostProcessors.add(beanPostProcessor);
    if (beanPostProcessor instanceof InstantiationAwareBeanPostProcessor) {
        this.hasInstantiationAwareBeanPostProcessors = true;
    }
    if (beanPostProcessor instanceof DestructionAwareBeanPostProcessor) {
        this.hasDestructionAwareBeanPostProcessors = true;
    }
}
DisposableBeanAdapter.java 文件源码 项目:spring4-understanding 阅读 15 收藏 0 点赞 0 评论 0
/**
 * Create a new DisposableBeanAdapter for the given bean.
 */
private DisposableBeanAdapter(Object bean, String beanName, boolean invokeDisposableBean,
        boolean nonPublicAccessAllowed, String destroyMethodName,
        List<DestructionAwareBeanPostProcessor> postProcessors) {

    this.bean = bean;
    this.beanName = beanName;
    this.invokeDisposableBean = invokeDisposableBean;
    this.nonPublicAccessAllowed = nonPublicAccessAllowed;
    this.acc = null;
    this.destroyMethodName = destroyMethodName;
    this.beanPostProcessors = postProcessors;
}
DisposableBeanAdapter.java 文件源码 项目:spring4-understanding 阅读 18 收藏 0 点赞 0 评论 0
/**
 * Search for all DestructionAwareBeanPostProcessors in the List.
 * @param postProcessors the List to search
 * @return the filtered List of DestructionAwareBeanPostProcessors
 */
private List<DestructionAwareBeanPostProcessor> filterPostProcessors(List<BeanPostProcessor> postProcessors) {
    List<DestructionAwareBeanPostProcessor> filteredPostProcessors = null;
    if (!CollectionUtils.isEmpty(postProcessors)) {
        filteredPostProcessors = new ArrayList<DestructionAwareBeanPostProcessor>(postProcessors.size());
        for (BeanPostProcessor postProcessor : postProcessors) {
            if (postProcessor instanceof DestructionAwareBeanPostProcessor) {
                filteredPostProcessors.add((DestructionAwareBeanPostProcessor) postProcessor);
            }
        }
    }
    return filteredPostProcessors;
}
DisposableBeanAdapter.java 文件源码 项目:spring4-understanding 阅读 18 收藏 0 点赞 0 评论 0
/**
 * Serializes a copy of the state of this class,
 * filtering out non-serializable BeanPostProcessors.
 */
protected Object writeReplace() {
    List<DestructionAwareBeanPostProcessor> serializablePostProcessors = null;
    if (this.beanPostProcessors != null) {
        serializablePostProcessors = new ArrayList<DestructionAwareBeanPostProcessor>();
        for (DestructionAwareBeanPostProcessor postProcessor : this.beanPostProcessors) {
            if (postProcessor instanceof Serializable) {
                serializablePostProcessors.add(postProcessor);
            }
        }
    }
    return new DisposableBeanAdapter(this.bean, this.beanName, this.invokeDisposableBean,
            this.nonPublicAccessAllowed, this.destroyMethodName, serializablePostProcessors);
}
AbstractBeanFactory.java 文件源码 项目:spring4-understanding 阅读 16 收藏 0 点赞 0 评论 0
@Override
public void addBeanPostProcessor(BeanPostProcessor beanPostProcessor) {
    Assert.notNull(beanPostProcessor, "BeanPostProcessor must not be null");
    this.beanPostProcessors.remove(beanPostProcessor);
    this.beanPostProcessors.add(beanPostProcessor);
    if (beanPostProcessor instanceof InstantiationAwareBeanPostProcessor) {
        this.hasInstantiationAwareBeanPostProcessors = true;
    }
    if (beanPostProcessor instanceof DestructionAwareBeanPostProcessor) {
        this.hasDestructionAwareBeanPostProcessors = true;
    }
}
DisposableBeanAdapter.java 文件源码 项目:spring 阅读 22 收藏 0 点赞 0 评论 0
/**
 * Create a new DisposableBeanAdapter for the given bean.
 */
private DisposableBeanAdapter(Object bean, String beanName, boolean invokeDisposableBean,
        boolean nonPublicAccessAllowed, String destroyMethodName,
        List<DestructionAwareBeanPostProcessor> postProcessors) {

    this.bean = bean;
    this.beanName = beanName;
    this.invokeDisposableBean = invokeDisposableBean;
    this.nonPublicAccessAllowed = nonPublicAccessAllowed;
    this.acc = null;
    this.destroyMethodName = destroyMethodName;
    this.beanPostProcessors = postProcessors;
}
DisposableBeanAdapter.java 文件源码 项目:spring 阅读 16 收藏 0 点赞 0 评论 0
/**
 * Serializes a copy of the state of this class,
 * filtering out non-serializable BeanPostProcessors.
 */
protected Object writeReplace() {
    List<DestructionAwareBeanPostProcessor> serializablePostProcessors = null;
    if (this.beanPostProcessors != null) {
        serializablePostProcessors = new ArrayList<DestructionAwareBeanPostProcessor>();
        for (DestructionAwareBeanPostProcessor postProcessor : this.beanPostProcessors) {
            if (postProcessor instanceof Serializable) {
                serializablePostProcessors.add(postProcessor);
            }
        }
    }
    return new DisposableBeanAdapter(this.bean, this.beanName, this.invokeDisposableBean,
            this.nonPublicAccessAllowed, this.destroyMethodName, serializablePostProcessors);
}
AbstractBeanFactory.java 文件源码 项目:spring 阅读 19 收藏 0 点赞 0 评论 0
@Override
public void addBeanPostProcessor(BeanPostProcessor beanPostProcessor) {
    Assert.notNull(beanPostProcessor, "BeanPostProcessor must not be null");
    this.beanPostProcessors.remove(beanPostProcessor);
    this.beanPostProcessors.add(beanPostProcessor);
    if (beanPostProcessor instanceof InstantiationAwareBeanPostProcessor) {
        this.hasInstantiationAwareBeanPostProcessors = true;
    }
    if (beanPostProcessor instanceof DestructionAwareBeanPostProcessor) {
        this.hasDestructionAwareBeanPostProcessors = true;
    }
}
DisposableBeanAdapter.java 文件源码 项目:class-guard 阅读 18 收藏 0 点赞 0 评论 0
/**
 * Create a new DisposableBeanAdapter for the given bean.
 */
private DisposableBeanAdapter(Object bean, String beanName, boolean invokeDisposableBean,
        boolean nonPublicAccessAllowed, String destroyMethodName,
        List<DestructionAwareBeanPostProcessor> postProcessors) {

    this.bean = bean;
    this.beanName = beanName;
    this.invokeDisposableBean = invokeDisposableBean;
    this.nonPublicAccessAllowed = nonPublicAccessAllowed;
    this.acc = null;
    this.destroyMethodName = destroyMethodName;
    this.beanPostProcessors = postProcessors;
}
DisposableBeanAdapter.java 文件源码 项目:class-guard 阅读 19 收藏 0 点赞 0 评论 0
/**
 * Search for all DestructionAwareBeanPostProcessors in the List.
 * @param postProcessors the List to search
 * @return the filtered List of DestructionAwareBeanPostProcessors
 */
private List<DestructionAwareBeanPostProcessor> filterPostProcessors(List<BeanPostProcessor> postProcessors) {
    List<DestructionAwareBeanPostProcessor> filteredPostProcessors = null;
    if (postProcessors != null && !postProcessors.isEmpty()) {
        filteredPostProcessors = new ArrayList<DestructionAwareBeanPostProcessor>(postProcessors.size());
        for (BeanPostProcessor postProcessor : postProcessors) {
            if (postProcessor instanceof DestructionAwareBeanPostProcessor) {
                filteredPostProcessors.add((DestructionAwareBeanPostProcessor) postProcessor);
            }
        }
    }
    return filteredPostProcessors;
}
DisposableBeanAdapter.java 文件源码 项目:class-guard 阅读 19 收藏 0 点赞 0 评论 0
/**
 * Serializes a copy of the state of this class,
 * filtering out non-serializable BeanPostProcessors.
 */
protected Object writeReplace() {
    List<DestructionAwareBeanPostProcessor> serializablePostProcessors = null;
    if (this.beanPostProcessors != null) {
        serializablePostProcessors = new ArrayList<DestructionAwareBeanPostProcessor>();
        for (DestructionAwareBeanPostProcessor postProcessor : this.beanPostProcessors) {
            if (postProcessor instanceof Serializable) {
                serializablePostProcessors.add(postProcessor);
            }
        }
    }
    return new DisposableBeanAdapter(this.bean, this.beanName, this.invokeDisposableBean,
            this.nonPublicAccessAllowed, this.destroyMethodName, serializablePostProcessors);
}
AbstractBeanFactory.java 文件源码 项目:class-guard 阅读 24 收藏 0 点赞 0 评论 0
public void addBeanPostProcessor(BeanPostProcessor beanPostProcessor) {
    Assert.notNull(beanPostProcessor, "BeanPostProcessor must not be null");
    this.beanPostProcessors.remove(beanPostProcessor);
    this.beanPostProcessors.add(beanPostProcessor);
    if (beanPostProcessor instanceof InstantiationAwareBeanPostProcessor) {
        this.hasInstantiationAwareBeanPostProcessors = true;
    }
    if (beanPostProcessor instanceof DestructionAwareBeanPostProcessor) {
        this.hasDestructionAwareBeanPostProcessors = true;
    }
}
DisposableBeanAdapter.java 文件源码 项目:lams 阅读 17 收藏 0 点赞 0 评论 0
@Override
public void destroy() {
    if (this.beanPostProcessors != null && !this.beanPostProcessors.isEmpty()) {
        for (DestructionAwareBeanPostProcessor processor : this.beanPostProcessors) {
            processor.postProcessBeforeDestruction(this.bean, this.beanName);
        }
    }

    if (this.invokeDisposableBean) {
        if (logger.isDebugEnabled()) {
            logger.debug("Invoking destroy() on bean with name '" + this.beanName + "'");
        }
        try {
            if (System.getSecurityManager() != null) {
                AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
                    @Override
                    public Object run() throws Exception {
                        ((DisposableBean) bean).destroy();
                        return null;
                    }
                }, acc);
            }
            else {
                ((DisposableBean) bean).destroy();
            }
        }
        catch (Throwable ex) {
            String msg = "Invocation of destroy method failed on bean with name '" + this.beanName + "'";
            if (logger.isDebugEnabled()) {
                logger.warn(msg, ex);
            }
            else {
                logger.warn(msg + ": " + ex);
            }
        }
    }

    if (this.destroyMethod != null) {
        invokeCustomDestroyMethod(this.destroyMethod);
    }
    else if (this.destroyMethodName != null) {
        Method methodToCall = determineDestroyMethod();
        if (methodToCall != null) {
            invokeCustomDestroyMethod(methodToCall);
        }
    }
}
DisposableBeanAdapter.java 文件源码 项目:spring4-understanding 阅读 17 收藏 0 点赞 0 评论 0
@Override
public void destroy() {
    if (!CollectionUtils.isEmpty(this.beanPostProcessors)) {
        for (DestructionAwareBeanPostProcessor processor : this.beanPostProcessors) {
            processor.postProcessBeforeDestruction(this.bean, this.beanName);
        }
    }

    if (this.invokeDisposableBean) {
        if (logger.isDebugEnabled()) {
            logger.debug("Invoking destroy() on bean with name '" + this.beanName + "'");
        }
        try {
            if (System.getSecurityManager() != null) {
                AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
                    @Override
                    public Object run() throws Exception {
                        ((DisposableBean) bean).destroy();
                        return null;
                    }
                }, acc);
            }
            else {
                ((DisposableBean) bean).destroy();
            }
        }
        catch (Throwable ex) {
            String msg = "Invocation of destroy method failed on bean with name '" + this.beanName + "'";
            if (logger.isDebugEnabled()) {
                logger.warn(msg, ex);
            }
            else {
                logger.warn(msg + ": " + ex);
            }
        }
    }

    if (this.destroyMethod != null) {
        invokeCustomDestroyMethod(this.destroyMethod);
    }
    else if (this.destroyMethodName != null) {
        Method methodToCall = determineDestroyMethod();
        if (methodToCall != null) {
            invokeCustomDestroyMethod(methodToCall);
        }
    }
}
DisposableBeanAdapter.java 文件源码 项目:spring 阅读 17 收藏 0 点赞 0 评论 0
@Override
public void destroy() {
    if (!CollectionUtils.isEmpty(this.beanPostProcessors)) {
        for (DestructionAwareBeanPostProcessor processor : this.beanPostProcessors) {
            processor.postProcessBeforeDestruction(this.bean, this.beanName);
        }
    }

    if (this.invokeDisposableBean) {
        if (logger.isDebugEnabled()) {
            logger.debug("Invoking destroy() on bean with name '" + this.beanName + "'");
        }
        try {
            if (System.getSecurityManager() != null) {
                AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
                    @Override
                    public Object run() throws Exception {
                        ((DisposableBean) bean).destroy();
                        return null;
                    }
                }, acc);
            }
            else {
                ((DisposableBean) bean).destroy();
            }
        }
        catch (Throwable ex) {
            String msg = "Invocation of destroy method failed on bean with name '" + this.beanName + "'";
            if (logger.isDebugEnabled()) {
                logger.warn(msg, ex);
            }
            else {
                logger.warn(msg + ": " + ex);
            }
        }
    }

    if (this.destroyMethod != null) {
        invokeCustomDestroyMethod(this.destroyMethod);
    }
    else if (this.destroyMethodName != null) {
        Method methodToCall = determineDestroyMethod();
        if (methodToCall != null) {
            invokeCustomDestroyMethod(methodToCall);
        }
    }
}
DisposableBeanAdapter.java 文件源码 项目:class-guard 阅读 16 收藏 0 点赞 0 评论 0
public void destroy() {
    if (this.beanPostProcessors != null && !this.beanPostProcessors.isEmpty()) {
        for (DestructionAwareBeanPostProcessor processor : this.beanPostProcessors) {
            processor.postProcessBeforeDestruction(this.bean, this.beanName);
        }
    }

    if (this.invokeDisposableBean) {
        if (logger.isDebugEnabled()) {
            logger.debug("Invoking destroy() on bean with name '" + this.beanName + "'");
        }
        try {
            if (System.getSecurityManager() != null) {
                AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
                    public Object run() throws Exception {
                        ((DisposableBean) bean).destroy();
                        return null;
                    }
                }, acc);
            }
            else {
                ((DisposableBean) bean).destroy();
            }
        }
        catch (Throwable ex) {
            String msg = "Invocation of destroy method failed on bean with name '" + this.beanName + "'";
            if (logger.isDebugEnabled()) {
                logger.warn(msg, ex);
            }
            else {
                logger.warn(msg + ": " + ex);
            }
        }
    }

    if (this.destroyMethod != null) {
        invokeCustomDestroyMethod(this.destroyMethod);
    }
    else if (this.destroyMethodName != null) {
        Method methodToCall = determineDestroyMethod();
        if (methodToCall != null) {
            invokeCustomDestroyMethod(methodToCall);
        }
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号