Java Code Examples for com.mysql.cj.jdbc.ha.LoadBalancedConnectionProxy#removeHost()
The following examples show how to use
com.mysql.cj.jdbc.ha.LoadBalancedConnectionProxy#removeHost() .
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 | 5 votes |
/** * Remove the given host (host:port pair) from this Connection Group and, consequently, from all the load-balanced connections it holds. * * @param hostPortPair * The host:port pair to remove. * @param removeExisting * Whether affects existing load-balanced connections or only new ones. * @param waitForGracefulFailover * If true instructs the load-balanced connections to fail-over the underlying active connection before removing this host, otherwise remove * immediately. * @throws SQLException */ public synchronized void removeHost(String hostPortPair, boolean removeExisting, boolean waitForGracefulFailover) throws SQLException { if (this.activeHosts == 1) { throw SQLError.createSQLException(Messages.getString("ConnectionGroup.0"), null); } if (this.hostList.remove(hostPortPair)) { this.activeHosts--; } else { throw SQLError.createSQLException(Messages.getString("ConnectionGroup.1", new Object[] { hostPortPair }), null); } if (removeExisting) { // 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()) { if (waitForGracefulFailover) { proxy.removeHostWhenNotInUse(hostPortPair); } else { proxy.removeHost(hostPortPair); } } } this.closedHosts.add(hostPortPair); }
Example 2
Source File: ConnectionGroup.java From FoxTelem with GNU General Public License v3.0 | 5 votes |
/** * Remove the given host (host:port pair) from this Connection Group and, consequently, from all the load-balanced connections it holds. * * @param hostPortPair * The host:port pair to remove. * @param removeExisting * Whether affects existing load-balanced connections or only new ones. * @param waitForGracefulFailover * If true instructs the load-balanced connections to fail-over the underlying active connection before removing this host, otherwise remove * immediately. * @throws SQLException * if a database access error occurs */ public synchronized void removeHost(String hostPortPair, boolean removeExisting, boolean waitForGracefulFailover) throws SQLException { if (this.activeHosts == 1) { throw SQLError.createSQLException(Messages.getString("ConnectionGroup.0"), null); } if (this.hostList.remove(hostPortPair)) { this.activeHosts--; } else { throw SQLError.createSQLException(Messages.getString("ConnectionGroup.1", new Object[] { hostPortPair }), null); } if (removeExisting) { // 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()) { if (waitForGracefulFailover) { proxy.removeHostWhenNotInUse(hostPortPair); } else { proxy.removeHost(hostPortPair); } } } this.closedHosts.add(hostPortPair); }