Java Code Examples for com.mongodb.WriteConcern#JOURNALED

The following examples show how to use com.mongodb.WriteConcern#JOURNALED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PutMongo.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
protected WriteConcern getWriteConcern(final ProcessContext context) {
    final String writeConcernProperty = context.getProperty(WRITE_CONCERN).getValue();
    WriteConcern writeConcern = null;
    switch (writeConcernProperty) {
    case WRITE_CONCERN_ACKNOWLEDGED:
        writeConcern = WriteConcern.ACKNOWLEDGED;
        break;
    case WRITE_CONCERN_UNACKNOWLEDGED:
        writeConcern = WriteConcern.UNACKNOWLEDGED;
        break;
    case WRITE_CONCERN_FSYNCED:
        writeConcern = WriteConcern.FSYNCED;
        break;
    case WRITE_CONCERN_JOURNALED:
        writeConcern = WriteConcern.JOURNALED;
        break;
    case WRITE_CONCERN_REPLICA_ACKNOWLEDGED:
        writeConcern = WriteConcern.REPLICA_ACKNOWLEDGED;
        break;
    case WRITE_CONCERN_MAJORITY:
        writeConcern = WriteConcern.MAJORITY;
        break;
    default:
        writeConcern = WriteConcern.ACKNOWLEDGED;
    }
    return writeConcern;
}
 
Example 2
Source File: EclipseLinkConfigurationTest.java    From jpa-unit with Apache License 2.0 5 votes vote down vote up
@Test
public void testMongoClientOptions() {
    // GIVEN
    final Map<String, Object> properties = new HashMap<>();
    when(descriptor.getProperties()).thenReturn(properties);

    properties.put("eclipselink.nosql.property.mongo.db", "foo");

    // it looks like only the two options below are supported by EclipseLink

    final ReadPreference readPreference = ReadPreference.nearest();
    final WriteConcern writeConcern = WriteConcern.JOURNALED;

    properties.put("eclipselink.nosql.property.mongo.read-preference", readPreference.getName());
    properties.put("eclipselink.nosql.property.mongo.write-concern", "JOURNALED");

    final ConfigurationFactory factory = new ConfigurationFactoryImpl();

    // WHEN
    final Configuration configuration = factory.createConfiguration(descriptor);

    // THEN
    assertThat(configuration, notNullValue());

    final MongoClientOptions clientOptions = configuration.getClientOptions();
    assertThat(clientOptions, notNullValue());
    assertThat(clientOptions.getReadPreference(), equalTo(readPreference));
    assertThat(clientOptions.getWriteConcern(), equalTo(writeConcern));
}
 
Example 3
Source File: WriteConcernParserTest.java    From vertx-mongo-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimpleAndAdvancedWriteConcern() {
  WriteConcern expected = WriteConcern.JOURNALED;
  JsonObject config = new JsonObject();
  config.put("w", "majority");
  config.put("wtimeoutMS", 1);
  config.put("j", true);
  // this overwrites the other options
  config.put("writeConcern", "journaled");

  WriteConcern wc = new WriteConcernParser(null, config).writeConcern();
  assertNotNull(wc);
  assertEquals(expected, wc);
}
 
Example 4
Source File: PutMongo.java    From nifi with Apache License 2.0 5 votes vote down vote up
protected WriteConcern getWriteConcern(final ProcessContext context) {
    final String writeConcernProperty = context.getProperty(WRITE_CONCERN).getValue();
    WriteConcern writeConcern = null;
    switch (writeConcernProperty) {
    case WRITE_CONCERN_ACKNOWLEDGED:
        writeConcern = WriteConcern.ACKNOWLEDGED;
        break;
    case WRITE_CONCERN_UNACKNOWLEDGED:
        writeConcern = WriteConcern.UNACKNOWLEDGED;
        break;
    case WRITE_CONCERN_FSYNCED:
        writeConcern = WriteConcern.FSYNCED;
        break;
    case WRITE_CONCERN_JOURNALED:
        writeConcern = WriteConcern.JOURNALED;
        break;
    case WRITE_CONCERN_REPLICA_ACKNOWLEDGED:
        writeConcern = WriteConcern.REPLICA_ACKNOWLEDGED;
        break;
    case WRITE_CONCERN_MAJORITY:
        writeConcern = WriteConcern.MAJORITY;
        break;
    default:
        writeConcern = WriteConcern.ACKNOWLEDGED;
    }
    return writeConcern;
}
 
Example 5
Source File: AbstractMongoProcessor.java    From nifi with Apache License 2.0 5 votes vote down vote up
protected WriteConcern getWriteConcern(final ProcessContext context) {
    final String writeConcernProperty = context.getProperty(WRITE_CONCERN).getValue();
    WriteConcern writeConcern = null;
    switch (writeConcernProperty) {
        case WRITE_CONCERN_ACKNOWLEDGED:
            writeConcern = WriteConcern.ACKNOWLEDGED;
            break;
        case WRITE_CONCERN_UNACKNOWLEDGED:
            writeConcern = WriteConcern.UNACKNOWLEDGED;
            break;
        case WRITE_CONCERN_FSYNCED:
            writeConcern = WriteConcern.FSYNCED;
            break;
        case WRITE_CONCERN_JOURNALED:
            writeConcern = WriteConcern.JOURNALED;
            break;
        case WRITE_CONCERN_REPLICA_ACKNOWLEDGED:
            writeConcern = WriteConcern.REPLICA_ACKNOWLEDGED;
            break;
        case WRITE_CONCERN_MAJORITY:
            writeConcern = WriteConcern.MAJORITY;
            break;
        default:
            writeConcern = WriteConcern.ACKNOWLEDGED;
    }
    return writeConcern;
}
 
Example 6
Source File: MongoDBControllerService.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public WriteConcern getWriteConcern(final ConfigurationContext context) {
    final String writeConcernProperty = context.getProperty(WRITE_CONCERN).getValue();
    WriteConcern writeConcern = null;
    switch (writeConcernProperty) {
        case WRITE_CONCERN_ACKNOWLEDGED:
            writeConcern = WriteConcern.ACKNOWLEDGED;
            break;
        case WRITE_CONCERN_UNACKNOWLEDGED:
            writeConcern = WriteConcern.UNACKNOWLEDGED;
            break;
        case WRITE_CONCERN_FSYNCED:
            writeConcern = WriteConcern.FSYNCED;
            break;
        case WRITE_CONCERN_JOURNALED:
            writeConcern = WriteConcern.JOURNALED;
            break;
        case WRITE_CONCERN_REPLICA_ACKNOWLEDGED:
            writeConcern = WriteConcern.REPLICA_ACKNOWLEDGED;
            break;
        case WRITE_CONCERN_MAJORITY:
            writeConcern = WriteConcern.MAJORITY;
            break;
        default:
            writeConcern = WriteConcern.ACKNOWLEDGED;
    }
    return writeConcern;
}
 
Example 7
Source File: HibernateOgmConfigurationTest.java    From jpa-unit with Apache License 2.0 4 votes vote down vote up
@Test
public void testMongoClientOptions() {
    // GIVEN
    final Map<String, Object> properties = new HashMap<>();
    when(descriptor.getProperties()).thenReturn(properties);

    final String description = "Some Description";
    final String applicationName = "Some Application";
    final int minConnectionsPerHost = 1;
    final int connectionsPerHost = 2;
    final int threadsAllowedToBlockForConnectionMultiplier = 2;
    final int serverSelectionTimeout = 500;
    final int maxWaitTime = 1000;
    final int maxConnectionIdleTime = 30000;
    final int maxConnectionLifeTime = 60000;
    final int connectTimeout = 1000;
    final int socketTimeout = 1500;
    final boolean socketKeepAlive = true;
    final boolean sslEnabled = true;
    final boolean sslInvalidHostNameAllowed = false;
    final boolean cursorFinalizerEnabled = false;
    final boolean alwaysUseMBeans = true;
    final int heartbeatFrequency = 1600;
    final int minHeartbeatFrequency = 1700;
    final int heartbeatConnectTimeout = 1800;
    final int heartbeatSocketTimeout = 1900;
    final int localThreshold = 2000;
    final String requiredReplicaSetName = "Replica Name";
    final ReadPreference readPreference = ReadPreference.nearest();
    final WriteConcern writeConcern = WriteConcern.JOURNALED;

    properties.put("hibernate.ogm.datastore.database", "foo");

    properties.put("hibernate.ogm.mongodb.driver.alwaysUseMBeans", "" + alwaysUseMBeans);
    properties.put("hibernate.ogm.mongodb.driver.applicationName", applicationName);
    properties.put("hibernate.ogm.mongodb.driver.connectionsPerHost", "" + connectionsPerHost);
    properties.put("hibernate.ogm.mongodb.driver.connectTimeout", "" + connectTimeout);
    properties.put("hibernate.ogm.mongodb.driver.cursorFinalizerEnabled", "" + cursorFinalizerEnabled);
    properties.put("hibernate.ogm.mongodb.driver.description", description);
    properties.put("hibernate.ogm.mongodb.driver.heartbeatConnectTimeout", "" + heartbeatConnectTimeout);
    properties.put("hibernate.ogm.mongodb.driver.heartbeatFrequency", "" + heartbeatFrequency);
    properties.put("hibernate.ogm.mongodb.driver.heartbeatSocketTimeout", "" + heartbeatSocketTimeout);
    properties.put("hibernate.ogm.mongodb.driver.localThreshold", "" + localThreshold);
    properties.put("hibernate.ogm.mongodb.driver.maxWaitTime", "" + maxWaitTime);
    properties.put("hibernate.ogm.mongodb.driver.maxConnectionIdleTime", "" + maxConnectionIdleTime);
    properties.put("hibernate.ogm.mongodb.driver.maxConnectionLifeTime", "" + maxConnectionLifeTime);
    properties.put("hibernate.ogm.mongodb.driver.minConnectionsPerHost", "" + minConnectionsPerHost);
    properties.put("hibernate.ogm.mongodb.driver.minHeartbeatFrequency", "" + minHeartbeatFrequency);
    properties.put("hibernate.ogm.mongodb.driver.requiredReplicaSetName", requiredReplicaSetName);
    properties.put("hibernate.ogm.mongodb.driver.serverSelectionTimeout", "" + serverSelectionTimeout);
    properties.put("hibernate.ogm.mongodb.driver.socketKeepAlive", "" + socketKeepAlive);
    properties.put("hibernate.ogm.mongodb.driver.socketTimeout", "" + socketTimeout);
    properties.put("hibernate.ogm.mongodb.driver.sslEnabled", "" + sslEnabled);
    properties.put("hibernate.ogm.mongodb.driver.sslInvalidHostNameAllowed", "" + sslInvalidHostNameAllowed);
    properties.put("hibernate.ogm.mongodb.driver.threadsAllowedToBlockForConnectionMultiplier",
            "" + threadsAllowedToBlockForConnectionMultiplier);

    properties.put("hibernate.ogm.mongodb.read_preference", readPreference.getName());
    properties.put("hibernate.ogm.mongodb.write_concern", "JOURNALED");

    final ConfigurationFactory factory = new ConfigurationFactoryImpl();

    // WHEN
    final Configuration configuration = factory.createConfiguration(descriptor);

    // THEN
    assertThat(configuration, notNullValue());

    final MongoClientOptions clientOptions = configuration.getClientOptions();
    assertThat(clientOptions, notNullValue());
    assertThat(clientOptions.getApplicationName(), equalTo(applicationName));
    assertThat(clientOptions.getConnectionsPerHost(), equalTo(connectionsPerHost));
    assertThat(clientOptions.getConnectTimeout(), equalTo(connectTimeout));
    assertThat(clientOptions.getDescription(), equalTo(description));
    assertThat(clientOptions.getHeartbeatConnectTimeout(), equalTo(heartbeatConnectTimeout));
    assertThat(clientOptions.getHeartbeatFrequency(), equalTo(heartbeatFrequency));
    assertThat(clientOptions.getHeartbeatSocketTimeout(), equalTo(heartbeatSocketTimeout));
    assertThat(clientOptions.getLocalThreshold(), equalTo(localThreshold));
    assertThat(clientOptions.getMaxConnectionIdleTime(), equalTo(maxConnectionIdleTime));
    assertThat(clientOptions.getMaxConnectionLifeTime(), equalTo(maxConnectionLifeTime));
    assertThat(clientOptions.getMaxWaitTime(), equalTo(maxWaitTime));
    assertThat(clientOptions.getMinConnectionsPerHost(), equalTo(minConnectionsPerHost));
    assertThat(clientOptions.getMinHeartbeatFrequency(), equalTo(minHeartbeatFrequency));
    assertThat(clientOptions.getRequiredReplicaSetName(), equalTo(requiredReplicaSetName));
    assertThat(clientOptions.getServerSelectionTimeout(), equalTo(serverSelectionTimeout));
    assertThat(clientOptions.getSocketTimeout(), equalTo(socketTimeout));
    assertThat(clientOptions.getThreadsAllowedToBlockForConnectionMultiplier(), equalTo(threadsAllowedToBlockForConnectionMultiplier));
    assertThat(clientOptions.isAlwaysUseMBeans(), equalTo(alwaysUseMBeans));
    assertThat(clientOptions.isCursorFinalizerEnabled(), equalTo(cursorFinalizerEnabled));
    assertThat(clientOptions.isSocketKeepAlive(), equalTo(socketKeepAlive));
    assertThat(clientOptions.isSslEnabled(), equalTo(sslEnabled));
    assertThat(clientOptions.isSslInvalidHostNameAllowed(), equalTo(sslInvalidHostNameAllowed));

    assertThat(clientOptions.getReadPreference(), equalTo(readPreference));
    assertThat(clientOptions.getWriteConcern(), equalTo(writeConcern));
}
 
Example 8
Source File: MongoDBEntityStoreMixin.java    From attic-polygene-java with Apache License 2.0 4 votes vote down vote up
private void loadConfiguration()
    throws UnknownHostException
{
    configuration.refresh();
    MongoDBEntityStoreConfiguration 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();
    List<String> nodes = config.nodes().get();
    if( nodes.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( nodes.stream()
                                     .map( this::parseNode )
                                     .collect( toList() )
                              );
    }

    // If database name not configured, set it to polygene:entitystore
    databaseName = config.database().get();
    if( databaseName == null )
    {
        databaseName = DEFAULT_DATABASE_NAME;
    }

    // If collection name not configured, set it to polygene: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 W1:
        writeConcern = WriteConcern.W1;
        break;
    case W2:
        writeConcern = WriteConcern.W2;
        break;
    case W3:
        writeConcern = WriteConcern.W3;
        break;
    case UNACKNOWLEDGED:
        writeConcern = WriteConcern.UNACKNOWLEDGED;
        break;
    case JOURNALED:
        writeConcern = WriteConcern.JOURNALED;
        break;
    case MAJORITY:
        writeConcern = WriteConcern.MAJORITY;
        break;
    case ACKNOWLEDGED:
    default:
        writeConcern = WriteConcern.ACKNOWLEDGED;
    }

    // Username and password are defaulted to empty strings
    username = config.username().get();
    password = config.password().get().toCharArray();
}