Example usage for com.mongodb WriteConcern SAFE

List of usage examples for com.mongodb WriteConcern SAFE

Introduction

In this page you can find the example usage for com.mongodb WriteConcern SAFE.

Prototype

WriteConcern SAFE

To view the source code for com.mongodb WriteConcern SAFE.

Click Source Link

Document

Write operations that use this write concern will wait for acknowledgement from the primary server before returning.

Usage

From source file:com.ebay.cloud.cms.entmgr.service.ServiceFactory.java

License:Apache License

public static IBranchService getBranchService(MongoDataSource ds,
        List<PersistenceService.Registration> implementations) {
    return getBranchService(ds, WriteConcern.SAFE, implementations);
}

From source file:com.ebay.cloud.cms.entmgr.service.ServiceFactory.java

License:Apache License

public static IEntityService getEntityService(MongoDataSource ds, IRepositoryService repositoryService,
        List<PersistenceService.Registration> implementations) {
    return getEntityService(ds, repositoryService, WriteConcern.SAFE, implementations);
}

From source file:com.ebay.cloud.cms.lock.mongo.MongoMutex.java

License:Apache License

public MongoMutex(Mongo mongo, String dbName, String collName, String lockName, String clientName,
        int expireTime, int renewPeriod) {
    super();//from   w w w .j a v a  2  s  .  c om

    CheckConditions.checkArgument(!StringUtils.isNullOrEmpty(dbName), "dbName should not be null or empty");
    CheckConditions.checkArgument(!StringUtils.isNullOrEmpty(collName), "collName should not be null or empty");
    CheckConditions.checkArgument(mongo != null, "mongo should not be null");
    CheckConditions.checkArgument(!StringUtils.isNullOrEmpty(lockName), "lockName should not be null or empty");
    CheckConditions.checkArgument(!StringUtils.isNullOrEmpty(clientName),
            "clientName should not be null or empty");
    CheckConditions.checkArgument(expireTime >= 1000, "expireTime must be larger than 1 second");

    CheckConditions.checkArgument(renewPeriod >= 400,
            "renewPeroid must larger than 0.4 second so renew will not cost cpu alot");
    CheckConditions.checkArgument(expireTime - renewPeriod >= 1000,
            "expireTime - renewPeriod must be larger than 1 second so client have enough time to renew");

    this.lockName = lockName;
    this.clientName = clientName;
    this.expireTime = expireTime;
    this.renewPeriod = renewPeriod;

    coll = mongo.getDB(dbName).getCollection(collName);
    coll.setWriteConcern(WriteConcern.SAFE);
    createIfNotExist(coll, lockName);
}

From source file:com.ebay.cloud.cms.metadata.mongo.MongoMetadataServiceImpl.java

License:Apache License

public MongoMetadataServiceImpl(Mongo mongo, int maxCacheSize, int cacheExpiredTime,
        int collectionCountCacheSize, int collectionCountCacheExpiredTime, Repository repo,
        ICMSLock metadataLock) {// w w w . ja v a 2  s  .c o m

    CheckConditions.checkNotNull(mongo, "mongo can not be null");
    CheckConditions.checkNotNull(repo, "repository can not be null");
    CheckConditions.checkArgument(maxCacheSize > 0, "maximumSize can not be negtive value");
    CheckConditions.checkArgument(cacheExpiredTime > 0, "expireAfterSeconds can not be negtive value");
    CheckConditions.checkArgument(collectionCountCacheSize > 0,
            "collectionCountCacheSize can not be negtive value");
    CheckConditions.checkArgument(collectionCountCacheExpiredTime > 0,
            "collectionCountCacheExpiredTime can not be negtive value");
    CheckConditions.checkArgument(metadataLock != null, "metadataLock should not be null");

    this.metadataLock = metadataLock;
    this.maxCacheSize = maxCacheSize;
    this.cacheExpiredTime = cacheExpiredTime;

    this.mongo = mongo;
    this.repo = repo;
    this.cacheManager = new MongoMetaCacheManager(maxCacheSize, cacheExpiredTime, collectionCountCacheSize,
            collectionCountCacheExpiredTime);

    String collectionName = CMSConsts.METACLASS_COLL;
    collection = mongo.getDB(repo.getRepositoryName()).getCollection(collectionName);
    // read from primary only
    collection.setReadPreference(ReadPreference.primary());
    collection.setWriteConcern(WriteConcern.SAFE);

    sequence = new MongoSequence(mongo, CMSConsts.SYS_DB, CMSConsts.SEQUENCE_COLL,
            CMSConsts.NEXT_FIELD_NAME_SEQ);

    this.getMetaClasses(new MetadataContext(true, true));
}

From source file:com.ebay.cloud.cms.metadata.mongo.MongoMetadataServiceImpl.java

License:Apache License

@Override
public int getCollectionCount(String dbCollectionName) {
    CheckConditions.checkNotNull(dbCollectionName, "Collection name can't be null!");
    Integer count = cacheManager.getCountFromCache(dbCollectionName);
    if (count == null) {
        DBCollection col = this.mongo.getDB(repo.getRepositoryName()).getCollection(dbCollectionName);
        // read from primary only
        col.setReadPreference(ReadPreference.primary());
        col.setWriteConcern(WriteConcern.SAFE);

        count = (Integer) col.getStats().get("count");
        if (count == null) {
            count = 0;/*from  w w w .j a v  a 2  s .c  o  m*/
        } else {
            cacheManager.putCountToCache(dbCollectionName, count);
        }
    }
    return count;
}

From source file:com.ebay.cloud.cms.metadata.mongo.MongoRepositoryServiceImpl.java

License:Apache License

public static void prepareSystemDB(Mongo mongo) {
    DBCollection repoCollection = mongo.getDB(CMSConsts.SYS_DB).getCollection(CMSConsts.REPOSITORY_COLL);

    MongoUtils.ensureIndex(repoCollection, Repository.REPOSITORY_FIELD_NAME, true, false);

    repoCollection.setWriteConcern(WriteConcern.SAFE);
}

From source file:com.ebay.cloud.cms.metadata.mongo.MongoRepositoryServiceImpl.java

License:Apache License

@Override
public Repository createRepository(Repository repo) {
    return createRepository(repo, WriteConcern.SAFE);
}

From source file:com.ebay.cloud.cms.metadata.RepositoryServiceFactory.java

License:Apache License

public static synchronized IRepositoryService createRepositoryService(MongoDataSource ds, String clientName) {
    return createRepositoryService(ds, clientName, WriteConcern.SAFE);
}

From source file:com.ebay.cloud.cms.metadata.sequence.MongoSequence.java

License:Apache License

public MongoSequence(Mongo mongo, String dbName, String collName, String key) {
    super();//from ww  w . ja va  2  s  .c om
    this.coll = mongo.getDB(dbName).getCollection(collName);
    this.key = key;

    this.coll.setWriteConcern(WriteConcern.SAFE);
}

From source file:com.ebay.jetstream.config.mongo.MongoDAO.java

License:MIT License

public static boolean removeConfigurationByQuery(BasicDBObject query, MongoConnection mongoConnection) {

    DBCollection dbCol = mongoConnection.getDBCollection();

    if (dbCol == null) {
        throw new MongoConfigRuntimeException("jetstreamconfig collection is unknown");
    }/*from w  w  w.java  2  s.co  m*/

    try {
        if (query == null) {
            return false;
        }

        WriteResult result = dbCol.remove(query, WriteConcern.SAFE);

        if (result.getLastError().ok()) {
            return true;
        }

    } catch (Exception err) {
        throw new MongoConfigRuntimeException(err);
    }

    return true;
}