Java Code Examples for com.mysql.cj.jdbc.ha.LoadBalancedConnectionProxy#addHost()

The following examples show how to use com.mysql.cj.jdbc.ha.LoadBalancedConnectionProxy#addHost() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConnectionGroup.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Add the given host (host:port pair) to this Connection Group and, consequently, to all the load-balanced connections it holds.
 * 
 * @param hostPortPair
 *            The host:port pair to add.
 * @param forExisting
 *            Whether affects existing load-balanced connections or only new ones.
 */
public void addHost(String hostPortPair, boolean forExisting) {
    synchronized (this) {
        if (this.hostList.add(hostPortPair)) {
            this.activeHosts++;
        }
    }
    // all new connections will have this host
    if (!forExisting) {
        return;
    }

    // make a local copy to keep synchronization overhead to minimum
    Map<Long, LoadBalancedConnectionProxy> proxyMap = new HashMap<>();
    synchronized (this.connectionProxies) {
        proxyMap.putAll(this.connectionProxies);
    }

    for (LoadBalancedConnectionProxy proxy : proxyMap.values()) {
        proxy.addHost(hostPortPair);
    }
}
 
Example 2
Source File: ConnectionGroup.java    From FoxTelem with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Add the given host (host:port pair) to this Connection Group and, consequently, to all the load-balanced connections it holds.
 * 
 * @param hostPortPair
 *            The host:port pair to add.
 * @param forExisting
 *            Whether affects existing load-balanced connections or only new ones.
 */
public void addHost(String hostPortPair, boolean forExisting) {
    synchronized (this) {
        if (this.hostList.add(hostPortPair)) {
            this.activeHosts++;
        }
    }
    // all new connections will have this host
    if (!forExisting) {
        return;
    }

    // make a local copy to keep synchronization overhead to minimum
    Map<Long, LoadBalancedConnectionProxy> proxyMap = new HashMap<>();
    synchronized (this.connectionProxies) {
        proxyMap.putAll(this.connectionProxies);
    }

    for (LoadBalancedConnectionProxy proxy : proxyMap.values()) {
        proxy.addHost(hostPortPair);
    }
}