本文整理汇总了Java中com.mysql.fabric.ServerGroup类的典型用法代码示例。如果您正苦于以下问题:Java ServerGroup类的具体用法?Java ServerGroup怎么用?Java ServerGroup使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ServerGroup类属于com.mysql.fabric包,在下文中一共展示了ServerGroup类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getServerGroups
import com.mysql.fabric.ServerGroup; //导入依赖的package包/类
/**
* Facade for "dump.servers". Will not return empty server groups.
*/
public FabricStateResponse<Set<ServerGroup>> getServerGroups(String groupPattern) throws FabricCommunicationException {
int version = 0; // necessary but unused
Response response = errorSafeCallMethod(METHOD_DUMP_SERVERS, new Object[] { version, groupPattern });
// collect all servers by group name
Map<String, Set<Server>> serversByGroupName = new HashMap<String, Set<Server>>();
for (Map<String, ?> server : response.getResultSet()) {
Server s = unmarshallServer(server);
if (serversByGroupName.get(s.getGroupName()) == null) {
serversByGroupName.put(s.getGroupName(), new HashSet<Server>());
}
serversByGroupName.get(s.getGroupName()).add(s);
}
// create group set
Set<ServerGroup> serverGroups = new HashSet<ServerGroup>();
for (Map.Entry<String, Set<Server>> entry : serversByGroupName.entrySet()) {
ServerGroup g = new ServerGroup(entry.getKey(), entry.getValue());
serverGroups.add(g);
}
return new FabricStateResponse<Set<ServerGroup>>(serverGroups, response.getTtl());
}
示例2: getServerGroups
import com.mysql.fabric.ServerGroup; //导入依赖的package包/类
/**
* Facade for "dump.servers". Will not return empty server groups.
*/
public FabricStateResponse<Set<ServerGroup>> getServerGroups(String groupPattern) throws FabricCommunicationException {
int version = 0; // necessary but unused
Response response = errorSafeCallMethod(METHOD_DUMP_SERVERS, new Object[] { version, groupPattern });
// collect all servers by group name
Map<String, Set<Server>> serversByGroupName = new HashMap<String, Set<Server>>();
for (Map server : response.getResultSet()) {
Server s = unmarshallServer(server);
if (serversByGroupName.get(s.getGroupName()) == null) {
serversByGroupName.put(s.getGroupName(), new HashSet<Server>());
}
serversByGroupName.get(s.getGroupName()).add(s);
}
// create group set
Set<ServerGroup> serverGroups = new HashSet<ServerGroup>();
for (Map.Entry<String, Set<Server>> entry : serversByGroupName.entrySet()) {
ServerGroup g = new ServerGroup(entry.getKey(), entry.getValue());
serverGroups.add(g);
}
return new FabricStateResponse<Set<ServerGroup>>(serverGroups, response.getTtl());
}
示例3: getServerGroups
import com.mysql.fabric.ServerGroup; //导入依赖的package包/类
/**
* Facade for "dump.servers".
*/
public FabricStateResponse<Set<ServerGroup>> getServerGroups(String groupPattern) throws FabricCommunicationException {
int version = 0; // necessary but unused
DumpResponse response = callDumpMethod("dump.servers", new Object[] {version, groupPattern});
// collect all servers by group name
Map<String, Set<Server>> serversByGroupName = new HashMap<String, Set<Server>>();
for (List server : (List<List>) response.getReturnValue()) {
Server s = unmarshallServer(server);
if (serversByGroupName.get(s.getGroupName()) == null) {
serversByGroupName.put(s.getGroupName(), new HashSet<Server>());
}
serversByGroupName.get(s.getGroupName()).add(s);
}
// create group set
Set<ServerGroup> serverGroups = new HashSet<ServerGroup>();
for (Map.Entry<String, Set<Server>> entry : serversByGroupName.entrySet()) {
ServerGroup g = new ServerGroup(entry.getKey(), entry.getValue());
serverGroups.add(g);
}
return new FabricStateResponse<Set<ServerGroup>>(serverGroups, response.getTtl());
}
示例4: testDumpServersAll
import com.mysql.fabric.ServerGroup; //导入依赖的package包/类
/**
* Test the Client.getServers() without a match pattern (all servers).
*/
public void testDumpServersAll() throws Exception {
if (!this.isSetForFabricTest) {
return;
}
Set<ServerGroup> serverGroups = this.client.getServerGroups().getData();
List<Server> servers = new ArrayList<Server>();
for (ServerGroup g : serverGroups) {
servers.addAll(g.getServers());
}
Collections.sort(servers, serverHostnamePortSorter);
assertEquals(3, servers.size());
assertEquals("fabric_test1_global", servers.get(0).getGroupName());
assertEquals("fabric_test1_shard1", servers.get(1).getGroupName());
assertEquals("fabric_test1_shard2", servers.get(2).getGroupName());
assertEquals((this.globalHost != null ? this.globalHost : "127.0.0.1"), servers.get(0).getHostname());
assertEquals((this.shard1Host != null ? this.shard1Host : "127.0.0.1"), servers.get(1).getHostname());
assertEquals((this.shard2Host != null ? this.shard2Host : "127.0.0.1"), servers.get(2).getHostname());
assertEquals((this.globalPort != null ? Integer.valueOf(this.globalPort) : 3401), servers.get(0).getPort());
assertEquals((this.shard1Port != null ? Integer.valueOf(this.shard1Port) : 3402), servers.get(1).getPort());
assertEquals((this.shard2Port != null ? Integer.valueOf(this.shard2Port) : 3403), servers.get(2).getPort());
assertEquals(ServerMode.READ_WRITE, servers.get(0).getMode());
assertEquals(ServerRole.PRIMARY, servers.get(0).getRole());
assertEquals(ServerMode.READ_WRITE, servers.get(1).getMode());
assertEquals(ServerRole.PRIMARY, servers.get(1).getRole());
assertEquals(ServerMode.READ_WRITE, servers.get(2).getMode());
assertEquals(ServerRole.PRIMARY, servers.get(2).getRole());
}
示例5: 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());
}
示例6: getServerGroup
import com.mysql.fabric.ServerGroup; //导入依赖的package包/类
public ServerGroup getServerGroup(String groupName) throws FabricCommunicationException {
Set<ServerGroup> groups = getServerGroups(groupName).getData();
if (groups.size() == 1) {
return groups.iterator().next();
}
return null;
}
示例7: 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;
}
}
}
示例8: getConnection
import com.mysql.fabric.ServerGroup; //导入依赖的package包/类
/**
* Get a connection to access data association with the provided `tenantIdentifier' (or shard
* key in Fabric-speak). The returned connection is a READ_WRITE connection.
*/
public Connection getConnection(String tenantIdentifier) throws SQLException {
String serverGroupName = this.shardMapping.getGroupNameForKey(tenantIdentifier);
try {
ServerGroup serverGroup = this.fabricConnection.getServerGroup(serverGroupName);
return getReadWriteConnectionFromServerGroup(serverGroup);
} catch (FabricCommunicationException ex) {
throw new RuntimeException(ex);
}
}