Search in sources :

Example 1 with AliyunProvider

use of com.jeesuite.cos.provider.aliyun.AliyunProvider in project jeesuite-libs by vakinge.

the class CosProviderServiceFacade method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    // 
    if (defaultBucket == null) {
        defaultBucket = ResourceUtils.getProperty("cos.defaultBucket");
    }
    if (type == null) {
        type = ResourceUtils.getAndValidateProperty("cos.provider");
    }
    if (config == null) {
        config = new CosProviderConfig();
        config.setAccessKey(ResourceUtils.getProperty("cos.accessKey"));
        config.setSecretKey(ResourceUtils.getProperty("cos.secretKey"));
        config.setAppId(ResourceUtils.getProperty("cos.appId"));
        config.setRegionName(ResourceUtils.getProperty("cos.regionName"));
        config.setMaxConnectionsCount(ResourceUtils.getInt("cos.maxConnections", 200));
    }
    if (AliyunProvider.NAME.equals(type)) {
        provider = new AliyunProvider(config);
    } else if (QcloudProvider.NAME.equals(type)) {
        provider = new QcloudProvider(config);
    } else if (QiniuProvider.NAME.equals(type)) {
        provider = new QiniuProvider(config);
    } else {
        throw new JeesuiteBaseException("cos[" + type + "] not support");
    }
    if (defaultBucket != null) {
        BucketConfig bucketConfig = provider.getBucketConfig(defaultBucket);
        bucketConfig.setUrlPrefix(ResourceUtils.getProperty("cos.defaultUrlPrefix"));
        ((AbstractProvider) provider).addBucketConfig(bucketConfig);
    } else {
        Map<String, String> urlPrefixMappings = ResourceUtils.getMappingValues("cos.bucket.urlPrefix.mapping");
        if (urlPrefixMappings != null) {
            urlPrefixMappings.forEach((bucket, urlPrefix) -> {
                BucketConfig bucketConfig = provider.getBucketConfig(defaultBucket);
                bucketConfig.setUrlPrefix(ResourceUtils.getProperty("cos.defaultUrlPrefix"));
                ((AbstractProvider) provider).addBucketConfig(bucketConfig);
            });
        }
    }
    logUrl = ResourceUtils.getProperty("cos.loghandler.url");
    if (logUrl != null && Boolean.parseBoolean(ResourceUtils.getProperty("cos.loghandler.enabled", "true"))) {
        int nThread = ResourceUtils.getInt("cos.loghandler.threads", 1);
        int capacity = ResourceUtils.getInt("cos.loghandler.queueSize", 1000);
        logHandleExecutor = new ThreadPoolExecutor(nThread, nThread, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(capacity), new StandardThreadFactory("cosLogHandleExecutor"));
        logger.info("init logHandleExecutor OK ,nThread:{},queue:{}", nThread, capacity);
    }
}
Also used : AbstractProvider(com.jeesuite.cos.provider.AbstractProvider) AliyunProvider(com.jeesuite.cos.provider.aliyun.AliyunProvider) StandardThreadFactory(com.jeesuite.common.async.StandardThreadExecutor.StandardThreadFactory) QiniuProvider(com.jeesuite.cos.provider.qiniu.QiniuProvider) QcloudProvider(com.jeesuite.cos.provider.qcloud.QcloudProvider) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Aggregations

JeesuiteBaseException (com.jeesuite.common.JeesuiteBaseException)1 StandardThreadFactory (com.jeesuite.common.async.StandardThreadExecutor.StandardThreadFactory)1 AbstractProvider (com.jeesuite.cos.provider.AbstractProvider)1 AliyunProvider (com.jeesuite.cos.provider.aliyun.AliyunProvider)1 QcloudProvider (com.jeesuite.cos.provider.qcloud.QcloudProvider)1 QiniuProvider (com.jeesuite.cos.provider.qiniu.QiniuProvider)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1