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);
}
}
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);
}
}
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);
}
}
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());
}
}
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());
}
}
Aggregations