當前位置: 首頁>>代碼示例>>Java>>正文


Java DataSourceFetcher類代碼示例

本文整理匯總了Java中com.taobao.tddl.group.jdbc.DataSourceFetcher的典型用法代碼示例。如果您正苦於以下問題:Java DataSourceFetcher類的具體用法?Java DataSourceFetcher怎麽用?Java DataSourceFetcher使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DataSourceFetcher類屬於com.taobao.tddl.group.jdbc包,在下文中一共展示了DataSourceFetcher類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: buildDataSourceWrapperSequential

import com.taobao.tddl.group.jdbc.DataSourceFetcher; //導入依賴的package包/類
public static List<DataSourceWrapper> buildDataSourceWrapperSequential(String dsWeightCommaStr,
                                                                       final DataSourceFetcher fetcher) {
    final String[] dsWeightArray = dsWeightCommaStr.split(","); // 逗號分隔:db0:rwp1q1i0,
    // db1:rwp0q0i1
    List<DataSourceWrapper> dss = new ArrayList<DataSourceWrapper>(dsWeightArray.length);

    for (int i = 0; i < dsWeightArray.length; i++) {
        final int j = i;
        final String[] dsAndWeight = dsWeightArray[j].split(":"); // 冒號分隔:db0:rwp1q1i0
        final String dsKey = dsAndWeight[0].trim();
        String weightStr = dsAndWeight.length == 2 ? dsAndWeight[1] : null;
        try {
            dss.add(getDataSourceWrapper(dsKey, weightStr, j, fetcher));
        } catch (Exception e) {
            throw new RuntimeException("init ds error! atom key is " + dsKey, e);
        }
    }

    return dss;
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:21,代碼來源:GroupConfigManager.java

示例2: buildDataSourceWrapper

import com.taobao.tddl.group.jdbc.DataSourceFetcher; //導入依賴的package包/類
/**
 * @param dsWeightCommaStr : 例如 db0:rwp1q1i0, db1:rwp0q0i1
 */
public static List<DataSourceWrapper> buildDataSourceWrapper(String dsWeightCommaStr, DataSourceFetcher fetcher) {
    String[] dsWeightArray = dsWeightCommaStr.split(","); // 逗號分隔:db0:rwp1q1i0,
                                                          // db1:rwp0q0i1
    List<DataSourceWrapper> dss = new ArrayList<DataSourceWrapper>(dsWeightArray.length);
    for (int i = 0; i < dsWeightArray.length; i++) {
        String[] dsAndWeight = dsWeightArray[i].split(":"); // 冒號分隔:db0:rwp1q1i0
        String dsKey = dsAndWeight[0].trim();
        String weightStr = dsAndWeight.length == 2 ? dsAndWeight[1] : null;

        DataSourceWrapper dsw = getDataSourceWrapper(dsKey, weightStr, i, fetcher);
        dss.add(dsw);
    }
    return dss;
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:18,代碼來源:GroupConfigManager.java

示例3: getDataSourceWrapper

import com.taobao.tddl.group.jdbc.DataSourceFetcher; //導入依賴的package包/類
public static DataSourceWrapper getDataSourceWrapper(String dsKey, String weightStr, int index,
                                                     DataSourceFetcher fetcher) {
    // 如果多個group複用一個真實dataSource,會造成所有group引用
    // 這個dataSource的配置 會以最後一個dataSource的配置為準
    DataSource dataSource = fetcher.getDataSource(dsKey);
    DBType fetcherDbType = fetcher.getDataSourceDBType(dsKey);
    // dbType = fetcherDbType == null ? dbType :
    // fetcherDbType;
    DataSourceWrapper dsw = new DataSourceWrapper(dsKey, weightStr, dataSource, fetcherDbType, index);
    return dsw;
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:12,代碼來源:GroupConfigManager.java

示例4: buildDataSourceWrapperParallel

import com.taobao.tddl.group.jdbc.DataSourceFetcher; //導入依賴的package包/類
public static List<DataSourceWrapper> buildDataSourceWrapperParallel(String dsWeightCommaStr,
                                                                     final DataSourceFetcher fetcher) {
    final String[] dsWeightArray = dsWeightCommaStr.split(","); // 逗號分隔:db0:rwp1q1i0,
    // db1:rwp0q0i1
    List<DataSourceWrapper> dss = new ArrayList<DataSourceWrapper>(dsWeightArray.length);

    ThreadPoolExecutor executor = new ThreadPoolExecutor(2,
        2,
        5,
        TimeUnit.SECONDS,
        new LinkedBlockingQueue<Runnable>(),
        new NamedThreadFactory("TDDL_GROUP_INIT"),
        new ThreadPoolExecutor.CallerRunsPolicy());

    Map<String, Future<DataSourceWrapper>> m = new HashMap<String, Future<DataSourceWrapper>>();
    for (int i = 0; i < dsWeightArray.length; i++) {
        final int j = i;
        final String[] dsAndWeight = dsWeightArray[j].split(":"); // 冒號分隔:db0:rwp1q1i0
        final String dsKey = dsAndWeight[0].trim();
        Future<DataSourceWrapper> f = executor.submit(new Callable<DataSourceWrapper>() {

            @Override
            public DataSourceWrapper call() throws Exception {
                String weightStr = dsAndWeight.length == 2 ? dsAndWeight[1] : null;
                return getDataSourceWrapper(dsKey, weightStr, j, fetcher);
            }
        });

        m.put(dsKey, f);
    }

    for (Map.Entry<String, Future<DataSourceWrapper>> en : m.entrySet()) {
        try {
            dss.add(en.getValue().get());
        } catch (Exception e) {
            throw new RuntimeException("init ds error! atom key is " + en.getKey(), e);
        }
    }

    executor.shutdown();
    return dss;
}
 
開發者ID:beebeandwer,項目名稱:TDDL,代碼行數:43,代碼來源:GroupConfigManager.java


注:本文中的com.taobao.tddl.group.jdbc.DataSourceFetcher類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。