Search in sources :

Example 1 with StopWatch

use of core.framework.util.StopWatch in project core-ng-project by neowu.

the class MongoCollectionImpl method forEach.

@Override
public void forEach(Query query, Consumer<T> consumer) {
    StopWatch watch = new StopWatch();
    int returnedRows = 0;
    try {
        FindIterable<T> mongoQuery = mongoQuery(query);
        returnedRows = apply(mongoQuery, consumer);
    } finally {
        long elapsedTime = watch.elapsedTime();
        ActionLogContext.track("mongoDB", elapsedTime, returnedRows, 0);
        logger.debug("forEach, collection={}, filter={}, projection={}, sort={}, skip={}, limit={}, readPref={}, returnedRows={}, elapsedTime={}", collectionName, new BsonParam(query.filter, mongo.registry), new BsonParam(query.projection, mongo.registry), new BsonParam(query.sort, mongo.registry), query.skip, query.limit, query.readPreference == null ? null : query.readPreference.getName(), returnedRows, elapsedTime);
    }
}
Also used : StopWatch(core.framework.util.StopWatch)

Example 2 with StopWatch

use of core.framework.util.StopWatch in project core-ng-project by neowu.

the class MongoCollectionImpl method update.

@Override
public long update(Bson filter, Bson update) {
    StopWatch watch = new StopWatch();
    long updatedRows = 0;
    try {
        UpdateResult result = collection().updateMany(filter, update);
        updatedRows = result.getModifiedCount();
        return updatedRows;
    } finally {
        long elapsedTime = watch.elapsedTime();
        ActionLogContext.track("mongoDB", elapsedTime, 0, (int) updatedRows);
        logger.debug("update, collection={}, filter={}, update={}, updatedRows={}, elapsedTime={}", collectionName, new BsonParam(filter, mongo.registry), update, updatedRows, elapsedTime);
        checkSlowOperation(elapsedTime);
    }
}
Also used : UpdateResult(com.mongodb.client.result.UpdateResult) StopWatch(core.framework.util.StopWatch)

Example 3 with StopWatch

use of core.framework.util.StopWatch in project core-ng-project by neowu.

the class MongoCollectionImpl method delete.

@Override
public boolean delete(Object id) {
    StopWatch watch = new StopWatch();
    long deletedRows = 0;
    try {
        DeleteResult result = collection().deleteOne(Filters.eq("_id", id));
        deletedRows = result.getDeletedCount();
        return deletedRows == 1;
    } finally {
        long elapsedTime = watch.elapsedTime();
        ActionLogContext.track("mongoDB", elapsedTime, 0, (int) deletedRows);
        logger.debug("delete, collection={}, id={}, elapsedTime={}", collectionName, id, elapsedTime);
        checkSlowOperation(elapsedTime);
    }
}
Also used : DeleteResult(com.mongodb.client.result.DeleteResult) StopWatch(core.framework.util.StopWatch)

Example 4 with StopWatch

use of core.framework.util.StopWatch in project core-ng-project by neowu.

the class MongoImpl method view.

public <T> void view(Class<T> viewClass) {
    StopWatch watch = new StopWatch();
    try {
        new MongoClassValidator(viewClass).validateViewClass();
        codecs.registerView(viewClass);
    } finally {
        logger.info("register mongo view, viewClass={}, elapsedTime={}", viewClass.getCanonicalName(), watch.elapsedTime());
    }
}
Also used : StopWatch(core.framework.util.StopWatch)

Example 5 with StopWatch

use of core.framework.util.StopWatch in project core-ng-project by neowu.

the class MongoImpl method createDatabase.

protected MongoDatabase createDatabase(CodecRegistry registry) {
    if (uri == null)
        throw new Error("uri must not be null");
    StopWatch watch = new StopWatch();
    try {
        builder.connectTimeout(timeoutInMs);
        builder.socketTimeout(timeoutInMs);
        // pool checkout timeout
        builder.maxWaitTime(timeoutInMs);
        // able to try 3 servers
        builder.serverSelectionTimeout(timeoutInMs * 3);
        builder.codecRegistry(registry);
        mongoClient = new MongoClient(uri);
        return mongoClient.getDatabase(uri.getDatabase());
    } finally {
        logger.info("create mongo client, uri={}, elapsedTime={}", uri, watch.elapsedTime());
    }
}
Also used : MongoClient(com.mongodb.MongoClient) StopWatch(core.framework.util.StopWatch)

Aggregations

StopWatch (core.framework.util.StopWatch)79 IOException (java.io.IOException)21 UncheckedIOException (java.io.UncheckedIOException)21 SearchException (core.framework.search.SearchException)10 ElasticsearchException (org.elasticsearch.ElasticsearchException)10 ArrayList (java.util.ArrayList)6 HTMLTemplate (core.framework.impl.template.HTMLTemplate)4 BytesParam (core.framework.impl.log.filter.BytesParam)3 Map (java.util.Map)3 BsonDocument (org.bson.BsonDocument)3 BulkWriteOptions (com.mongodb.client.model.BulkWriteOptions)2 UpdateOptions (com.mongodb.client.model.UpdateOptions)2 DeleteResult (com.mongodb.client.result.DeleteResult)2 TemplateContext (core.framework.impl.template.TemplateContext)2 Headers (org.apache.kafka.common.header.Headers)2 Bson (org.bson.conversions.Bson)2 BulkRequestBuilder (org.elasticsearch.action.bulk.BulkRequestBuilder)2 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)2 Settings (org.elasticsearch.common.settings.Settings)2 MongoClient (com.mongodb.MongoClient)1