shikeying
2024-05-08 19ab3a8c760fa5e7e6cfab1b2ff97c187589efae
walker-infrastructure/src/main/java/com/walker/infrastructure/arguments/AbstractArgumentsManager.java
@@ -2,7 +2,6 @@
import com.walker.infrastructure.arguments.support.DefaultVariable;
import com.walker.infrastructure.utils.StringUtils;
import com.walker.security.SystemLogMan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -22,42 +21,41 @@
public abstract class AbstractArgumentsManager implements ArgumentsManager {
   protected Logger logger = LoggerFactory.getLogger(getClass());
   private Object source;
   /* 分组集合 */
   private Map<String, Group> groupMap = new TreeMap<String, Group>();
   /* 变量集合与组ID映射关系:key=groupId, value=variable ID set */
   private ConcurrentHashMap<String, List<String>> variableMap = new ConcurrentHashMap<String, List<String>>(8);
   private ConcurrentHashMap<String, Variable> allVars = new ConcurrentHashMap<String, Variable>(32);
   private Object lock = new Object();
   @Override
   public void setSource(Object source){
      assert (source != null);
      this.source = source;
   }
   @Override
   public void afterPropertiesSet() throws Exception{
      SystemLogMan.getInstance().checkMan();
//      if(this.source == null){
//         throw new ArgumentsException("parameter: source is not found!");
//      }
      List<Group> groupList = null;
      try{
         groupList = load(source);
      } catch(Exception ex){
         throw new ArgumentsException("业务加载配置参数失败:" + ex.getMessage(), ex);
      }
      initGroup(groupList);
      if(logger.isDebugEnabled()){
         logger.debug("~~~~~~~~~~~~~~~~~ 系统加载所有配置参数-start ~~~~~~~~~~~~~~~~~");
         for(Variable v : allVars.values()){
@@ -66,7 +64,7 @@
         logger.debug("~~~~~~~~~~~~~~~~~ 系统加载所有配置参数-end ~~~~~~~~~~~~~~~~~");
      }
   }
   private void initGroup(List<Group> groupList){
      if(groupList != null){
         Collections.sort(groupList);
@@ -76,7 +74,7 @@
         }
      }
   }
   private void initVariableInGroup(Group group){
      List<Variable> varList = group.getChildren();
      if(varList != null && varList.size() > 0){
@@ -89,7 +87,7 @@
      } else
         variableMap.put(group.getId(), null);
   }
   /**
    * 加载具体的参数数据,并返回分组集合信息,分组中包含了可变参数数据。</p>
    * 子类实现具体加载过程。
@@ -97,15 +95,15 @@
    * @return
    */
   protected abstract List<Group> load(Object source) throws Exception;
   /**
    * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    *
    *
    * 以下为系统提供的标准API
    *
    *
    * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    */
   @Override
   public Variable getVariable(String id) {
      assert (StringUtils.isNotEmpty(id));
@@ -127,19 +125,19 @@
   public void persist(String groupId, String variableId, Object value) {
      assert (StringUtils.isNotEmpty(groupId));
      assert (value != null);
      /* 更新实体中的数据 */
      try {
         saveVariable(groupId, variableId, value);
      } catch (Exception e) {
         throw new ArgumentsException("更新可变参数到业务中出现错误: " + e.getMessage(), e);
      }
      synchronized (lock) {
         updateCache(groupId, variableId, value);
      }
   }
   private void updateCache(String groupId, String variableId, Object value){
      if(groupMap.get(groupId) == null)
         throw new IllegalArgumentException("not found group id: " + groupId);
@@ -153,7 +151,7 @@
      } else
         throw new ElementNotFoundException("var id: " + variableId);
   }
   @Override
   public void persist(List<Object[]> changedList){
      if(changedList == null) return;
@@ -167,21 +165,21 @@
         if(arr[2] == null)
            throw new IllegalArgumentException("第三个参数:value不存在或者是空值");
      }
      /* 更新实体中的数据 */
      try {
         saveVariables(changedList);
      } catch (Exception e) {
         throw new ArgumentsException("更新可变参数到业务中出现错误: " + e.getMessage(), e);
      }
      synchronized (lock){
         for(Object[] args : changedList){
            updateCache(args[0].toString(), args[1].toString(), args[2]);
         }
      }
   }
   @Override
   public void insert(List<Object[]> insertList) {
      if(insertList == null) return;
@@ -199,14 +197,14 @@
      } catch (Exception e) {
         throw new ArgumentsException("新建可变参数出现错误: " + e.getMessage(), e);
      }
      synchronized (lock){
         for(Object[] args : insertList){
            insertCache((Group)args[0], (Variable)args[1]);
         }
      }
   }
   /**
    * 由子类来实现具体的更新介质中的参数,如:数据库、配置文件等。
    * @param groupId 分组ID
@@ -216,7 +214,7 @@
    */
   protected abstract void saveVariable(String groupId
         , String variableId, Object value) throws Exception;
   /**
    * 子类实现持久化更新参数信息到介质中,如:数据库、配置文件等。</p>
    * 批量更新方法,集合中是数组对象,Object[]{groupId, variableId, value}</br>
@@ -225,7 +223,7 @@
    * @throws Exception
    */
   protected abstract void saveVariables(List<Object[]> changedList) throws Exception;
   /**
    * 加入新的参数集合,集合中是数组对象,Object[]{group, variable}
    * 如果已经存在该参数,则不再创建。
@@ -251,7 +249,7 @@
         varList.add(variable.getId());
      }
   }
   @Override
   public List<Group> getGroupList() {
      if(groupMap.size() == 0) return null;
@@ -272,7 +270,7 @@
      List<String> varIds = variableMap.get(groupId);
      if(varIds == null)
         return null;
      List<Variable> result = new ArrayList<Variable>(8);
      Variable var = null;
      for(String vid : varIds){