use of com.mongodb.ServerAddress in project qi4j-sdk by Qi4j.
the class MongoMapEntityStoreMixin method loadConfiguration.
private void loadConfiguration() throws UnknownHostException {
configuration.refresh();
MongoEntityStoreConfiguration config = configuration.get();
// Combine hostname, port and nodes configuration properties
// If no configuration, use 127.0.0.1:27017
serverAddresses = new ArrayList<>();
int port = config.port().get() == null ? 27017 : config.port().get();
if (config.nodes().get().isEmpty()) {
String hostname = config.hostname().get() == null ? "127.0.0.1" : config.hostname().get();
serverAddresses.add(new ServerAddress(hostname, port));
} else {
if (config.hostname().get() != null && !config.hostname().get().isEmpty()) {
serverAddresses.add(new ServerAddress(config.hostname().get(), port));
}
serverAddresses.addAll(config.nodes().get());
}
// If database name not configured, set it to qi4j:entitystore
databaseName = config.database().get();
if (databaseName == null) {
databaseName = DEFAULT_DATABASE_NAME;
}
// If collection name not configured, set it to qi4j:entitystore:entities
collectionName = config.collection().get();
if (collectionName == null) {
collectionName = DEFAULT_COLLECTION_NAME;
}
// If write concern not configured, set it to normal
switch(config.writeConcern().get()) {
case FSYNC_SAFE:
writeConcern = WriteConcern.FSYNC_SAFE;
break;
case JOURNAL_SAFE:
writeConcern = WriteConcern.JOURNAL_SAFE;
break;
case MAJORITY:
writeConcern = WriteConcern.MAJORITY;
break;
case REPLICAS_SAFE:
writeConcern = WriteConcern.REPLICAS_SAFE;
break;
case SAFE:
writeConcern = WriteConcern.SAFE;
break;
case NORMAL:
default:
writeConcern = WriteConcern.NORMAL;
}
// Username and password are defaulted to empty strings
username = config.username().get();
password = config.password().get().toCharArray();
}
use of com.mongodb.ServerAddress in project DataX by alibaba.
the class MongoUtil method parseServerAddress.
/**
* 转换为mongo地址协议
* @param rawAddressList
* @return
*/
private static List<ServerAddress> parseServerAddress(List<Object> rawAddressList) throws UnknownHostException {
List<ServerAddress> addressList = new ArrayList<ServerAddress>();
for (Object address : rawAddressList) {
String[] tempAddress = ((String) address).split(":");
try {
ServerAddress sa = new ServerAddress(tempAddress[0], Integer.valueOf(tempAddress[1]));
addressList.add(sa);
} catch (Exception e) {
throw new UnknownHostException();
}
}
return addressList;
}
use of com.mongodb.ServerAddress in project mongo-java-driver by mongodb.
the class AbstractServerDiscoveryAndMonitoringTest method applyResponse.
protected void applyResponse(final BsonArray response) {
ServerAddress serverAddress = new ServerAddress(response.get(0).asString().getValue());
BsonDocument isMasterResult = response.get(1).asDocument();
ServerDescription serverDescription;
if (isMasterResult.isEmpty()) {
serverDescription = ServerDescription.builder().type(ServerType.UNKNOWN).state(CONNECTING).address(serverAddress).build();
} else {
serverDescription = createServerDescription(serverAddress, isMasterResult, getVersion(new BsonDocument("versionArray", new BsonArray(asList(new BsonInt32(2), new BsonInt32(6), new BsonInt32(0))))), 5000000);
}
factory.sendNotification(serverAddress, serverDescription);
}
use of com.mongodb.ServerAddress in project mongo-java-driver by mongodb.
the class ClusterDescriptionTest method testObjectOverrides.
@Test
public void testObjectOverrides() throws UnknownHostException {
ClusterDescription description = new ClusterDescription(MULTIPLE, UNKNOWN, asList(builder().state(CONNECTING).address(new ServerAddress("loc:27019")).lastUpdateTimeNanos(42L).build(), builder().state(CONNECTING).address(new ServerAddress("loc:27018")).lastUpdateTimeNanos(42L).build(), builder().state(CONNECTING).address(new ServerAddress("loc:27017")).lastUpdateTimeNanos(42L).build()));
ClusterDescription descriptionTwo = new ClusterDescription(MULTIPLE, UNKNOWN, asList(builder().state(CONNECTING).address(new ServerAddress("loc:27019")).lastUpdateTimeNanos(42L).build(), builder().state(CONNECTING).address(new ServerAddress("loc:27018")).lastUpdateTimeNanos(42L).build(), builder().state(CONNECTING).address(new ServerAddress("loc:27017")).lastUpdateTimeNanos(42L).build()));
assertEquals(description, descriptionTwo);
assertEquals(description.hashCode(), descriptionTwo.hashCode());
assertTrue(description.toString().startsWith("ClusterDescription"));
}
use of com.mongodb.ServerAddress in project mongo-java-driver by mongodb.
the class PlainAuthenticatorUnitTest method before.
@Before
public void before() {
connection = new TestInternalConnection(new ServerId(new ClusterId(), new ServerAddress("localhost", 27017)));
connectionDescription = new ConnectionDescription(new ServerId(new ClusterId(), new ServerAddress()));
credential = MongoCredential.createPlainCredential("user", "$external", "pencil".toCharArray());
subject = new PlainAuthenticator(this.credential);
}
Aggregations