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