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


Java CommandResult.containsField方法代码示例

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


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

示例1: discoverReplicas

import com.mongodb.CommandResult; //导入方法依赖的package包/类
protected List<String> discoverReplicas(final String host, final int port)
    throws Exception {

    List<String> replicas = new ArrayList<String>();

    final CommandResult cr = dbAdminCmd(host, port, "isMaster");

    replicas.addAll((List<String>) cr.get("hosts"));
    // hidden replicas are replicas that cannot become primaries and
    // are hidden to the client app
    if (cr.getBoolean("hidden")) {
        // TODO: We can't assume we're the master here....
        replicas.add(cr.getString("me"));
    }
    // passives are replicas that cannot become primaries because
    // their priority is set to 0
    if (cr.containsField("passives")) {
        replicas.addAll((List<String>) cr.get("passives"));
    }
    // arbiters exist only to vote in master elections.  They don't
    // actually hold replica data.
    if (cr.containsField("arbiters")) {
        replicas.addAll((List<String>) cr.get("arbiters"));
    }
    return replicas;
}
 
开发者ID:CA-APM,项目名称:ca-apm-fieldpack-mongodb,代码行数:27,代码来源:Topology.java

示例2: discoverTopology

import com.mongodb.CommandResult; //导入方法依赖的package包/类
public Topology discoverTopology() throws Exception {

        final String host = getStringProp(DB_HOST_PROP);
        final int port = getIntProp(DB_PORT_PROP);

        logger.log(Level.INFO, "Discovering Topology for host: {0}:{1}",
            new Object[] {host, port});

        final CommandResult master = dbAdminCmd(host, port, "isMaster");

        // ismaster returns true for a standalone mongod instance, a mongos
        // instance, a mongod shard node, or a primary in a replica set
        if (master.getBoolean("ismaster") || master.containsField("primary")) {

            boolean isReplicaSet = false;
            if (master.containsField("primary")) {
                isReplicaSet = true;
            }

            if (isInShardCluster(master)) {
                topology = new ShardCluster(props, host, port, logger);
                topology.discoverServers(getClusterNodeType());
            } else if (isReplicaSet(master)) {
                topology = new ReplicaSet(props, host, port, logger);
                topology.discoverServers("doesn't matter");
            } else {
                topology = new StandaloneMongod(props, host, port, logger);
                topology.discoverServers("doesn't matter");
            }
        }
        logger.log(Level.INFO, "Topology: {0}", topology);
        return topology;
    }
 
开发者ID:CA-APM,项目名称:ca-apm-fieldpack-mongodb,代码行数:34,代码来源:Collector.java

示例3: isInShardCluster

import com.mongodb.CommandResult; //导入方法依赖的package包/类
private boolean isInShardCluster(
    final CommandResult cr
) throws Exception {

    MongoServer ms = new MongoServer(getMyself(cr));
    final String host = ms.getHost();
    final int port = ms.getPort();

    boolean sharded = false;

    final String msg = cr.getString("msg");
    if ((msg != null) && msg.contains("isdbgrid")) {
        sharded = true;
    } else if (cr.getBoolean("ismaster")) {
        final CommandResult shardState =
            dbAdminCmd(host, port, "shardingState");
        // shardingState command only returns OK when server is in a sharded
        // cluster
        if (shardState.ok()) {
            if (shardState.getBoolean("enabled")) {
                sharded = true;
            }
        }
    }  else if (cr.containsField("primary")) {
        // we are in a replica set but not the primary,
        // check the primary to see if it is a shard member
        final String primary = cr.getString("primary");
        ms = new MongoServer(primary);
        final CommandResult priIsMaster =
            dbAdminCmd(ms.getHost(), ms.getPort(), "isMaster");
        sharded = isInShardCluster(priIsMaster);
    }
    return sharded;
}
 
开发者ID:CA-APM,项目名称:ca-apm-fieldpack-mongodb,代码行数:35,代码来源:Collector.java

示例4: isReplicaMember

import com.mongodb.CommandResult; //导入方法依赖的package包/类
/**
 * This method is to check to see if a node is in a replica set despite
 * not being the primary member.
 */
private boolean isReplicaMember(final CommandResult cr) {
    boolean isReplMember = false;
    if (cr.containsField("primary")) {
        if (cr.getBoolean("secondary") ||
            cr.getBoolean("passive") ||
            cr.getBoolean("arbiterOnly")) {
            isReplMember = true;
        }
    }
    return isReplMember;
}
 
开发者ID:CA-APM,项目名称:ca-apm-fieldpack-mongodb,代码行数:16,代码来源:Collector.java

示例5: getConfigServersFromShard

import com.mongodb.CommandResult; //导入方法依赖的package包/类
private List<String> getConfigServersFromShard(
    final String host,
    final int port
) throws Exception {

    final List<String> cfgServers = new ArrayList<String>();

    String cHost = host;
    int cPort = port;

    final CommandResult isMaster = dbAdminCmd(cHost, cPort, "isMaster");

    // we can't run the DB command "shardingState" from a node
    // which isn't a master.  This should only apply to non-primary
    // replica members, so find the primary and run the command on it.
    if (! isMaster.getBoolean("ismaster")) {
        if (isMaster.containsField("primary")) {
            final String primary = isMaster.getString("primary");
            final MongoServer ms = new MongoServer(primary);
            cHost = ms.getHost();
            cPort = ms.getPort();
        }
    }

    CommandResult shardState =
        dbAdminCmd(cHost, cPort, "shardingState");

    if (shardState.ok()) {
        final String cfgSrvs =
            shardState.getString("configServer");
        addCommaSeparatedHosts(cfgServers, cfgSrvs);
    }
    return cfgServers;
}
 
开发者ID:CA-APM,项目名称:ca-apm-fieldpack-mongodb,代码行数:35,代码来源:ShardCluster.java

示例6: isReplicaSet

import com.mongodb.CommandResult; //导入方法依赖的package包/类
private boolean isReplicaSet(final CommandResult cr) {
    return cr.containsField("primary");
}
 
开发者ID:CA-APM,项目名称:ca-apm-fieldpack-mongodb,代码行数:4,代码来源:Collector.java


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