本文整理汇总了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());
}
示例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;
}
}
}
示例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;
}
}
}
示例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;
}
示例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;
}