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


Java ServerMode类代码示例

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


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

示例1: testDumpServersAll

import com.mysql.fabric.ServerMode; //导入依赖的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());
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:35,代码来源:TestDumpCommands.java

示例2: getReadWriteConnectionFromServerGroup

import com.mysql.fabric.ServerMode; //导入依赖的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

示例3: unmarshallServer

import com.mysql.fabric.ServerMode; //导入依赖的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);
    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:33,代码来源:XmlRpcClient.java

示例4: unmarshallServer

import com.mysql.fabric.ServerMode; //导入依赖的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);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:33,代码来源:XmlRpcClient.java

示例5: getActiveConnection

import com.mysql.fabric.ServerMode; //导入依赖的package包/类
protected Connection getActiveConnection() throws SQLException {
    if (this.currentConnection != null) {
        return this.currentConnection;
    }

    if (getCurrentServerGroup() == null) {
        throw SQLError.createSQLException("No server group selected.", SQLError.SQL_STATE_CONNECTION_REJECTED, null, getExceptionInterceptor(), this);
    }

    // try to find an existing replication connection to the current group
    this.currentConnection = this.serverConnections.get(this.serverGroup);
    if (this.currentConnection != null) {
        return this.currentConnection;
    }

    // otherwise, build a replication connection to the current group
    List<String> masterHost = new ArrayList<String>();
    List<String> slaveHosts = new ArrayList<String>();
    for (Server s : this.serverGroup.getServers()) {
        if (ServerMode.READ_WRITE.equals(s.getMode())) {
            masterHost.add(s.getHostname() + ":" + s.getPort());
        } else {
            slaveHosts.add(s.getHostname() + ":" + s.getPort());
        }
    }
    Properties info = exposeAsProperties(null);
    info.put("replicationConnectionGroup", this.serverGroup.getName());
    info.setProperty(NonRegisteringDriver.USER_PROPERTY_KEY, this.username);
    info.setProperty(NonRegisteringDriver.PASSWORD_PROPERTY_KEY, this.password);
    info.setProperty(NonRegisteringDriver.DBNAME_PROPERTY_KEY, getCatalog());
    info.setProperty("connectionAttributes", "fabricHaGroup:" + this.serverGroup.getName());
    this.currentConnection = new ReplicationConnection(info, info, masterHost, slaveHosts);
    this.serverConnections.put(this.serverGroup, this.currentConnection);

    this.currentConnection.setProxy(this);
    this.currentConnection.setAutoCommit(this.autoCommit);
    this.currentConnection.setReadOnly(this.readOnly);
    this.currentConnection.setTransactionIsolation(this.transactionIsolation);
    return this.currentConnection;
}
 
开发者ID:mniepert,项目名称:TPKB,代码行数:41,代码来源:FabricMySQLConnectionProxy.java

示例6: testDumpServersAll

import com.mysql.fabric.ServerMode; //导入依赖的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());
}
 
开发者ID:Prometheus-ETSIIT,项目名称:locaviewer,代码行数:39,代码来源:TestDumpCommands.java


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