Example usage for com.mongodb Mongo getAddress

List of usage examples for com.mongodb Mongo getAddress

Introduction

In this page you can find the example usage for com.mongodb Mongo getAddress.

Prototype

@Deprecated
@SuppressWarnings("deprecation")
@Nullable
public ServerAddress getAddress() 

Source Link

Document

Gets the address of the current master

Usage

From source file:com.opencanarias.mset.internal.benchmark.repository.cdo.mongodb.JVMMongodbCDOModelRepository.java

License:Open Source License

@Override
public boolean isAvailable() {
    try {/*from   w  w  w. j a  v a  2  s.  c o m*/
        Mongo mongo = new Mongo(MONGO_URI);
        mongo.getConnector().getDBPortPool(mongo.getAddress()).get().ensureOpen();
    } catch (Exception e) {
        fireRepositoryEvent(EventLevel.ERROR, "MongoDB is not available", e);
        logger.error("MongoDB is not available", e);
        return false;
    }
    return true;
}

From source file:com.tomtom.services.notifications.dao.DaoModule.java

License:Apache License

@Nonnull
@Provides//  ww w .j  a  v  a2  s.  c  o m
@Singleton
public static MongoDB provideMongoDB(@Nonnull final DatabaseProperties properties) {
    assert properties != null;

    try {
        LOG.info("provideMongoDB: Creating MongoDB connection: {}", properties.getServers());
        final Mongo mongo = MongoConnectionCache.getMongoDB(properties.getServers(), MONGODB_TIMEOUT_SECS,
                properties.getUserName(), properties.getDatabase(), properties.getPassword());

        // The address may not be available yet, if we connect like this.
        final ServerAddress address = mongo.getAddress();
        LOG.info("provideMongoDB: MongoDB connection established: {}",
                properties.getDatabase() + " at " + properties.getServers() + " [master:"
                        + ((address == null) ? "(unknown)"
                                : (address.getHost() + ':' + mongo.getAddress().getPort()))
                        + "] (MongoDB version " + ')');
        final MongoDB db = getDB(mongo, properties.getDatabase(), "", properties.getUserName(),
                properties.getPassword());
        return db;
    } catch (final UnknownHostException e) {
        throw new MongoDBConnectionException("Cannot find any of MongoDB servers: " + properties.getServers(),
                e);
    }
}

From source file:org.greenmongoquery.db.service.impl.MongoServiceImpl.java

License:Open Source License

@Override
public void updatetDb(String db, String updateDb, Mongo mongo) {
    DB dbs = mongo.getDB("admin");
    DBObject cmd = new BasicDBObject();
    DBObject key = new BasicDBObject();
    logger.info("host " + mongo.getAddress().getHost() + " from db " + db + " updte db " + updateDb);

    cmd.put("copydb", 1);

    cmd.put("fromhost", mongo.getAddress().getHost());
    cmd.put("todb", updateDb);
    cmd.put("fromdb", db);

    CommandResult result = dbs.command(cmd);

    DB dbsDop = mongo.getDB(db);/*  w ww.  ja v a 2  s  . com*/
    dbsDop.dropDatabase();
    logger.info(result.getErrorMessage() + result.getException());
}