Examples of SmoothValve


Examples of com.taobao.tddl.common.util.SmoothValve

  /**
   * ����ֻ����tryLock���ӳ��ԣ��������߼�ί�ɸ�getConnection0
   */
  public Connection getConnection(String username, String password) throws SQLException {
    SmoothValve valve = smoothValve;
    try {
      //modify by junyu,��ʱȥ��������ܡ�
//      if (!runTimeConf.isSingleInGroup() && timeOutPunisher.punish()) { //group��ֻʣһ��ʱ������ʱ�ͷ�������Ҳ�øɻ�
//        throw new AtomSlowPunishException(this.runTimeConf.getDbName() + "'s timeout " + timeOutPunisher); //��ʱ�ͷ�
//      }
      if (valve.isNotAvailable()) {
        boolean toTry = System.currentTimeMillis() - lastRetryTime > retryBadDbInterval;
        if (toTry && lock.tryLock()) {
          try {
            Connection t = this.getConnection0(username, password); //ͬһ��ʱ��ֻ����һ���̼߳���ʹ���������Դ��
            //isNotAvailable = false; //��һ���߳����ԣ�ִ�гɹ�����Ϊ���ã��Զ��ָ�
            valve.setAvailable(); //��һ���߳����ԣ�ִ�гɹ�����Ϊ���ã��Զ��ָ�
            return t;
          } finally {
            lastRetryTime = System.currentTimeMillis();
            lock.unlock();
          }
        } else {
          throw new AtomNotAvailableException(this.runTimeConf.getDbName() + " isNotAvailable"); //�����߳�fail-fast
        }
      } else {
        if (valve.smoothThroughOnInitial()) {
          return this.getConnection0(username, password);
        } else {
          throw new AtomNotAvailableException(this.runTimeConf.getDbName()
              + " squeezeThrough rejected on fatal reset"); //δͨ����λʱ����������
        }
      }
    } catch (SQLException e) {
      String dbType=this.runTimeConf.getDbType();
      if(dbType!=null){
        dbType=dbType.toUpperCase();
      }
     
      ExceptionSorter exceptionSorter = exceptionSorters
          .get(dbType);
      if (exceptionSorter.isExceptionFatal(e)) {
        NagiosUtils.addNagiosLog(NagiosUtils.KEY_DB_NOT_AVAILABLE + "|" + this.runTimeConf.getDbName(), e
            .getMessage());
        //isNotAvailable = true;
        valve.setNotAvailable();
      }
      throw e;
    }
  }
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.