Example usage for com.mongodb ServerAddress getPort

List of usage examples for com.mongodb ServerAddress getPort

Introduction

In this page you can find the example usage for com.mongodb ServerAddress getPort.

Prototype

public int getPort() 

Source Link

Document

Gets the port number

Usage

From source file:org.grails.datastore.mapping.mongo.MongoDatastore.java

License:Apache License

public void afterPropertiesSet() throws Exception {
    if (mongo == null) {
        ServerAddress defaults = new ServerAddress();
        MongoFactoryBean dbFactory = new MongoFactoryBean();
        dbFactory.setHost(read(String.class, MONGO_HOST, connectionDetails, defaults.getHost()));
        dbFactory.setPort(read(Integer.class, MONGO_PORT, connectionDetails, defaults.getPort()));
        if (mongoOptions != null) {
            dbFactory.setMongoOptions(mongoOptions);
        }/*from   w w w . j  a v a2  s .c  o m*/

        dbFactory.afterPropertiesSet();
        mongo = dbFactory.getObject();
    }

    for (PersistentEntity entity : mappingContext.getPersistentEntities()) {
        // Only create Mongo templates for entities that are mapped with Mongo
        if (!entity.isExternal()) {
            createMongoTemplate(entity, mongo);
        }
    }
}

From source file:org.graylog2.system.stats.mongo.MongoProbe.java

License:Open Source License

public MongoStats mongoStats() {
    final List<ServerAddress> serverAddresses = mongoClient.getServerAddressList();
    final List<HostAndPort> servers = Lists.newArrayListWithCapacity(serverAddresses.size());
    for (ServerAddress serverAddress : serverAddresses) {
        servers.add(HostAndPort.fromParts(serverAddress.getHost(), serverAddress.getPort()));
    }//w ww. java  2s .  c o  m

    final DatabaseStats dbStats;
    final CommandResult dbStatsResult = db.command("dbStats");
    if (dbStatsResult.ok()) {
        final BasicDBObject extentFreeListMap = (BasicDBObject) dbStatsResult.get("extentFreeList");
        final DatabaseStats.ExtentFreeList extentFreeList = DatabaseStats.ExtentFreeList
                .create(extentFreeListMap.getInt("num"), extentFreeListMap.getInt("totalSize"));

        final BasicDBObject dataFileVersionMap = (BasicDBObject) dbStatsResult.get("dataFileVersion");
        final DatabaseStats.DataFileVersion dataFileVersion = DatabaseStats.DataFileVersion
                .create(dataFileVersionMap.getInt("major"), dataFileVersionMap.getInt("minor"));

        dbStats = DatabaseStats.create(dbStatsResult.getString("db"), dbStatsResult.getLong("collections"),
                dbStatsResult.getLong("objects"), dbStatsResult.getDouble("avgObjSize"),
                dbStatsResult.getLong("dataSize"), dbStatsResult.getLong("storageSize"),
                dbStatsResult.getLong("numExtents"), dbStatsResult.getLong("indexes"),
                dbStatsResult.getLong("indexSize"), dbStatsResult.getLong("fileSize"),
                dbStatsResult.getLong("nsSizeMB"), extentFreeList, dataFileVersion);
    } else {
        dbStats = null;
    }

    final ServerStatus serverStatus;
    final CommandResult serverStatusResult = adminDb.command("serverStatus");
    if (serverStatusResult.ok()) {
        final BasicDBObject connectionsMap = (BasicDBObject) serverStatusResult.get("connections");
        final ServerStatus.Connections connections = ServerStatus.Connections.create(
                connectionsMap.getInt("current"), connectionsMap.getInt("available"),
                connectionsMap.getLong("totalCreated"));

        final BasicDBObject networkMap = (BasicDBObject) serverStatusResult.get("network");
        final ServerStatus.Network network = ServerStatus.Network.create(networkMap.getInt("bytesIn"),
                networkMap.getInt("bytesOut"), networkMap.getInt("numRequests"));

        final BasicDBObject memoryMap = (BasicDBObject) serverStatusResult.get("mem");
        final ServerStatus.Memory memory = ServerStatus.Memory.create(memoryMap.getInt("bits"),
                memoryMap.getInt("resident"), memoryMap.getInt("virtual"), memoryMap.getBoolean("supported"),
                memoryMap.getInt("mapped"), memoryMap.getInt("mappedWithJournal"));

        serverStatus = ServerStatus.create(serverStatusResult.getString("host"),
                serverStatusResult.getString("version"), serverStatusResult.getString("process"),
                serverStatusResult.getLong("pid"), serverStatusResult.getInt("uptime"),
                serverStatusResult.getLong("uptimeMillis"), serverStatusResult.getInt("uptimeEstimate"),
                new DateTime(serverStatusResult.getDate("localTime")), connections, network, memory);
    } else {
        serverStatus = null;
    }

    // TODO Collection stats? http://docs.mongodb.org/manual/reference/command/collStats/

    return MongoStats.create(servers, buildInfo, hostInfo, serverStatus, dbStats);
}

From source file:org.springframework.data.mongodb.core.MongoClientFactoryBean.java

License:Apache License

private ServerAddress createConfiguredOrDefaultServerAddress() throws UnknownHostException {

    ServerAddress defaultAddress = new ServerAddress();

    return new ServerAddress(StringUtils.hasText(host) ? host : defaultAddress.getHost(),
            port != null ? port.intValue() : defaultAddress.getPort());
}

From source file:org.springframework.datastore.mapping.mongo.MongoDatastore.java

License:Apache License

public void afterPropertiesSet() throws Exception {
    if (this.mongo == null) {
        ServerAddress defaults = new ServerAddress();
        MongoFactoryBean dbFactory = new MongoFactoryBean();
        dbFactory.setHost(read(String.class, MONGO_HOST, connectionDetails, defaults.getHost()));
        dbFactory.setPort(read(Integer.class, MONGO_PORT, connectionDetails, defaults.getPort()));
        if (mongoOptions != null) {
            dbFactory.setMongoOptions(mongoOptions);
        }/*ww  w  . j a v a  2s . c  o m*/
        dbFactory.afterPropertiesSet();

        this.mongo = dbFactory.getObject();
    }

    for (PersistentEntity entity : mappingContext.getPersistentEntities()) {
        createMongoTemplate(entity, mongo);
    }
}