ludc
2025-01-16 986aa62ed00bee39363bab41b4eeb8259d446efd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.vci.server.cache;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
import org.apache.commons.lang3.StringUtils;
 
import com.alibaba.fastjson.JSONObject;
import com.vci.corba.framework.data.PvolumeInfo;
import com.vci.server.cache.redis.RedisUtil;
 
public final class VolumeCacheProvider {
    
    public static PvolumeInfo getVolume(String name) {
        String attrObj = RedisUtil.getInstance().hget(CacheNames.VOLUMES, name);
        if (StringUtils.isBlank(attrObj))
            return null;
        
        return JSONObject.parseObject(attrObj, PvolumeInfo.class);
    }
    
    public static PvolumeInfo[] getVolumes(String[] names) {
        List<PvolumeInfo> lstAI = new ArrayList<PvolumeInfo>();
        for (int i = 0; i < names.length; i++) {
            String jsonObj = RedisUtil.getInstance().hget(CacheNames.VOLUMES, names[i]);
            if (StringUtils.isBlank(jsonObj))
                continue;
            
            lstAI.add(JSONObject.parseObject(jsonObj, PvolumeInfo.class));
        }
        
        return lstAI.toArray(new PvolumeInfo[0]);
    }
 
    
    public static PvolumeInfo[] getAllVolumes() {
        Map<String, String> allVols = RedisUtil.getInstance().hgetAll(CacheNames.VOLUMES);
        
        List<PvolumeInfo> lstAI = new ArrayList<PvolumeInfo>();
        String[] items = allVols.values().toArray(new String[0]);
        for (int i = 0; i < items.length; i++) {
            lstAI.add(JSONObject.parseObject(items[i], PvolumeInfo.class));
        }
        
        return lstAI.toArray(new PvolumeInfo[0]);
    }
 
 
}