All Downloads are FREE. Search and download functionalities are using the official Maven repository.

chao.java.tools.servicepool.cache.Once Maven / Gradle / Ivy

There is a newer version: 1.9.0
Show newest version
package chao.java.tools.servicepool.cache;

import chao.java.tools.servicepool.IService;
import chao.java.tools.servicepool.IServiceFactory;
import chao.java.tools.servicepool.ReflectUtil;

/**
 * 每次获取时创建一个新的对象
 */
public final class Once extends AbsServiceCacheStrategy {

    private IServiceFactory factory;

    public Once(IServiceFactory factory) {
        this.factory = factory;
    }

    @Override
    public T getService(Class serviceClass, Class originClass) {
        IService instance;
        if (factory != null) {
            instance = factory.createInstance(serviceClass);
        } else {
            instance = ReflectUtil.newInstance(serviceClass);
        }
        if (instance != null) {
            return getProxyService(originClass, serviceClass.cast(instance));
        }
        return null;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy