コード例 #1
0
  public static void main(String args[]) {
    // PhpClientWatcher client = new PhpClientWatcher(new ZKManager());
    List<String> list = new ArrayList<String>();
    list.add("master@@@db_pay_info_0001@@@192.168.1.1_3");
    list.add("master@@@db_pay_info_0001@@@192.168.1.2_2");
    list.add("master@@@db_pay_info_0002@@@192.168.1.1_3");
    list.add("master@@@db_pay_info_0002@@@192.168.1.2_2");
    list.add("slave@@@db_pay_info_0001@@@192.168.1.3_3");
    list.add("slave@@@db_pay_info_0001@@@192.168.1.4_3");
    list.add("slave@@@db_pay_info_0002@@@192.168.1.3_3");
    list.add("slave@@@db_pay_info_0002@@@192.168.1.4_3");
    System.out.println(FileUtil.listToString(list, null, "mmall@@@db_pay_info_config"));

    String node_path = "mmall@@@db_pay_info_config";

    PhpClientDO php = new PhpClientDO();
    String[] strs = node_path.split(FileUtil.SPLIT_STR);
    php.setAppName(strs[0]);
    php.setDbConfigName(strs[1]);
    php.setGenerateFilePath("/app/" + strs[0] + "/includes/db_config.php");
    php.setChildPath(node_path + "/base_config");
    php.setNodePath(node_path);

    System.out.println(php.getGenerateFilePath());
    FileUtil.writeFile(
        "E:\\db_config.php", "<?php\n" + FileUtil.listToString(list, null, php.getDbConfigName()));

    // String baseConfig =
    // "host=192.168.1.1;user_name=lhs001;pass_word=123456;consistent_hash_separate_string='[0,256w]=sc_refund_0000;[256w,512w]=sc_refund_0001;[512,768]=sc_refund_0002;[768,1024]=sc_refund_0003;'";
    // baseConfig="$a['host']='192.168.1.1';$a['user_name']=lhs001;$a['pass_word']=123456;consistent_hash_separate_string='[0,256w]=sc_refund_0000;[256w,512w]=sc_refund_0001;[512,768]=sc_refund_0002;[768,1024]=sc_refund_0003;'";
  }
コード例 #2
0
 private void setPhpClientList(ZKManager zkmanager) {
   List<String> phpClients = zkmanager.getPhpClient();
   Map<String, String> generatePathMap = this.zkmanager.getGeneratePath();
   String zkRootPath = zkmanager.getZkRootPath();
   if (!phpClients.isEmpty()) {
     for (String path : phpClients) {
       PhpClientDO client = new PhpClientDO();
       String[] strs = path.split(FileUtil.SPLIT_STR);
       client.setAppName(strs[0]);
       client.setDbConfigName(strs[1]);
       client.setGenerateFilePath(generatePathMap.get(strs[0]));
       client.setChildPath(zkRootPath + ZKManager.ZK_SEPARATOR + path + "/base_config");
       client.setNodePath(zkRootPath + ZKManager.ZK_SEPARATOR + path);
       phpClientList.add(client);
     }
   }
 }