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

The following examples show how to use com.mysql.cj.conf.HostInfo#getHost() . 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: MysqlxSession.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public MysqlxSession(HostInfo hostInfo, PropertySet propSet) {
    super(hostInfo, propSet);

    // create protocol instance
    this.host = hostInfo.getHost();
    if (this.host == null || StringUtils.isEmptyOrWhitespaceOnly(this.host)) {
        this.host = "localhost";
    }
    this.port = hostInfo.getPort();
    if (this.port < 0) {
        this.port = 33060;
    }

    this.protocol = XProtocol.getInstance(this.host, this.port, propSet);

    this.messageBuilder = this.protocol.getMessageBuilder();

    this.protocol.connect(hostInfo.getUser(), hostInfo.getPassword(), hostInfo.getDatabase());
}
 
Example 2
Source File: XProtocol.java    From FoxTelem with GNU General Public License v3.0 6 votes vote down vote up
public XProtocol(HostInfo hostInfo, PropertySet propertySet) {
    String host = hostInfo.getHost();
    if (host == null || StringUtils.isEmptyOrWhitespaceOnly(host)) {
        host = "localhost";
    }
    int port = hostInfo.getPort();
    if (port < 0) {
        port = 33060;
    }
    this.defaultSchemaName = hostInfo.getDatabase();

    // Override common connectTimeout with xdevapi.connect-timeout to provide unified logic in StandardSocketFactory
    RuntimeProperty<Integer> connectTimeout = propertySet.getIntegerProperty(PropertyKey.connectTimeout);
    RuntimeProperty<Integer> xdevapiConnectTimeout = propertySet.getIntegerProperty(PropertyKey.xdevapiConnectTimeout);
    if (xdevapiConnectTimeout.isExplicitlySet() || !connectTimeout.isExplicitlySet()) {
        connectTimeout.setValue(xdevapiConnectTimeout.getValue());
    }

    SocketConnection socketConn = propertySet.getBooleanProperty(PropertyKey.xdevapiUseAsyncProtocol).getValue() ? new XAsyncSocketConnection()
            : new NativeSocketConnection();
    socketConn.connect(host, port, propertySet, null, null, 0);
    init(null, socketConn, propertySet, null);
}
 
Example 3
Source File: BaseTestCase.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
protected Connection getUnreliableMultiHostConnection(String haMode, String[] hostNames, Properties props, Set<String> downedHosts) throws Exception {
    if (downedHosts == null) {
        downedHosts = new HashSet<>();
    }

    props = getHostFreePropertiesFromTestsuiteUrl(props);
    props.setProperty(PropertyKey.socketFactory.getKeyName(), "testsuite.UnreliableSocketFactory");

    HostInfo defaultHost = mainConnectionUrl.getMainHost();
    String db = defaultHost.getDatabase();
    String port = String.valueOf(defaultHost.getPort());
    String host = defaultHost.getHost();

    UnreliableSocketFactory.flushAllStaticData();

    StringBuilder hostString = new StringBuilder();
    String delimiter = "";
    for (String hostName : hostNames) {
        UnreliableSocketFactory.mapHost(hostName, host);
        hostString.append(delimiter);
        delimiter = ",";
        hostString.append(hostName + ":" + port);

        if (downedHosts.contains(hostName)) {
            UnreliableSocketFactory.downHost(hostName);
        }
    }

    if (haMode == null) {
        haMode = "";
    } else if (haMode.length() > 0) {
        haMode += ":";
    }

    return getConnectionWithProps(ConnectionUrl.Type.FAILOVER_CONNECTION.getScheme() + haMode + "//" + hostString.toString() + "/" + db, props);
}
 
Example 4
Source File: BaseTestCase.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
protected ReplicationConnection getUnreliableReplicationConnection(Set<MockConnectionConfiguration> configs, Properties props) throws Exception {
    props = getHostFreePropertiesFromTestsuiteUrl(props);
    props.setProperty(PropertyKey.socketFactory.getKeyName(), "testsuite.UnreliableSocketFactory");

    HostInfo defaultHost = mainConnectionUrl.getMainHost();
    String db = defaultHost.getDatabase();
    String port = String.valueOf(defaultHost.getPort());
    String host = defaultHost.getHost();

    UnreliableSocketFactory.flushAllStaticData();

    StringBuilder hostString = new StringBuilder();
    String glue = "";
    for (MockConnectionConfiguration config : configs) {
        UnreliableSocketFactory.mapHost(config.hostName, host);
        hostString.append(glue);
        glue = ",";
        if (config.port == null) {
            config.port = (port == null ? "3306" : port);
        }
        hostString.append(config.getAddress());
        if (config.isDowned) {
            UnreliableSocketFactory.downHost(config.hostName);
        }
    }

    return (ReplicationConnection) getConnectionWithProps(ConnectionUrl.Type.REPLICATION_CONNECTION.getScheme() + "//" + hostString.toString() + "/" + db,
            props);
}