Search in sources :

Example 51 with StopWatch

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

the class RepositoryImpl method selectOne.

@Override
public Optional<T> selectOne(String where, Object... params) {
    StopWatch watch = new StopWatch();
    String sql = selectQuery.selectSQL(where);
    int returnedRows = 0;
    try {
        Optional<T> result = database.operation.selectOne(sql, rowMapper, params);
        if (result.isPresent())
            returnedRows = 1;
        return result;
    } finally {
        long elapsedTime = watch.elapsedTime();
        ActionLogContext.track("db", elapsedTime, returnedRows, 0);
        logger.debug("selectOne, sql={}, params={}, elapsedTime={}", sql, params, elapsedTime);
        checkSlowOperation(elapsedTime);
    }
}
Also used : StopWatch(core.framework.util.StopWatch)

Example 52 with StopWatch

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

the class RepositoryImpl method get.

@Override
public Optional<T> get(Object... primaryKeys) {
    StopWatch watch = new StopWatch();
    String sql = selectQuery.getSQL;
    int returnedRows = 0;
    try {
        Optional<T> result = database.operation.selectOne(sql, rowMapper, primaryKeys);
        if (result.isPresent())
            returnedRows = 1;
        return result;
    } finally {
        long elapsedTime = watch.elapsedTime();
        ActionLogContext.track("db", elapsedTime, returnedRows, 0);
        logger.debug("get, sql={}, params={}, elapsedTime={}", sql, primaryKeys, elapsedTime);
        checkSlowOperation(elapsedTime);
    }
}
Also used : StopWatch(core.framework.util.StopWatch)

Example 53 with StopWatch

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

the class RedisHashImpl method set.

@Override
public void set(String key, String field, String value) {
    StopWatch watch = new StopWatch();
    PoolItem<RedisConnection> item = redis.pool.borrowItem();
    try {
        RedisConnection connection = item.resource;
        connection.write(HSET, encode(key), encode(field), encode(value));
        connection.readLong();
    } catch (IOException e) {
        item.broken = true;
        throw new UncheckedIOException(e);
    } finally {
        redis.pool.returnItem(item);
        long elapsedTime = watch.elapsedTime();
        ActionLogContext.track("redis", elapsedTime, 0, 1);
        logger.debug("hset, key={}, field={}, value={}, elapsedTime={}", key, field, value, elapsedTime);
        redis.checkSlowOperation(elapsedTime);
    }
}
Also used : UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) StopWatch(core.framework.util.StopWatch)

Example 54 with StopWatch

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

the class RedisHashImpl method getAll.

@Override
public Map<String, String> getAll(String key) {
    StopWatch watch = new StopWatch();
    PoolItem<RedisConnection> item = redis.pool.borrowItem();
    int returnedFields = 0;
    try {
        RedisConnection connection = item.resource;
        connection.write(HGETALL, encode(key));
        Object[] response = connection.readArray();
        if (response.length % 2 != 0)
            throw new RedisException("unexpected length of array, length=" + response.length);
        returnedFields = response.length / 2;
        Map<String, String> values = Maps.newHashMapWithExpectedSize(returnedFields);
        for (int i = 0; i < response.length; i += 2) {
            values.put(decode((byte[]) response[i]), decode((byte[]) response[i + 1]));
        }
        return values;
    } catch (IOException e) {
        item.broken = true;
        throw new UncheckedIOException(e);
    } finally {
        redis.pool.returnItem(item);
        long elapsedTime = watch.elapsedTime();
        ActionLogContext.track("redis", elapsedTime, returnedFields, 0);
        logger.debug("hgetAll, key={}, elapsedTime={}", key, elapsedTime);
        redis.checkSlowOperation(elapsedTime);
    }
}
Also used : UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) StopWatch(core.framework.util.StopWatch)

Example 55 with StopWatch

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

the class RedisHashImpl method multiSet.

@Override
public void multiSet(String key, Map<String, String> values) {
    StopWatch watch = new StopWatch();
    PoolItem<RedisConnection> item = redis.pool.borrowItem();
    try {
        RedisConnection connection = item.resource;
        connection.write(HMSET, encode(key, values));
        connection.readSimpleString();
    } catch (IOException e) {
        item.broken = true;
        throw new UncheckedIOException(e);
    } finally {
        redis.pool.returnItem(item);
        long elapsedTime = watch.elapsedTime();
        ActionLogContext.track("redis", elapsedTime, 0, values.size());
        logger.debug("hmset, key={}, values={}, elapsedTime={}", key, values, elapsedTime);
        redis.checkSlowOperation(elapsedTime);
    }
}
Also used : UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) 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