当前位置: 首页>>代码示例>>Java>>正文


Java ServerGroup.getServers方法代码示例

本文整理汇总了Java中com.mysql.fabric.ServerGroup.getServers方法的典型用法代码示例。如果您正苦于以下问题:Java ServerGroup.getServers方法的具体用法?Java ServerGroup.getServers怎么用?Java ServerGroup.getServers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.mysql.fabric.ServerGroup的用法示例。


在下文中一共展示了ServerGroup.getServers方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getReadWriteConnectionFromServerGroup

import com.mysql.fabric.ServerGroup; //导入方法依赖的package包/类
/**
 * Find a server with mode READ_WRITE in the given server group and create a JDBC connection to it.
 * 
 * @returns a {@link Connection} to an arbitrary MySQL server
 * @throws SQLException
 *             if connection fails or a READ_WRITE server is not contained in the group
 */
private Connection getReadWriteConnectionFromServerGroup(ServerGroup serverGroup) throws SQLException {
    for (Server s : serverGroup.getServers()) {
        if (ServerMode.READ_WRITE.equals(s.getMode())) {
            String jdbcUrl = String.format("jdbc:mysql://%s:%s/%s", s.getHostname(), s.getPort(), this.database);
            return DriverManager.getConnection(jdbcUrl, this.user, this.password);
        }
    }
    throw new SQLException("Unable to find r/w server for chosen shard mapping in group " + serverGroup.getName());
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:17,代码来源:FabricMultiTenantConnectionProvider.java

示例2: promoteServerInGroup

import com.mysql.fabric.ServerGroup; //导入方法依赖的package包/类
public void promoteServerInGroup(String groupName, String hostname, int port) throws FabricCommunicationException {
    ServerGroup serverGroup = getServerGroup(groupName);
    for (Server s : serverGroup.getServers()) {
        if (s.getHostname().equals(hostname) && s.getPort() == port) {
            errorSafeCallMethod(METHOD_GROUP_PROMOTE, new Object[] { groupName, s.getUuid() });
            break;
        }
    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:10,代码来源:XmlRpcClient.java

示例3: promoteServerInGroup

import com.mysql.fabric.ServerGroup; //导入方法依赖的package包/类
public void promoteServerInGroup(String groupName, String hostname, int port) throws FabricCommunicationException {
	ServerGroup serverGroup = getServerGroup(groupName);
	for (Server s : serverGroup.getServers()) {
		if (s.getHostname().equals(hostname) &&
			s.getPort() == port) {
			errorSafeCallMethod("group.promote", new Object[] {groupName, s.getUuid()});
			break;
		}
	}
}
 
开发者ID:hinsenchan,项目名称:fil_project_mgmt_app_v2,代码行数:11,代码来源:XmlRpcClient.java

示例4: interceptException

import com.mysql.fabric.ServerGroup; //导入方法依赖的package包/类
/**
 * @param sqlEx
 * @param conn
 * @param group
 * @param hostname
 * @param portnumber
 * @throws FabricCommunicationException
 */
SQLException interceptException(SQLException sqlEx, Connection conn, String group, String hostname, String portnumber) throws FabricCommunicationException {
    if (!sqlEx.getSQLState().startsWith("08")) {
        return null;
    }

    if (this.intercepting) {
        return null;
    }

    this.intercepting = true;

    try {
        // find the Server corresponding to this connection
        // TODO could be indexed for quicker lookup
        Server currentServer = null;
        ServerGroup currentGroup = this.fabricConnection.getServerGroup(group);
        for (Server s : currentGroup.getServers()) {
            if (s.getHostname().equals(hostname) && Integer.valueOf(s.getPort()).toString().equals(portnumber)) {
                currentServer = s;
                break;
            }
        }

        if (currentServer == null) {
            return SQLError.createSQLException("Unable to lookup server to report error to Fabric", sqlEx.getSQLState(), sqlEx, getExceptionInterceptor(),
                    this);
        }

        if (this.reportErrors) {
            this.fabricConnection.getClient().reportServerError(currentServer, sqlEx.toString(), true);
        }

        this.serverConnections.remove(this.serverGroup);
        try {
            this.currentConnection.close();
        } catch (SQLException ex) {
        }
        this.currentConnection = null;
        this.serverGroup = currentGroup;
    } finally {
        this.intercepting = false;
    }

    return null;
}
 
开发者ID:mniepert,项目名称:TPKB,代码行数:54,代码来源:FabricMySQLConnectionProxy.java

示例5: interceptException

import com.mysql.fabric.ServerGroup; //导入方法依赖的package包/类
/**
 * 
 * @param sqlEx
 * @param conn
 * @param group
 * @param hostname
 * @param portnumber
 * @return
 * @throws FabricCommunicationException
 */
SQLException interceptException(SQLException sqlEx, Connection conn,
								String group, String hostname, String portnumber)
	throws FabricCommunicationException {
	if (!sqlEx.getSQLState().startsWith("08")) {
		return null;
	}

	if (intercepting) {
		return null;
	}

	intercepting = true;

	try {
		// find the Server corresponding to this connection
		// TODO could be indexed for quicker lookup
		Server currentServer = null;
		ServerGroup currentGroup = this.fabricConnection.getServerGroup(group);
		for (Server s : currentGroup.getServers()) {
			if (s.getHostname().equals(hostname) &&
				Integer.valueOf(s.getPort()).toString().equals(portnumber)) {
				currentServer = s;
				break;
			}
		}
	
		if (currentServer == null) {
			return SQLError.createSQLException("Unable to lookup server to report error to Fabric",
											   sqlEx.getSQLState(), sqlEx, getExceptionInterceptor(), this);
		}

		if (this.reportErrors) {
			this.fabricConnection.getClient().reportServerError(currentServer,
																sqlEx.toString(), true);
		}

		this.serverConnections.remove(this.serverGroup);
		try {
			this.currentConnection.close();
		} catch (SQLException ex) {
		}
		this.currentConnection = null;
		this.serverGroup = currentGroup;
	} finally {
		intercepting = false;
	}

	return null;
}
 
开发者ID:hinsenchan,项目名称:fil_project_mgmt_app_v2,代码行数:60,代码来源:FabricMySQLConnectionProxy.java


注:本文中的com.mysql.fabric.ServerGroup.getServers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。