本文整理汇总了Java中com.mongodb.CommandResult.getBoolean方法的典型用法代码示例。如果您正苦于以下问题:Java CommandResult.getBoolean方法的具体用法?Java CommandResult.getBoolean怎么用?Java CommandResult.getBoolean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mongodb.CommandResult
的用法示例。
在下文中一共展示了CommandResult.getBoolean方法的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;
}
示例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;
}
示例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;
}
示例4: getClusterNodeType
import com.mongodb.CommandResult; //导入方法依赖的package包/类
private String getClusterNodeType() throws Exception {
final String host = getStringProp(DB_HOST_PROP);
final int port = getIntProp(DB_PORT_PROP);
String nodeType = null;
final CommandResult isMaster = dbAdminCmd(host, port, "isMaster");
if (isMaster.getBoolean("ismaster")) {
final String msg = isMaster.getString("msg");
if (msg != null && msg.contains("isdbgrid")) {
nodeType = "shardRouter";
} else {
final CommandResult shardState =
dbAdminCmd(host, port, "shardingState");
if (shardState.ok() && shardState.getBoolean("enabled")) {
if (isConfigServer(host, port)) {
nodeType = "shardConfigServer";
} else {
nodeType = "shardMember";
}
}
}
} else if (isReplicaMember(isMaster)) {
nodeType = "shardMember";
}
return nodeType;
}
示例5: 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;
}
示例6: 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;
}