List of usage examples for com.mongodb ServerAddress getPort
public int getPort()
From source file:MongoRyaDirectExample.java
License:Apache License
private static Configuration getConf() throws IOException { final MongoDBRdfConfiguration conf = new MongoDBRdfConfiguration(); conf.set(ConfigUtils.USE_MONGO, "true"); if (USE_MOCK) { mock = MockMongoFactory.newFactory(); final MongoClient c = mock.newMongoClient(); final ServerAddress address = c.getAddress(); final String url = address.getHost(); final String port = Integer.toString(address.getPort()); c.close();/* w w w . ja v a2 s. c o m*/ conf.set(MongoDBRdfConfiguration.MONGO_INSTANCE, url); conf.set(MongoDBRdfConfiguration.MONGO_INSTANCE_PORT, port); } else { // User name and password must be filled in: conf.set(MongoDBRdfConfiguration.MONGO_USER, "fill this in"); conf.set(MongoDBRdfConfiguration.MONGO_USER_PASSWORD, "fill this in"); conf.set(MongoDBRdfConfiguration.MONGO_INSTANCE, MONGO_INSTANCE_URL); conf.set(MongoDBRdfConfiguration.MONGO_INSTANCE_PORT, MONGO_INSTANCE_PORT); } conf.set(MongoDBRdfConfiguration.MONGO_DB_NAME, MONGO_DB); conf.set(MongoDBRdfConfiguration.MONGO_COLLECTION_PREFIX, MONGO_COLL_PREFIX); conf.set(ConfigUtils.GEO_PREDICATES_LIST, "http://www.opengis.net/ont/geosparql#asWKT"); // conf.set(ConfigUtils.USE_GEO, "true"); conf.set(ConfigUtils.USE_FREETEXT, "true"); conf.setTablePrefix(MONGO_COLL_PREFIX); conf.set(ConfigUtils.GEO_PREDICATES_LIST, GeoConstants.GEO_AS_WKT.stringValue()); conf.set(ConfigUtils.FREETEXT_PREDICATES_LIST, RDFS.LABEL.stringValue()); conf.set(ConfigUtils.FREETEXT_PREDICATES_LIST, RDFS.LABEL.stringValue()); conf.set(RdfCloudTripleStoreConfiguration.CONF_INFER, Boolean.toString(USE_INFER)); return conf; }
From source file:InferenceExamples.java
License:Apache License
private static Configuration getConf() throws IOException { // MongoDBIndexingConfigBuilder builder = MongoIndexingConfiguration.builder() // .setUseMockMongo(USE_MOCK).setUseInference(USE_INFER).setAuths("U"); MongoDBIndexingConfigBuilder builder = MongoIndexingConfiguration.builder() .setUseMockMongo(USE_EMBEDDED_MONGO).setUseInference(true).setAuths("U"); if (USE_EMBEDDED_MONGO) { final MongoClient c = EmbeddedMongoFactory.newFactory().newMongoClient(); final ServerAddress address = c.getAddress(); final String url = address.getHost(); final String port = Integer.toString(address.getPort()); c.close();//from w ww . jav a 2 s.c o m builder.setMongoHost(url).setMongoPort(port); } else { // User name and password must be filled in: builder = builder.setMongoUser(MongoUserName).setMongoPassword(MongoUserPassword) .setMongoHost(MONGO_INSTANCE_URL).setMongoPort(MONGO_INSTANCE_PORT); } return builder.setMongoDBName(MONGO_DB).setMongoCollectionPrefix(MONGO_COLL_PREFIX) .setUseMongoFreetextIndex(true).setMongoFreeTextPredicates(RDFS.LABEL.stringValue()).build(); }
From source file:brooklyn.entity.nosql.mongodb.MongoDBClientSupport.java
License:Apache License
private HostAndPort getServerHostAndPort() { ServerAddress address = getServerAddress(); return HostAndPort.fromParts(address.getHost(), address.getPort()); }
From source file:com.ca.apm.mongo.Collector.java
License:Open Source License
public MetricFeedBundle makeMetrics(final CommandResult mcr) throws Exception { MetricFeedBundle mfb = new MetricFeedBundle(); ServerAddress sa = mcr.getServerUsed(); // Add a "mongo segment" to the metric path to insure that // mongo metrics are grouped/segregated in the metric browser. // Note that we can't use ":" in that segment though final String basePath = String.format("MongoDB@%s;%d", sa.getHost(), sa.getPort()); makeMetrics(mfb, basePath, mcr);/* www .j a va 2 s.c o m*/ return mfb; }
From source file:com.ebay.cloud.cms.mongo.MongoDataSource.java
License:Apache License
public MongoDataSource(String servers, int connectionsPerHost, ReadPreference readPreference, CMSDBConfig config) {/*ww w . ja va 2 s . co m*/ this.addrs = parseServerString(servers); Collections.sort(addrs, new Comparator<ServerAddress>() { @Override public int compare(ServerAddress s1, ServerAddress s2) { int result = s1.getHost().compareTo(s2.getHost()); if (result != 0) { return result; } else { return s1.getPort() - s2.getPort(); } } }); MongoClientOptions.Builder builder = MongoClientOptions.builder(); builder.socketKeepAlive(false); builder.connectionsPerHost(connectionsPerHost); if (readPreference != null) { builder.readPreference(readPreference); } // set socket timeout if (config != null) { Integer socketTimeOut = (Integer) config.get(CMSDBConfig.MONGO_CONNECTION_SOCKET_TIMEOUT); builder.socketTimeout(socketTimeOut); } MongoClientOptions mongoOptions = builder.build(); this.mongo = new MongoClient(addrs, mongoOptions); }
From source file:com.ebay.cloud.cms.mongo.MongoDataSource.java
License:Apache License
@Override public int hashCode() { int hash = 0; for (ServerAddress a : addrs) { hash += a.getHost().hashCode();/*from w ww . j av a 2 s.co m*/ hash += a.getPort(); } if (hash == 0) { return "".hashCode(); } return hash; }
From source file:com.edgytech.umongo.MongoPanel.java
License:Apache License
private String getServerAddressString(ServerAddress addr) { String ip = "unknown"; try {//from w w w . j av a 2 s . c o m ip = addr.getSocketAddress().getAddress().toString(); } catch (UnknownHostException ex) { Logger.getLogger(MongoPanel.class.getName()).log(Level.WARNING, null, ex); } return addr.getHost() + ":" + addr.getPort() + " (" + ip + ")"; }
From source file:com.edgytech.umongo.RouterPanel.java
License:Apache License
@Override protected void updateComponentCustom(JPanel comp) { try {/*from ww w . ja va 2 s .c om*/ ServerAddress addr = getRouterNode().getAddress(); setStringFieldValue(Item.host, addr.getHost() + ":" + addr.getPort()); setStringFieldValue(Item.address, addr.getSocketAddress().toString()); ((DocField) getBoundUnit(Item.shards)).setDoc(((RouterNode) node).shards); } catch (Exception e) { UMongo.instance.showError(this.getClass().getSimpleName() + " update", e); } }
From source file:com.github.nlloyd.hornofmongo.adaptor.Mongo.java
License:Open Source License
@SuppressWarnings("unchecked") @JSConstructor/*from w ww . j a v a2 s .co 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.gopivotal.cloudfoundry.test.core.MongoDbUtils.java
License:Apache License
public String getUrl(MongoDbFactory mongoDbFactory) { DB mongoDb = mongoDbFactory.getDb(); if (mongoDb != null) { ServerAddress serverAddress = mongoDb.getMongo().getAddress(); String host = serverAddress.getHost(); int port = serverAddress.getPort(); String db = mongoDb.getName(); return String.format("mongodb://%s:%d/%s", host, port, db); }// ww w .j a v a 2 s . c om return "mongodb://fake.connection"; }