Java Code Examples for com.mysql.cj.conf.HostInfo#getHostProperties()

The following examples show how to use com.mysql.cj.conf.HostInfo#getHostProperties() . 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: ReplicationConnectionUrl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs an instance of {@link ReplicationConnectionUrl}, performing all the required initializations.
 * 
 * @param connStrParser
 *            a {@link ConnectionUrlParser} instance containing the parsed version of the original connection string
 * @param info
 *            the connection arguments map
 */
public ReplicationConnectionUrl(ConnectionUrlParser connStrParser, Properties info) {
    super(connStrParser, info);
    this.type = Type.REPLICATION_CONNECTION;

    // Split masters and slaves:
    LinkedList<HostInfo> undefinedHosts = new LinkedList<>();
    for (HostInfo hi : this.hosts) {
        Map<String, String> hostProperties = hi.getHostProperties();
        if (hostProperties.containsKey(TYPE_PROPERTY_KEY)) {
            if (TYPE_MASTER.equalsIgnoreCase(hostProperties.get(TYPE_PROPERTY_KEY))) {
                this.masterHosts.add(hi);
            } else if (TYPE_SLAVE.equalsIgnoreCase(hostProperties.get(TYPE_PROPERTY_KEY))) {
                this.slaveHosts.add(hi);
            } else {
                undefinedHosts.add(hi);
            }
        } else {
            undefinedHosts.add(hi);
        }
    }
    if (!undefinedHosts.isEmpty()) {
        if (this.masterHosts.isEmpty()) {
            this.masterHosts.add(undefinedHosts.removeFirst());
        }
        this.slaveHosts.addAll(undefinedHosts);
    }

    // TODO: Validate the hosts list: there can't be any two hosts with same host:port.
    // Although this should be required, it also is incompatible with our current tests which are creating replication connections
    // using the same host configurations.
    //        Set<String> visitedHosts = new HashSet<>();
    //        for (List<HostInfo> hostsLists : Arrays.asList(this.masterHosts, this.slaveHosts)) {
    //            for (HostInfo hi : hostsLists) {
    //                if (visitedHosts.contains(hi.getHostPortPair())) {
    //                    throw ExceptionFactory.createException(WrongArgumentException.class,
    //                            Messages.getString("ConnectionString.13", new Object[] { hi.getHostPortPair(), Type.REPLICATION_CONNECTION.getProtocol() }));
    //                }
    //                visitedHosts.add(hi.getHostPortPair());
    //            }
    //        }
}
 
Example 2
Source File: ReplicationConnectionUrl.java    From FoxTelem with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Constructs an instance of {@link ReplicationConnectionUrl}, performing all the required initializations.
 * 
 * @param connStrParser
 *            a {@link ConnectionUrlParser} instance containing the parsed version of the original connection string
 * @param info
 *            the connection arguments map
 */
public ReplicationConnectionUrl(ConnectionUrlParser connStrParser, Properties info) {
    super(connStrParser, info);
    this.type = Type.REPLICATION_CONNECTION;

    // Split masters and slaves:
    LinkedList<HostInfo> undefinedHosts = new LinkedList<>();
    for (HostInfo hi : this.hosts) {
        Map<String, String> hostProperties = hi.getHostProperties();
        if (hostProperties.containsKey(PropertyKey.TYPE.getKeyName())) {
            if (TYPE_MASTER.equalsIgnoreCase(hostProperties.get(PropertyKey.TYPE.getKeyName()))) {
                this.masterHosts.add(hi);
            } else if (TYPE_SLAVE.equalsIgnoreCase(hostProperties.get(PropertyKey.TYPE.getKeyName()))) {
                this.slaveHosts.add(hi);
            } else {
                undefinedHosts.add(hi);
            }
        } else {
            undefinedHosts.add(hi);
        }
    }
    if (!undefinedHosts.isEmpty()) {
        if (this.masterHosts.isEmpty()) {
            this.masterHosts.add(undefinedHosts.removeFirst());
        }
        this.slaveHosts.addAll(undefinedHosts);
    }

    // TODO: Validate the hosts list: there can't be any two hosts with same host:port.
    // Although this should be required, it also is incompatible with our current tests which are creating replication connections
    // using the same host configurations.
    //        Set<String> visitedHosts = new HashSet<>();
    //        for (List<HostInfo> hostsLists : Arrays.asList(this.masterHosts, this.slaveHosts)) {
    //            for (HostInfo hi : hostsLists) {
    //                if (visitedHosts.contains(hi.getHostPortPair())) {
    //                    throw ExceptionFactory.createException(WrongArgumentException.class,
    //                            Messages.getString("ConnectionString.13", new Object[] { hi.getHostPortPair(), Type.REPLICATION_CONNECTION.getProtocol() }));
    //                }
    //                visitedHosts.add(hi.getHostPortPair());
    //            }
    //        }
}