use of core.framework.util.StopWatch in project core-ng-project by neowu.
the class MongoImpl method collection.
public <T> MongoCollection<T> collection(Class<T> entityClass) {
StopWatch watch = new StopWatch();
try {
new MongoClassValidator(entityClass).validateEntityClass();
codecs.registerEntity(entityClass);
return new MongoCollectionImpl<>(this, entityClass);
} finally {
logger.info("register mongo entity, entityClass={}, elapsedTime={}", entityClass.getCanonicalName(), watch.elapsedTime());
}
}
use of core.framework.util.StopWatch in project core-ng-project by neowu.
the class RedisHashImpl method del.
@Override
public boolean del(String key, String... fields) {
StopWatch watch = new StopWatch();
PoolItem<RedisConnection> item = redis.pool.borrowItem();
try {
RedisConnection connection = item.resource;
connection.write(HDEL, encode(key, fields));
return connection.readLong() >= 1;
} catch (IOException e) {
item.broken = true;
throw new UncheckedIOException(e);
} finally {
redis.pool.returnItem(item);
long elapsedTime = watch.elapsedTime();
ActionLogContext.track("redis", elapsedTime, 0, fields.length);
logger.debug("hdel, key={}, fields={}, elapsedTime={}", key, fields, elapsedTime);
redis.checkSlowOperation(elapsedTime);
}
}
use of core.framework.util.StopWatch in project core-ng-project by neowu.
the class RedisImpl method multiGetBytes.
public Map<String, byte[]> multiGetBytes(String... keys) {
StopWatch watch = new StopWatch();
PoolItem<RedisConnection> item = pool.borrowItem();
try {
RedisConnection connection = item.resource;
byte[][] arguments = new byte[keys.length][];
for (int i = 0; i < keys.length; i++) {
arguments[i] = encode(keys[i]);
}
Map<String, byte[]> values = Maps.newHashMapWithExpectedSize(keys.length);
connection.write(Protocol.Command.MGET, arguments);
Object[] response = connection.readArray();
for (int i = 0; i < response.length; i++) {
byte[] value = (byte[]) response[i];
if (value != null)
values.put(keys[i], value);
}
return values;
} catch (IOException e) {
item.broken = true;
throw new UncheckedIOException(e);
} finally {
pool.returnItem(item);
long elapsedTime = watch.elapsedTime();
ActionLogContext.track("redis", elapsedTime, keys.length, 0);
logger.debug("mget, keys={}, elapsedTime={}", keys, elapsedTime);
checkSlowOperation(elapsedTime);
}
}
use of core.framework.util.StopWatch in project core-ng-project by neowu.
the class RedisImpl method multiSet.
@Override
public void multiSet(Map<String, String> values) {
StopWatch watch = new StopWatch();
PoolItem<RedisConnection> item = pool.borrowItem();
try {
RedisConnection connection = item.resource;
connection.write(Protocol.Command.MSET, encode(values));
connection.readSimpleString();
} catch (IOException e) {
item.broken = true;
throw new UncheckedIOException(e);
} finally {
pool.returnItem(item);
long elapsedTime = watch.elapsedTime();
ActionLogContext.track("redis", elapsedTime, 0, values.size());
logger.debug("mset, values={}, elapsedTime={}", values, elapsedTime);
checkSlowOperation(elapsedTime);
}
}
use of core.framework.util.StopWatch in project core-ng-project by neowu.
the class RedisImpl method setIfAbsent.
@Override
public boolean setIfAbsent(String key, String value, Duration expiration) {
StopWatch watch = new StopWatch();
PoolItem<RedisConnection> item = pool.borrowItem();
try {
RedisConnection connection = item.resource;
connection.write(Protocol.Command.SET, encode(key), encode(value), NX, EX, encode(expiration.getSeconds()));
String result = connection.readSimpleString();
return "OK".equals(result);
} catch (IOException e) {
item.broken = true;
throw new UncheckedIOException(e);
} finally {
pool.returnItem(item);
long elapsedTime = watch.elapsedTime();
ActionLogContext.track("redis", elapsedTime, 0, 1);
logger.debug("setIfAbsent, key={}, value={}, expiration={}, elapsedTime={}", key, value, expiration, elapsedTime);
checkSlowOperation(elapsedTime);
}
}
Aggregations