类 LoadBalancedConnectionProxy

  • 所有已实现的接口:
    PingTarget, InvocationHandler

    public class LoadBalancedConnectionProxy
    extends MultiHostConnectionProxy
    implements PingTarget
    A proxy for a dynamic com.mysql.cj.jdbc.JdbcConnection implementation that load balances requests across a series of MySQL JDBC connections, where the balancing takes place at transaction commit. Therefore, for this to work (at all), you must use transactions, even if only reading data. This implementation will invalidate connections that it detects have had communication errors when processing a request. Problematic hosts will be added to a global blacklist for loadBalanceBlacklistTimeout ms, after which they will be removed from the blacklist and made eligible once again to be selected for new connections. This implementation is thread-safe, but it's questionable whether sharing a connection instance amongst threads is a good idea, given that transactions are scoped to connections in JDBC.
    • 构造器详细资料

      • LoadBalancedConnectionProxy

        public LoadBalancedConnectionProxy​(ConnectionUrl connectionUrl)
                                    throws SQLException
        Creates a proxy for java.sql.Connection that routes requests between the hosts in the connection URL.
        参数:
        connectionUrl - The connection URL containing the hosts to load balance.
        抛出:
        SQLException - if an error occurs
    • 方法详细资料

      • propagateProxyDown

        protected void propagateProxyDown​(JdbcConnection proxyConn)
        Propagates the connection proxy down through all live connections.
        覆盖:
        propagateProxyDown 在类中 MultiHostConnectionProxy
        参数:
        proxyConn - The top level connection in the multi-host connections chain.
      • shouldExceptionTriggerFailover

        @Deprecated
        public boolean shouldExceptionTriggerFailover​(Throwable t)
        已过时。
      • pickNewConnection

        public void pickNewConnection()
                               throws SQLException
        Picks the "best" connection to use for the next transaction based on the BalanceStrategy in use.
        抛出:
        SQLException - if an error occurs
      • createConnectionForHost

        public ConnectionImpl createConnectionForHost​(HostInfo hostInfo)
                                               throws SQLException
        Creates a new physical connection for the given HostInfo and updates required internal mappings and statistics for that connection.
        参数:
        hostInfo - The host info instance.
        返回:
        The new Connection instance.
        抛出:
        SQLException - if an error occurs
      • createConnectionForHost

        public ConnectionImpl createConnectionForHost​(String hostPortPair)
                                               throws SQLException
        Creates a new physical connection for the given host:port info. If the this connection's connection URL knows about this host:port then its host info is used, otherwise a new host info based on current connection URL defaults is spawned.
        参数:
        hostPortPair - The host:port pair identifying the host to connect to.
        返回:
        The new Connection instance.
        抛出:
        SQLException - if an error occurs
      • invokeMore

        public Object invokeMore​(Object proxy,
                                 Method method,
                                 Object[] args)
                          throws Throwable
        Proxies method invocation on the java.sql.Connection interface, trapping "close", "isClosed" and "commit/rollback" to switch connections for load balancing. This is the continuation of MultiHostConnectionProxy#invoke(Object, Method, Object[]).
        抛出:
        Throwable
      • addToGlobalBlacklist

        public void addToGlobalBlacklist​(String host,
                                         long timeout)
        Adds a host to the blacklist with the given timeout.
        参数:
        host - The host to be blacklisted.
        timeout - The blacklist timeout for this entry.
      • addToGlobalBlacklist

        public void addToGlobalBlacklist​(String host)
        Adds a host to the blacklist.
        参数:
        host - The host to be blacklisted.
      • isGlobalBlacklistEnabled

        public boolean isGlobalBlacklistEnabled()
        Checks if host blacklist management was enabled.
        返回:
        true if host blacklist management was enabled
      • getGlobalBlacklist

        public Map<String,​Long> getGlobalBlacklist()
        Returns a local hosts blacklist, while cleaning up expired records from the global blacklist, or a blacklist with the hosts to be removed.
        返回:
        A local hosts blacklist.
      • removeHostWhenNotInUse

        public void removeHostWhenNotInUse​(String hostPortPair)
                                    throws SQLException
        Removes a host from the host list, allowing it some time to be released gracefully if needed.
        参数:
        hostPortPair - The host to be removed.
        抛出:
        SQLException - if an error occurs
      • removeHost

        public void removeHost​(String hostPortPair)
                        throws SQLException
        Removes a host from the host list.
        参数:
        hostPortPair - The host to be removed.
        抛出:
        SQLException - if an error occurs
      • addHost

        public boolean addHost​(String hostPortPair)
        Adds a host to the hosts list.
        参数:
        hostPortPair - The host to be added.
        返回:
        true if host was added and false if the host list already contains it
      • inTransaction

        public boolean inTransaction()
      • getTransactionCount

        public long getTransactionCount()
      • getActivePhysicalConnectionCount

        public long getActivePhysicalConnectionCount()
      • getTotalPhysicalConnectionCount

        public long getTotalPhysicalConnectionCount()
      • getConnectionGroupProxyID

        public long getConnectionGroupProxyID()
      • getCurrentActiveHost

        public String getCurrentActiveHost()
      • getCurrentTransactionDuration

        public long getCurrentTransactionDuration()