/** * 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; }
Mongo mongo = new Mongo(); try { mongo.getConnector().getDBPortPool(mongo.getAddress()).get().ensureOpen(); } catch (Exception e) { ... }
public boolean keepAlive(Mongo mongo) { return mongo.getAddress() != null; }
/** * 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; }
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; } }
/** * 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(); }
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(); } } }
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; } }