use of core.framework.util.StopWatch in project core-ng-project by neowu.
the class RedisSetImpl method members.
@Override
public Set<String> members(String key) {
StopWatch watch = new StopWatch();
PoolItem<RedisConnection> item = redis.pool.borrowItem();
int returnedMembers = 0;
try {
RedisConnection connection = item.resource;
connection.write(SMEMBERS, encode(key));
Object[] response = connection.readArray();
returnedMembers = response.length;
Set<String> members = new HashSet<>(returnedMembers);
for (Object member : response) {
members.add(decode((byte[]) member));
}
return members;
} catch (IOException e) {
item.broken = true;
throw new UncheckedIOException(e);
} finally {
redis.pool.returnItem(item);
long elapsedTime = watch.elapsedTime();
ActionLogContext.track("redis", elapsedTime, returnedMembers, 0);
logger.debug("smembers, key={}, elapsedTime={}", key, elapsedTime);
redis.checkSlowOperation(elapsedTime);
}
}
use of core.framework.util.StopWatch in project core-ng-project by neowu.
the class RedisSetImpl method isMember.
@Override
public boolean isMember(String key, String value) {
StopWatch watch = new StopWatch();
PoolItem<RedisConnection> item = redis.pool.borrowItem();
try {
RedisConnection connection = item.resource;
connection.write(SISMEMBER, encode(key), encode(value));
Long response = connection.readLong();
return response == 1;
} catch (IOException e) {
item.broken = true;
throw new UncheckedIOException(e);
} finally {
redis.pool.returnItem(item);
long elapsedTime = watch.elapsedTime();
ActionLogContext.track("redis", elapsedTime, 1, 0);
logger.debug("sismember, key={}, value={}, elapsedTime={}", key, value, elapsedTime);
redis.checkSlowOperation(elapsedTime);
}
}
use of core.framework.util.StopWatch in project core-ng-project by neowu.
the class RedisSetImpl method remove.
@Override
public boolean remove(String key, String... values) {
StopWatch watch = new StopWatch();
PoolItem<RedisConnection> item = redis.pool.borrowItem();
try {
RedisConnection connection = item.resource;
connection.write(SREM, encode(key, values));
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, values.length);
logger.debug("srem, key={}, values={}, elapsedTime={}", key, values, elapsedTime);
redis.checkSlowOperation(elapsedTime);
}
}
use of core.framework.util.StopWatch in project core-ng-project by neowu.
the class Pool method recycleItem.
private void recycleItem(PoolItem<T> item) {
StopWatch watch = new StopWatch();
int size = this.size.decrementAndGet();
try {
closeResource(item.resource);
} finally {
logger.debug("recycle resource, pool={}, size={}, elapsed={}", name, size, watch.elapsedTime());
}
}
Aggregations