Package com.alibaba.druid.pool.ha

Examples of com.alibaba.druid.pool.ha.MultiDataSource


        this.maxActive = maxActive;
    }

    @Override
    public Connection getConnection(MultiDataSourceConnection connectionProxy, String sql) throws SQLException {
        MultiDataSource multiDataSource = connectionProxy.getHaDataSource();

        Object[] array = multiDataSource.getDataSources().toArray();

        DruidDataSource minDataSource = null;
        int min = 0;
        for (Object item : array) {
            DruidDataSource dataSource = (DruidDataSource) item;
View Full Code Here


    }

    @Override
    public Connection getConnection(MultiDataSourceConnection connectionProxy, String sql) throws SQLException {
        MultiDataSource multiDataSource = connectionProxy.getHaDataSource();

        int tryCount = 0;

        for (;;) {
            int size = multiDataSource.getDataSources().size();
            long connectionId = (int) connectionProxy.getId();

            if (size == 0) {
                throw new SQLException("can not get connection, no availabe datasources");
            }

            int index = (int) (connectionId % size);

            DruidDataSource dataSource = null;

            try {
                // 处理并发时的错误
                dataSource = multiDataSource.getDataSources().get(index);
            } catch (Exception ex) {
                indexErrorCount.incrementAndGet();
                if (LOG.isDebugEnabled()) {
                    LOG.debug("getDataSource error, index : " + index, ex);
                }
                continue;
            }

            assert dataSource != null;

            if (!dataSource.isEnable()) {
                multiDataSource.handleNotAwailableDatasource(dataSource);
                continue;
            }

            Connection conn = null;
View Full Code Here

    }

    @Override
    public MultiConnectionHolder getConnection(MultiDataSourceConnection conn, String sql) throws SQLException {
        MultiDataSource multiDataSource = conn.getMultiDataSource();

        int size = multiDataSource.getDataSources().size();
        long connectionId = (int) conn.getId();

        if (size == 0) {
            throw new SQLException("can not get connection, no availabe datasources");
        }

        int index = (int) (connectionId % size);

        DataSourceHolder first = null;
        DataSourceHolder dataSource = null;

        try {
            int itemIndex = 0;
            for (DataSourceHolder item : multiDataSource.getDataSources().values()) {
                if (!item.isEnable()) {
                    continue;
                }

                if (first == null) {
View Full Code Here

        getMultiDataSource().notFailSignal();
    }

    @Override
    public MultiConnectionHolder getConnection(MultiDataSourceConnection conn, String sql) throws SQLException {
        MultiDataSource multiDataSource = conn.getMultiDataSource();

        DataSourceHolder dataSource = null;

        int randomNumber = produceRandomNumber();
        DataSourceHolder first = null;

        for (DataSourceHolder item : multiDataSource.getDataSources().values()) {
            if (!item.isEnable()) {
                continue;
            }

            if (first == null) {
                first = item;
            }

            if (randomNumber >= item.getWeightRegionBegin() && randomNumber < item.getWeightRegionEnd()) {
                if (!item.isEnable()) {
                    continue;
                }

                if (item.getDataSource().isBusy()) {
                    multiDataSource.incrementBusySkipCount();
                    break;
                }

                dataSource = item;
            }
        }

        if (dataSource == null) {
            dataSource = first;
        }

        if (dataSource == null) {
            throw new SQLException("cannot get connection. enabledDataSourceCount "
                                   + multiDataSource.getEnabledDataSourceCount());
        }

        return dataSource.getConnection();
    }
View Full Code Here

    }

    @Override
    public MultiConnectionHolder getConnection(MultiDataSourceConnection conn, String sql) throws SQLException {
        MultiDataSource multiDataSource = conn.getMultiDataSource();

        DataSourceHolder dataSource = null;
        int leastCount = -1;

        for (DataSourceHolder item : multiDataSource.getDataSources().values()) {
            if (!item.isEnable()) {
                continue;
            }

            int activeCount = item.getDataSource().getActiveCount();
            if (dataSource == null) {
                leastCount = activeCount;
                dataSource = item;
            } else {
                if (leastCount > item.getDataSource().getActiveCount()) {
                    dataSource = item;
                    leastCount = activeCount;
                }
            }
        }

        if (dataSource == null) {
            throw new SQLException("can not get real connection, enableDataSourceCount "
                                   + multiDataSource.getEnabledDataSourceCount());
        }

        return dataSource.getConnection();
    }
View Full Code Here

    }

    @Override
    public MultiConnectionHolder getConnection(MultiDataSourceConnection conn, String sql) throws SQLException {
        MultiDataSource multiDataSource = conn.getMultiDataSource();

        int size = multiDataSource.getDataSources().size();
        long connectionId = (int) conn.getId();

        if (size == 0) {
            throw new SQLException("can not get connection, no availabe datasources");
        }

        int index = (int) (connectionId % size);

        DataSourceHolder first = null;
        DataSourceHolder dataSource = null;

        try {
            int itemIndex = 0;
            for (DataSourceHolder item : multiDataSource.getDataSources().values()) {
                if (!item.isEnable()) {
                    continue;
                }

                if (first == null) {
View Full Code Here

        getMultiDataSource().notFailSignal();
    }

    @Override
    public MultiConnectionHolder getConnection(MultiDataSourceConnection conn, String sql) throws SQLException {
        MultiDataSource multiDataSource = conn.getMultiDataSource();

        DataSourceHolder dataSource = null;

        int randomNumber = produceRandomNumber();
        DataSourceHolder first = null;

        for (DataSourceHolder item : multiDataSource.getDataSources().values()) {
            if (!item.isEnable()) {
                continue;
            }

            if (first == null) {
                first = item;
            }

            if (randomNumber >= item.getWeightRegionBegin() && randomNumber < item.getWeightRegionEnd()) {
                if (!item.isEnable()) {
                    continue;
                }

                if (item.getDataSource().isBusy()) {
                    multiDataSource.incrementBusySkipCount();
                    break;
                }

                dataSource = item;
            }
        }

        if (dataSource == null) {
            dataSource = first;
        }

        if (dataSource == null) {
            throw new SQLException("cannot get connection. enabledDataSourceCount "
                                   + multiDataSource.getEnabledDataSourceCount());
        }

        return dataSource.getConnection();
    }
View Full Code Here

    }

    @Override
    public MultiConnectionHolder getConnection(MultiDataSourceConnection conn, String sql) throws SQLException {
        MultiDataSource multiDataSource = conn.getMultiDataSource();

        DataSourceHolder dataSource = null;
        int leastCount = -1;

        for (DataSourceHolder item : multiDataSource.getDataSources().values()) {
            if (!item.isEnable()) {
                continue;
            }

            int activeCount = item.getDataSource().getActiveCount();
            if (dataSource == null) {
                leastCount = activeCount;
                dataSource = item;
            } else {
                if (leastCount > item.getDataSource().getActiveCount()) {
                    dataSource = item;
                    leastCount = activeCount;
                }
            }
        }

        if (dataSource == null) {
            throw new SQLException("can not get real connection, enableDataSourceCount "
                                   + multiDataSource.getEnabledDataSourceCount());
        }

        return dataSource.getConnection();
    }
View Full Code Here

    }

    @Override
    public MultiConnectionHolder getConnection(MultiDataSourceConnection conn, String sql) throws SQLException {
        MultiDataSource multiDataSource = conn.getMultiDataSource();

        int size = multiDataSource.getDataSources().size();
        long connectionId = (int) conn.getId();

        if (size == 0) {
            throw new SQLException("can not get connection, no availabe datasources");
        }

        int index = (int) (connectionId % size);

        DataSourceHolder first = null;
        DataSourceHolder dataSource = null;

        try {
            int itemIndex = 0;
            for (DataSourceHolder item : multiDataSource.getDataSources().values()) {
                if (!item.isEnable()) {
                    continue;
                }

                if (first == null) {
View Full Code Here

TOP

Related Classes of com.alibaba.druid.pool.ha.MultiDataSource

Copyright © 2018 www.massapicom. 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.