本文整理汇总了Java中com.mysql.fabric.ServerRole类的典型用法代码示例。如果您正苦于以下问题:Java ServerRole类的具体用法?Java ServerRole怎么用?Java ServerRole使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ServerRole类属于com.mysql.fabric包,在下文中一共展示了ServerRole类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDumpServersAll
import com.mysql.fabric.ServerRole; //导入依赖的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());
}
示例2: unmarshallServer
import com.mysql.fabric.ServerRole; //导入依赖的package包/类
/**
* Unmarshall a response representing a server.
*/
private static Server unmarshallServer(Map<String, ?> serverData) throws FabricCommunicationException {
ServerMode mode;
ServerRole role;
String host;
int port;
try {
// dump.servers returns integer mode/status
if (Integer.class.equals(serverData.get(FIELD_MODE).getClass())) {
mode = ServerMode.getFromConstant((Integer) serverData.get(FIELD_MODE));
role = ServerRole.getFromConstant((Integer) serverData.get(FIELD_STATUS));
host = (String) serverData.get(FIELD_HOST);
port = (Integer) serverData.get(FIELD_PORT);
} else {
// sharding.lookup_servers returns a different format
mode = ServerMode.valueOf((String) serverData.get(FIELD_MODE));
role = ServerRole.valueOf((String) serverData.get(FIELD_STATUS));
String hostnameAndPort[] = ((String) serverData.get(FIELD_ADDRESS)).split(":");
host = hostnameAndPort[0];
port = Integer.valueOf(hostnameAndPort[1]);
}
Server s = new Server((String) serverData.get(FIELD_GROUP_ID), (String) serverData.get(FIELD_SERVER_UUID), host, port, mode, role,
(Double) serverData.get(FIELD_WEIGHT));
return s;
} catch (Exception ex) {
throw new FabricCommunicationException("Unable to parse server definition", ex);
}
}
示例3: unmarshallServer
import com.mysql.fabric.ServerRole; //导入依赖的package包/类
/**
* Unmarshall a response representing a server.
*/
private static Server unmarshallServer(Map serverData) throws FabricCommunicationException {
ServerMode mode;
ServerRole role;
String host;
int port;
try {
// dump.servers returns integer mode/status
if (Integer.class.equals(serverData.get(FIELD_MODE).getClass())) {
mode = ServerMode.getFromConstant((Integer) serverData.get(FIELD_MODE));
role = ServerRole.getFromConstant((Integer) serverData.get(FIELD_STATUS));
host = (String) serverData.get(FIELD_HOST);
port = (Integer) serverData.get(FIELD_PORT);
} else {
// sharding.lookup_servers returns a different format
mode = ServerMode.valueOf((String) serverData.get(FIELD_MODE));
role = ServerRole.valueOf((String) serverData.get(FIELD_STATUS));
String hostnameAndPort[] = ((String) serverData.get(FIELD_ADDRESS)).split(":");
host = hostnameAndPort[0];
port = Integer.valueOf(hostnameAndPort[1]);
}
Server s = new Server((String) serverData.get(FIELD_GROUP_ID), (String) serverData.get(FIELD_SERVER_UUID), host, port, mode, role,
(Double) serverData.get(FIELD_WEIGHT));
return s;
} catch (Exception ex) {
throw new FabricCommunicationException("Unable to parse server definition", ex);
}
}
示例4: testDumpServersAll
import com.mysql.fabric.ServerRole; //导入依赖的package包/类
/**
* Test the Client.getServers() without a match pattern (all servers).
*/
public void testDumpServersAll() throws Exception {
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());
String ghost = System.getProperty("com.mysql.fabric.testsuite.global.host");
String gport = System.getProperty("com.mysql.fabric.testsuite.global.port");
String s1host = System.getProperty("com.mysql.fabric.testsuite.shard1.host");
String s1port = System.getProperty("com.mysql.fabric.testsuite.shard1.port");
String s2host = System.getProperty("com.mysql.fabric.testsuite.shard2.host");
String s2port = System.getProperty("com.mysql.fabric.testsuite.shard2.port");
assertEquals((ghost != null ? ghost : "127.0.0.1"), servers.get(0).getHostname());
assertEquals((s1host != null ? s1host : "127.0.0.1"), servers.get(1).getHostname());
assertEquals((s2host != null ? s2host : "127.0.0.1"), servers.get(2).getHostname());
assertEquals((gport != null ? Integer.valueOf(gport) : 3401), servers.get(0).getPort());
assertEquals((s1port != null ? Integer.valueOf(s1port) : 3402), servers.get(1).getPort());
assertEquals((s2port != null ? Integer.valueOf(s2port) : 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());
}