Example usage for com.mongodb ServerAddress defaultPort

List of usage examples for com.mongodb ServerAddress defaultPort

Introduction

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

Prototype

public static int defaultPort() 

Source Link

Document

Returns the default database port: 27017

Usage

From source file:com.aguin.stock.recommender.StockRecommender.java

License:Apache License

public static void main(String... args) throws FileNotFoundException, TasteException, IOException {

    MongoDBDataModel model = new MongoDBDataModel("localhost", ServerAddress.defaultPort(), "userdb", "prefs",
            true, true, null);/* www .ja  va 2 s .c o m*/
    // create a slope one recommender on the data
    CachingRecommender slopeOneRecommender = new CachingRecommender(new SlopeOneRecommender(model));
    run(model, slopeOneRecommender);
}

From source file:com.github.nlloyd.hornofmongo.adaptor.Mongo.java

License:Open Source License

@SuppressWarnings("unchecked")
@JSConstructor/*from  w  w w .  ja v a 2  s  .c  o  m*/
public Mongo(final Object host) throws UnknownHostException {
    super();
    if (host instanceof Undefined)
        this.hosts = Collections.singletonList(new ServerAddress("localhost", ServerAddress.defaultPort()));
    else if (host instanceof com.mongodb.Mongo) {
        this.innerMongo = (com.mongodb.Mongo) host;
        this.hosts = this.innerMongo.getAllAddress();
        this.mongoOptions = this.innerMongo.getMongoOptions();
        // now get the query options, not same as MongoOptions
        this.options = this.innerMongo.getOptions();
    } else if (host instanceof List<?>)
        // TODO check if we get a list of ServerAddresses or something else
        this.hosts = (List<ServerAddress>) host;
    else {
        String hostsString = Context.toString(host);
        if (hostsString.startsWith(MONGO_CLIENT_URI_PREFIX))
            hostsString = hostsString.substring(MONGO_CLIENT_URI_PREFIX.length());
        String[] hostStrings = hostsString.split(",");
        this.hosts = new ArrayList<ServerAddress>(hostStrings.length);
        for (String hostString : hostStrings) {
            if (hostString.indexOf(':') > -1) {
                String[] hostBits = hostString.split(":");
                this.hosts.add(new ServerAddress(hostBits[0], Integer.valueOf(hostBits[1])));
            } else
                this.hosts.add(new ServerAddress(hostString, ServerAddress.defaultPort()));
        }
    }

    StringBuilder hostStringBuilder = new StringBuilder();
    if (!(host instanceof Undefined)) {
        for (ServerAddress serverAddress : this.hosts) {
            if (hostStringBuilder.length() > 0)
                hostStringBuilder.append(",");
            hostStringBuilder.append(serverAddress.getHost()).append(":").append(serverAddress.getPort());
        }
    } else
        hostStringBuilder.append("127.0.0.1");
    put("host", this, hostStringBuilder.toString());
}

From source file:com.norconex.collector.core.data.store.impl.mongo.MongoCrawlDataStore.java

License:Apache License

protected static DB buildMongoDB(String crawlerId, MongoConnectionDetails connDetails) {

    String dbName = MongoUtil.getDbNameOrGenerate(connDetails.getDatabaseName(), crawlerId);

    int port = connDetails.getPort();
    if (port <= 0) {
        port = ServerAddress.defaultPort();
    }//from  w  ww  .  j  a va 2s. c  o m

    try {
        ServerAddress server = new ServerAddress(connDetails.getHost(), port);
        List<MongoCredential> credentialsList = new ArrayList<MongoCredential>();
        if (StringUtils.isNoneBlank(connDetails.getUsername())) {
            MongoCredential credential = MongoCredential.createMongoCRCredential(connDetails.getUsername(),
                    dbName, connDetails.getPassword().toCharArray());
            credentialsList.add(credential);
        }
        MongoClient client = new MongoClient(server, credentialsList);
        return client.getDB(dbName);
    } catch (UnknownHostException e) {
        throw new CrawlDataStoreException(e);
    }
}

From source file:org.eclipse.birt.data.oda.mongodb.internal.impl.MDbMetaData.java

License:Open Source License

/**
 * Returns the default database port.
 */
public static int defaultPort() {
    return ServerAddress.defaultPort();
}

From source file:org.graylog.plugins.metrics.mongodb.providers.MongoDBReporterProvider.java

License:Open Source License

private ServerAddress[] extractServerAddresses(MongoClientURI mongoClientURI) {
    final List<String> hosts = mongoClientURI.getHosts();
    final List<ServerAddress> serverAddresses = new ArrayList<>(hosts.size());
    for (String host : hosts) {
        final HostAndPort hostAndPort = HostAndPort.fromString(host)
                .withDefaultPort(ServerAddress.defaultPort());
        final ServerAddress serverAddress = new ServerAddress(hostAndPort.getHostText(), hostAndPort.getPort());
        serverAddresses.add(serverAddress);
    }/* ww w.j  a v  a2s . c  om*/
    return serverAddresses.toArray(new ServerAddress[serverAddresses.size()]);
}

From source file:org.sourcepit.akka.poc.mongodb.MongoClientActor.java

License:Apache License

private static ServerAddress toServerAddresse(BSONObject server) throws UnknownHostException {
    final Object oHost = server.get("host");
    final String host = oHost == null ? ServerAddress.defaultHost() : (String) oHost;
    final Object oPort = server.get("port");
    final int port = oPort == null ? ServerAddress.defaultPort() : ((Integer) oPort).intValue();
    return new ServerAddress(host, port);
}

From source file:uk.ac.ebi.eva.dbmigration.mongodb.MongobeeHelper.java

License:Apache License

private static List<ServerAddress> getServers(DatabaseParameters databaseParameters) {
    List<ServerAddress> addresses = new ArrayList<>();

    int port = ServerAddress.defaultPort();
    if (hasText(databaseParameters.getDbPort())) {
        port = Integer.parseInt(databaseParameters.getDbPort());
    }/*from   w ww  . j a v  a 2  s. c  o m*/

    String hosts = databaseParameters.getDbHosts();
    if (!hasText(hosts)) {
        hosts = ServerAddress.defaultHost();
    }

    for (String host : hosts.split(",")) {
        addresses.add(new ServerAddress(host, port));
    }

    return addresses;
}

From source file:xbdd.webapp.factory.ServletContextMongoClientFactory.java

License:Apache License

public ServletContextMongoClientFactory(@Context final ServletContext context) {
    this.host = Objects.toString(context.getInitParameter(XBDD_MONGO_HOSTNAME_INIT_PARAMETER),
            ServerAddress.defaultHost());
    this.username = context.getInitParameter(XBDD_MONGO_USERNAME_INIT_PARAMETER);
    this.password = context.getInitParameter(XBDD_MONGO_PASSWORD_INIT_PARAMETER) != null
            ? context.getInitParameter(XBDD_MONGO_PASSWORD_INIT_PARAMETER).toCharArray()
            : null;//  w w  w. j a  v  a2s.com
    this.port = NumberUtils.isNumber(context.getInitParameter(XBDD_MONGO_PORT_INIT_PARAMETER))
            ? Integer.parseInt(context.getInitParameter(XBDD_MONGO_PORT_INIT_PARAMETER))
            : ServerAddress.defaultPort();
}