com.mongodb.Mongo.getAddress()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(3.4k)|赞(0)|评价(0)|浏览(239)

本文整理了Java中com.mongodb.Mongo.getAddress()方法的一些代码示例,展示了Mongo.getAddress()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mongo.getAddress()方法的具体详情如下:
包路径:com.mongodb.Mongo
类名称:Mongo
方法名:getAddress

Mongo.getAddress介绍

[英]Gets the address of the current master
[中]获取当前主机的地址

代码示例

代码示例来源:origin: org.mongodb/mongo-java-driver

/**
 * Gets a {@code String} representation of current connection point, i.e. master.
 *
 * @return server address in a host:port form
 */
@Deprecated
@Nullable
public String getConnectPoint() {
  ServerAddress master = getAddress();
  return master != null ? String.format("%s:%d", master.getHost(), master.getPort()) : null;
}

代码示例来源:origin: stackoverflow.com

Mongo mongo = new Mongo();
try {
 mongo.getConnector().getDBPortPool(mongo.getAddress()).get().ensureOpen();
} catch (Exception e) {
 ...
}

代码示例来源:origin: stackoverflow.com

public boolean keepAlive(Mongo mongo) {
  return mongo.getAddress() != null;
}

代码示例来源:origin: org.mongodb/mongodb-driver

/**
 * Gets a {@code String} representation of current connection point, i.e. master.
 *
 * @return server address in a host:port form
 */
@Deprecated
@Nullable
public String getConnectPoint() {
  ServerAddress master = getAddress();
  return master != null ? String.format("%s:%d", master.getHost(), master.getPort()) : null;
}

代码示例来源:origin: stackoverflow.com

public boolean mongoRunningAt(String uri) {
  try {
    Mongo mongo = new Mongo(new MongoURI(uri));
    try {
      Socket socket = mongo.getMongoOptions().socketFactory.createSocket();
      socket.connect(mongo.getAddress().getSocketAddress());
      socket.close();
    } catch (IOException ex) {
      return false;
    }
    mongo.close();
    return true;
  } catch (UnknownHostException e) {
    return false;
  }
}

代码示例来源:origin: org.springframework.xd/spring-xd-test-fixtures

/**
 * Construct a new HdfsMongoDbJob using the provided directory and file names.
 *
 * @param dir the directory where the source file is located on hdfs
 * @param fileName The file from which data will be pulled.
 * @param collectionName the collection where the data will be written.
 * @param names a comma delimited list of column names that are contained in the source file.
 * @param mongoDbFactory The db factory for mongo
 */
public HdfsMongoDbJob(String dir, String fileName, String collectionName, String names, String idField,
    MongoDbFactory mongoDbFactory) {
  Assert.hasText(dir, "Dir must not be null or empty");
  Assert.hasText(fileName, "FileName must not be null or empty");
  Assert.hasText(collectionName, "CollectionName must not be null or empty");
  Assert.hasText(names, "Names must not be null nor empty");
  Assert.hasText(idField, "IdField must not be null nor empty");
  this.dir = dir;
  this.fileName = fileName;
  this.collectionName = collectionName;
  this.names = names;
  this.idField = idField;
  mongoTemplate = new MongoTemplate(mongoDbFactory);
  host = mongoTemplate.getDb().getMongo().getAddress().getHost();
  port = mongoTemplate.getDb().getMongo().getAddress().getPort();
}

代码示例来源:origin: cloudfoundry-samples/hello-spring-cloud

private String toString(MongoDbFactory mongoDbFactory) {
  if (mongoDbFactory == null) {
    return "<none>";
  } else {
    try {
      return mongoDbFactory.getDb().getMongo().getAddress().toString();
    } catch (Exception ex) {
      return "<invalid address> " + mongoDbFactory.getDb().getMongo().toString();
    }
  }
}

代码示例来源:origin: com.springsource.insight.plugins/insight-plugin-mongodb

public static Operation putDatabaseDetails (Operation op, DB db) {
    op.put("dbName", db.getName());
    
    Mongo            mongo=db.getMongo();
    ServerAddress    address=mongo.getAddress();
    op.put("host", address.getHost());
    op.put("port", address.getPort());
    return op;
  }
}

相关文章