public Ha3Connection()

in src/main/java/com/aliyun/ha3engine/jdbc/Ha3Connection.java [62:107]


    public Ha3Connection(Ha3Config ha3Config) throws Exception {
        long t0 = System.currentTimeMillis();
        try {
            printVitalProps(ha3Config);
            this.ha3Config = ha3Config;

            StringBuilder key = new StringBuilder();
            key.append(ha3Config.toString());
            this.clientKey = key.toString();

            CloudClient client;
            try {
                singletonLock.lock();
                CloudClientHolder cloudClientHolder = cloudClientHolders.get(getClientKey());
                if (cloudClientHolder != null) {
                    client = cloudClientHolder.getClient();
                } else {
                    long maxSizeConf = ha3Config.getMaxPoolSize();
                    maxSizeConf = maxSizeConf == 0 ? DEFAULT_POOL_SIZE : maxSizeConf;
                    if (cloudClientHolders.size() > maxSizeConf) {
                        throw new Ha3DriverException(ErrorCode.CONNECTION_SIZE_EXCEEDED_LIMIT,
                                String
                                        .format("The connection pool exceeded the limit: %d , if necessary,please increase "
                                                + "Ha3Config:maxPoolSize.", maxSizeConf));
                    }
                    client = new CloudClient(ha3Config);
                    cloudClientHolder = new CloudClientHolder(client);
                    cloudClientHolders.put(getClientKey(), cloudClientHolder);
                }
                cloudClientHolder.refInc();

            } finally {
                singletonLock.unlock();
            }

            this.cloudClient = client;
            this.active = true;
        } finally {
            long t1 = System.currentTimeMillis();
            long cost = t1 - t0;
            if (ha3Config.isEnableDetailLog()) {
                logger.warn("a new Ha3Connection has been create.cost:{}", cost);
            }
        }

    }