Examples of TAtomDsConfDO


Examples of com.taobao.tddl.jdbc.atom.config.object.TAtomDsConfDO

        }
        lock.lock();
        try {
          String globaConfStr = data;
          // �����ȫ�����÷����仯��������IP,PORT,DBNAME,DBTYPE,STATUS
          TAtomDsConfDO tmpConf = TAtomConfParser
              .parserTAtomDsConfDO(globaConfStr, null);
          TAtomDsConfDO newConf = TAtomDsConfHandle.this.runTimeConf
              .clone();
          // �������͵����ã����ǵ�ǰ������
          newConf.setIp(tmpConf.getIp());
          newConf.setPort(tmpConf.getPort());
          newConf.setDbName(tmpConf.getDbName());
          newConf.setDbType(tmpConf.getDbType());
          newConf.setDbStatus(tmpConf.getDbStatus());
          // ��������������
          overConfByLocal(TAtomDsConfHandle.this.localConf, newConf);
          // ������͹��������ݿ�״̬�� RW/R->NA,ֱ�����ٵ�����Դ������ҵ���߼���������
          if (AtomDbStatusEnum.NA_STATUS != TAtomDsConfHandle.this.runTimeConf
              .getDbStautsEnum()
              && AtomDbStatusEnum.NA_STATUS == tmpConf
                  .getDbStautsEnum()) {
            try {
              TAtomDsConfHandle.this.jbossDataSource.destroy();
              logger.warn("[NA STATUS PUSH] destroy DataSource !");
            } catch (Exception e) {
              logger.error(
                  "[NA STATUS PUSH] destroy DataSource  Error!",
                  e);
            }
          } else {
            // ת��tAtomDsConfDO
            LocalTxDataSourceDO localTxDataSourceDO = convertTAtomDsConf2JbossConf(
                newConf, TAtomConstants.getDbNameStr(
                    TAtomDsConfHandle.this.appName,
                    TAtomDsConfHandle.this.dbKey));
            // ���ת�������Ƿ���ȷ
            if (!checkLocalTxDataSourceDO(localTxDataSourceDO)) {
              logger.error("[GlobaConfError] dataSource Prams Error! dataId : "
                  + dataId + " config : " + data);
              return;
            }
            // ������͵�״̬ʱ NA->RW/R ʱ��Ҫ���´�������Դ��������ˢ��
            if (TAtomDsConfHandle.this.runTimeConf
                .getDbStautsEnum() == AtomDbStatusEnum.NA_STATUS
                && (newConf.getDbStautsEnum() == AtomDbStatusEnum.RW_STATUS || newConf
                    .getDbStautsEnum() == AtomDbStatusEnum.R_STAUTS)) {
              // ��������Դ
              try {
                // �ر�TB-DATASOURCE��JMXע��
                localTxDataSourceDO.setUseJmx(false);
                LocalTxDataSource localTxDataSource = TaobaoDataSourceFactory
                    .createLocalTxDataSource(localTxDataSourceDO);
                TAtomDsConfHandle.this.jbossDataSource = localTxDataSource;
                logger.warn("[NA->RW/R STATUS PUSH] ReCreate DataSource !");
              } catch (Exception e) {
                logger.error(
                    "[NA->RW/R STATUS PUSH] ReCreate DataSource Error!",
                    e);
              }
            } else {
              boolean needFlush = checkGlobaConfChange(
                  TAtomDsConfHandle.this.runTimeConf, newConf);
              // ������������ñ仯�Ƿ���Ҫ�ؽ�����Դ
              if (needFlush) {
                TAtomDsConfHandle.this.jbossDataSource
                    .setConnectionURL(localTxDataSourceDO
                        .getConnectionURL());
                TAtomDsConfHandle.this.jbossDataSource
                    .setDriverClass(localTxDataSourceDO
                        .getDriverClass());
                TAtomDsConfHandle.this.jbossDataSource
                    .setExceptionSorterClassName(localTxDataSourceDO
                        .getExceptionSorterClassName());
                try {
                  // ��������Դ
                  TAtomDsConfHandle.this.flushDataSource();
                } catch (Exception e) {
                  logger.error(
                      "[Flsh GlobaConf Error] flush dataSource Error !",
                      e);
                }
              }
            }
          }
          //�������ݿ�״̬������
          processDbStatusListener(TAtomDsConfHandle.this.runTimeConf.getDbStautsEnum(),
              newConf.getDbStautsEnum());
          //�����µ����ø�������ʱ������
          TAtomDsConfHandle.this.runTimeConf = newConf;
          clearDataSourceWrapper();
        } finally {
          lock.unlock();
        }
      }

      private boolean checkGlobaConfChange(TAtomDsConfDO runConf,
          TAtomDsConfDO newConf) {
        boolean needFlush = false;
        if (!TStringUtil.equals(runConf.getIp(), newConf.getIp())) {
          needFlush = true;
          return needFlush;
        }
        if (!TStringUtil.equals(runConf.getPort(), newConf.getPort())) {
          needFlush = true;
          return needFlush;
        }
        if (!TStringUtil.equals(runConf.getDbName(), newConf.getDbName())) {
          needFlush = true;
          return needFlush;
        }
        if (runConf.getDbTypeEnum() != newConf.getDbTypeEnum()) {
          needFlush = true;
          return needFlush;
        }
        return needFlush;
      }
View Full Code Here

Examples of com.taobao.tddl.jdbc.atom.config.object.TAtomDsConfDO

          return;
        }
        lock.lock();
        try {
          String appConfStr = data;
          TAtomDsConfDO tmpConf = TAtomConfParser
              .parserTAtomDsConfDO(null, appConfStr);
          TAtomDsConfDO newConf = TAtomDsConfHandle.this.runTimeConf
              .clone();
          // ��Щ�������ò��ܱ�������Կ�¡�ϵ����ã�Ȼ���µ�set��ȥ
          newConf.setUserName(tmpConf.getUserName());
          newConf.setMinPoolSize(tmpConf.getMinPoolSize());
          newConf.setMaxPoolSize(tmpConf.getMaxPoolSize());
          newConf.setIdleTimeout(tmpConf.getIdleTimeout());
          newConf.setBlockingTimeout(tmpConf.getBlockingTimeout());
          newConf.setPreparedStatementCacheSize(tmpConf
              .getPreparedStatementCacheSize());
          newConf.setConnectionProperties(tmpConf
              .getConnectionProperties());
          newConf.setOracleConType(tmpConf.getOracleConType());
          // ����3�������ʵ��
          newConf.setWriteRestrictTimes(tmpConf
              .getWriteRestrictTimes());
          newConf.setReadRestrictTimes(tmpConf.getReadRestrictTimes());
          newConf.setThreadCountRestrict(tmpConf
              .getThreadCountRestrict());
          newConf.setTimeSliceInMillis(tmpConf.getTimeSliceInMillis());
          // ��������������
          overConfByLocal(TAtomDsConfHandle.this.localConf, newConf);
          // ת��tAtomDsConfDO
          LocalTxDataSourceDO localTxDataSourceDO = convertTAtomDsConf2JbossConf(
              newConf, TAtomConstants.getDbNameStr(
                  TAtomDsConfHandle.this.appName,
                  TAtomDsConfHandle.this.dbKey));
          // ���ת�������Ƿ���ȷ
          if (!checkLocalTxDataSourceDO(localTxDataSourceDO)) {
            logger.error("[GlobaConfError] dataSource Prams Error! dataId : "
                + dataId + " config : " + data);
            return;
          }
          boolean isNeedReCreate = isNeedReCreate(
              TAtomDsConfHandle.this.runTimeConf, newConf);
          if (isNeedReCreate) {
            try {
              TAtomDsConfHandle.this.jbossDataSource.destroy();
              logger.warn("[destroy OldDataSource] dataId : "
                  + dataId);
              LocalTxDataSource localTxDataSource = TaobaoDataSourceFactory
                  .createLocalTxDataSource(localTxDataSourceDO);
              logger.warn("[create newDataSource] dataId : "
                  + dataId);
              TAtomDsConfHandle.this.jbossDataSource = localTxDataSource;
              clearDataSourceWrapper();
              TAtomDsConfHandle.this.runTimeConf = newConf;
            } catch (Exception e) {
              logger.error(
                  "[Flsh AppConf Error] reCreate dataSource Error ! dataId: "
                      + dataId, e);
            }
          } else {
            boolean isNeedFlush = isNeedFlush(
                TAtomDsConfHandle.this.runTimeConf, newConf);
            /**
             * ��ֵ�仯����ˢ�³��е�����Դ��ֻҪ����runTimeConf���������wrapDataSource
             */
            boolean isRestrictChange = isRestrictChange(
                TAtomDsConfHandle.this.runTimeConf, newConf);
            if (isNeedFlush) {
              TAtomDsConfHandle.this.jbossDataSource
                  .setConnectionURL(localTxDataSourceDO
                      .getConnectionURL());
              TAtomDsConfHandle.this.jbossDataSource
                  .setUserName(localTxDataSourceDO
                      .getUserName());
              try {
                // ��������Դ
                TAtomDsConfHandle.this.flushDataSource();
                // �����µ����ø�������ʱ������
                TAtomDsConfHandle.this.runTimeConf = newConf;
                clearDataSourceWrapper();
              } catch (Exception e) {
                logger.error(
                    "[Flash GlobaConf Error] flush dataSource Error !",
                    e);
              }
            } else if (isRestrictChange) {
              TAtomDsConfHandle.this.runTimeConf = newConf;
              clearDataSourceWrapper();
            }
          }
        } finally {
          lock.unlock();
        }
      }

      private boolean isNeedReCreate(TAtomDsConfDO runConf,
          TAtomDsConfDO newConf) {
        boolean needReCreate = false;
        if (AtomDbTypeEnum.ORACLE == newConf.getDbTypeEnum()) {
          Map<String, String> newProp = newConf
              .getConnectionProperties();
          Map<String, String> runProp = runConf
              .getConnectionProperties();
          if (!runProp.equals(newProp)) {
            return true;
          }
        }
        if (runConf.getMinPoolSize() != newConf.getMinPoolSize()) {
          return true;
        }
        if (runConf.getMaxPoolSize() != newConf.getMaxPoolSize()) {
          return true;
        }
        if (runConf.getBlockingTimeout() != newConf
            .getBlockingTimeout()) {
          return true;
        }
        if (runConf.getIdleTimeout() != newConf.getIdleTimeout()) {
          return true;
        }
        if (runConf.getPreparedStatementCacheSize() != newConf
            .getPreparedStatementCacheSize()) {
          return true;
        }
        return needReCreate;
      }

      private boolean isNeedFlush(TAtomDsConfDO runConf,
          TAtomDsConfDO newConf) {
        boolean needFlush = false;
        if (AtomDbTypeEnum.MYSQL == newConf.getDbTypeEnum()) {
          Map<String, String> newProp = newConf
              .getConnectionProperties();
          Map<String, String> runProp = runConf
              .getConnectionProperties();
          if (!runProp.equals(newProp)) {
            return true;
          }
        }
        if (!TStringUtil.equals(runConf.getUserName(),
            newConf.getUserName())) {
          return true;
        }
        if (!TStringUtil.equals(runConf.getPasswd(), newConf.getPasswd())) {
          return true;
        }
        return needFlush;
      }

      private boolean isRestrictChange(TAtomDsConfDO runConf,
          TAtomDsConfDO newConf) {
        if (runConf.getReadRestrictTimes() != newConf
            .getReadRestrictTimes()) {
          return true;
        }

        if (runConf.getWriteRestrictTimes() != newConf
            .getWriteRestrictTimes()) {
          return true;
        }

        if (runConf.getThreadCountRestrict() != newConf
            .getThreadCountRestrict()) {
          return true;
        }

        if (runConf.getTimeSliceInMillis() != newConf
            .getTimeSliceInMillis()) {
          return true;
        }

        return false;
View Full Code Here

Examples of com.taobao.tddl.jdbc.atom.config.object.TAtomDsConfDO

  public static final String APP_THREAD_COUNT_RESTRICT = "threadCountRestrict";
 
  public static final String APP_TIME_SLICE_IN_MILLS = "timeSliceInMillis";
 
  public static TAtomDsConfDO parserTAtomDsConfDO(String globaConfStr, String appConfStr) {
    TAtomDsConfDO pasObj = new TAtomDsConfDO();
    if (TStringUtil.isNotBlank(globaConfStr)) {
      Properties globaProp = TAtomConfParser.parserConfStr2Properties(globaConfStr);
      if (!globaProp.isEmpty()) {
        String ip = TStringUtil.trim(globaProp.getProperty(TAtomConfParser.GLOBA_IP_KEY));
        if (TStringUtil.isNotBlank(ip)) {
          pasObj.setIp(ip);
        }
        String port = TStringUtil.trim(globaProp.getProperty(TAtomConfParser.GLOBA_PORT_KEY));
        if (TStringUtil.isNotBlank(port)) {
          pasObj.setPort(port);
        }
        String dbName = TStringUtil.trim(globaProp.getProperty(TAtomConfParser.GLOBA_DB_NAME_KEY));
        if (TStringUtil.isNotBlank(dbName)) {
          pasObj.setDbName(dbName);
        }
        String dbType = TStringUtil.trim(globaProp.getProperty(TAtomConfParser.GLOBA_DB_TYPE_KEY));
        if (TStringUtil.isNotBlank(dbType)) {
          pasObj.setDbType(dbType);
        }
        String dbStatus = TStringUtil.trim(globaProp.getProperty(TAtomConfParser.GLOBA_DB_STATUS_KEY));
        if (TStringUtil.isNotBlank(dbStatus)) {
          pasObj.setDbStatus(dbStatus);
        }
      }
    }
    if (TStringUtil.isNotBlank(appConfStr)) {
      Properties appProp = TAtomConfParser.parserConfStr2Properties(appConfStr);
      if (!appProp.isEmpty()) {
        String userName = TStringUtil.trim(appProp.getProperty(TAtomConfParser.APP_USER_NAME_KEY));
        if (TStringUtil.isNotBlank(userName)) {
          pasObj.setUserName(userName);
        }
        String oracleConType = TStringUtil.trim(appProp.getProperty(TAtomConfParser.APP_ORACLE_CON_TYPE_KEY));
        if (TStringUtil.isNotBlank(oracleConType)) {
          pasObj.setOracleConType(oracleConType);
        }
        String minPoolSize = TStringUtil.trim(appProp.getProperty(TAtomConfParser.APP_MIN_POOL_SIZE_KEY));
        if (TStringUtil.isNotBlank(minPoolSize)&&TStringUtil.isNumeric(minPoolSize)) {
          pasObj.setMinPoolSize(Integer.valueOf(minPoolSize));
        }
        String maxPoolSize = TStringUtil.trim(appProp.getProperty(TAtomConfParser.APP_MAX_POOL_SIZE_KEY));
        if (TStringUtil.isNotBlank(maxPoolSize)&&TStringUtil.isNumeric(maxPoolSize)) {
          pasObj.setMaxPoolSize(Integer.valueOf(maxPoolSize));
        }
        String idleTimeout = TStringUtil.trim(appProp.getProperty(TAtomConfParser.APP_IDLE_TIMEOUT_KEY));
        if (TStringUtil.isNotBlank(idleTimeout)&&TStringUtil.isNumeric(idleTimeout)) {
          pasObj.setIdleTimeout(Long.valueOf(idleTimeout));
        }
        String blockingTimeout = TStringUtil.trim(appProp.getProperty(TAtomConfParser.APP_BLOCKING_TIMEOUT_KEY));
        if (TStringUtil.isNotBlank(blockingTimeout)&&TStringUtil.isNumeric(blockingTimeout)) {
          pasObj.setBlockingTimeout(Integer.valueOf(blockingTimeout));
        }
        String preparedStatementCacheSize = TStringUtil.trim(appProp
            .getProperty(TAtomConfParser.APP_PREPARED_STATEMENT_CACHE_SIZE_KEY));
        if (TStringUtil.isNotBlank(preparedStatementCacheSize)&&TStringUtil.isNumeric(preparedStatementCacheSize)) {
          pasObj.setPreparedStatementCacheSize(Integer.valueOf(preparedStatementCacheSize));
        }
       
        String writeRestrictTimes = TStringUtil.trim(appProp.getProperty(TAtomConfParser.APP_WRITE_RESTRICT_TIMES));
        if(TStringUtil.isNotBlank(writeRestrictTimes)&&TStringUtil.isNumeric(writeRestrictTimes)){
          pasObj.setWriteRestrictTimes(Integer.valueOf(writeRestrictTimes));
        }
       
        String readRestrictTimes = TStringUtil.trim(appProp.getProperty(TAtomConfParser.APP_READ_RESTRICT_TIMES));
        if(TStringUtil.isNotBlank(readRestrictTimes)&&TStringUtil.isNumeric(readRestrictTimes)){
          pasObj.setReadRestrictTimes(Integer.valueOf(readRestrictTimes));
        }
        String threadCountRestrict = TStringUtil.trim(appProp.getProperty(TAtomConfParser.APP_THREAD_COUNT_RESTRICT));
        if(TStringUtil.isNotBlank(threadCountRestrict)&&TStringUtil.isNumeric(threadCountRestrict)){
          pasObj.setThreadCountRestrict(Integer.valueOf(threadCountRestrict));
        }
        String timeSliceInMillis = TStringUtil.trim(appProp.getProperty(TAtomConfParser.APP_TIME_SLICE_IN_MILLS));
        if(TStringUtil.isNotBlank(timeSliceInMillis)&&TStringUtil.isNumeric(timeSliceInMillis)){
          pasObj.setTimeSliceInMillis(Integer.valueOf(timeSliceInMillis));
        }
       
        String conPropStr = TStringUtil.trim(appProp.getProperty(TAtomConfParser.APP_CON_PROP_KEY));
        Map<String, String> connectionProperties = parserConPropStr2Map(conPropStr);
        if (null != connectionProperties && !connectionProperties.isEmpty()) {
          pasObj.setConnectionProperties(connectionProperties);
        }
      }
    }
    return pasObj;
  }
View Full Code Here

Examples of com.taobao.tddl.jdbc.atom.config.object.TAtomDsConfDO

    MockServer.setConfigInfo(TAtomConstants.getGlobalDataId(dbKey), globaStr);
    //Ӧ������
    String appStr = PropLoadTestUtil.loadPropFile2String("conf/" + configName + "/app.properties");
    MockServer.setConfigInfo(TAtomConstants.getAppDataId(appName, dbKey), appStr);
    //��������
    TAtomDsConfDO tAtomDsConfDO = TAtomConfParser.parserTAtomDsConfDO(globaStr, appStr);
    Properties passwdProp = PropLoadTestUtil.loadPropFromFile("conf/" + configName + "/psswd.properties");
    String passwdDataId = TAtomConstants.getPasswdDataId(tAtomDsConfDO.getDbName(), tAtomDsConfDO.getDbType(),
        tAtomDsConfDO.getUserName());
    MockServer.setConfigInfo(passwdDataId, PropLoadTestUtil.convertProp2Str(change.doChange(passwdProp)));
    Thread.sleep(1200);
    //�ڴ����ִ���
    boolean result = false;
    try {
View Full Code Here

Examples of com.taobao.tddl.jdbc.atom.config.object.TAtomDsConfDO

    MockServer.setConfigInfo(TAtomConstants.getGlobalDataId(dbKey), globaStr);
    //Ӧ������
    String appStr = PropLoadTestUtil.loadPropFile2String("conf/" + configName + "/app.properties");
    MockServer.setConfigInfo(TAtomConstants.getAppDataId(appName, dbKey), appStr);
    //��������
    TAtomDsConfDO tAtomDsConfDO = TAtomConfParser.parserTAtomDsConfDO(globaStr, appStr);
    //��������
    String passwdStr = PropLoadTestUtil.loadPropFile2String("conf/" + configName + "/psswd.properties");
    MockServer.setConfigInfo(
        TAtomConstants.getPasswdDataId(tAtomDsConfDO.getDbName(), tAtomDsConfDO.getDbType(),
            tAtomDsConfDO.getUserName()), passwdStr);
    //���г�ʼ��
    TAtomDataSource tAtomDataSource = new TAtomDataSource();
    tAtomDataSource.setAppName(appName);
    tAtomDataSource.setDbKey(dbKey);
    tAtomDataSource.init();
View Full Code Here

Examples of com.taobao.tddl.jdbc.atom.config.object.TAtomDsConfDO

    //Ӧ������
    String appStr = PropLoadTestUtil.loadPropFile2String("conf/group_test1/app.properties");
    dataMap.put(TAtomConstants.getAppDataId(appName, dbKey1), appStr);

    //��������
    TAtomDsConfDO tAtomDsConfDO = TAtomConfParser.parserTAtomDsConfDO(globaStr, appStr);
    //��������
    String passwdStr = PropLoadTestUtil.loadPropFile2String("conf/group_test1/psswd.properties");
    dataMap.put(TAtomConstants.getPasswdDataId(tAtomDsConfDO.getDbName(), tAtomDsConfDO.getDbType(), tAtomDsConfDO
        .getUserName()), passwdStr);

    globaStr = PropLoadTestUtil.loadPropFile2String("conf/group_test2/globa.properties");
    dataMap.put(TAtomConstants.getGlobalDataId(dbKey2), globaStr);

    appStr = PropLoadTestUtil.loadPropFile2String("conf/group_test2/app.properties");
    dataMap.put(TAtomConstants.getAppDataId(appName, dbKey2), appStr);

    tAtomDsConfDO = TAtomConfParser.parserTAtomDsConfDO(globaStr, appStr);
    passwdStr = PropLoadTestUtil.loadPropFile2String("conf/group_test2/psswd.properties");
    dataMap.put(TAtomConstants.getPasswdDataId(tAtomDsConfDO.getDbName(), tAtomDsConfDO.getDbType(), tAtomDsConfDO
        .getUserName()), passwdStr);

    globaStr = PropLoadTestUtil.loadPropFile2String("conf/group_test3/globa.properties");
    dataMap.put(TAtomConstants.getGlobalDataId(dbKey3), globaStr);

    appStr = PropLoadTestUtil.loadPropFile2String("conf/group_test3/app.properties");
    dataMap.put(TAtomConstants.getAppDataId(appName, dbKey3), appStr);

    tAtomDsConfDO = TAtomConfParser.parserTAtomDsConfDO(globaStr, appStr);
    passwdStr = PropLoadTestUtil.loadPropFile2String("conf/group_test3/psswd.properties");
    //System.out.println("passwdStr = " + passwdStr);
    dataMap.put(TAtomConstants.getPasswdDataId(tAtomDsConfDO.getDbName(), tAtomDsConfDO.getDbType(), tAtomDsConfDO
        .getUserName()), passwdStr);

    MockServer.setConfigInfos(dataMap);

    //System.out.println("dataMap = " + dataMap);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.