Search in sources :

Example 76 with StopWatch

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);
    }
}
Also used : UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) StopWatch(core.framework.util.StopWatch) HashSet(java.util.HashSet)

Example 77 with StopWatch

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);
    }
}
Also used : UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) StopWatch(core.framework.util.StopWatch)

Example 78 with StopWatch

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);
    }
}
Also used : UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) StopWatch(core.framework.util.StopWatch)

Example 79 with StopWatch

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());
    }
}
Also used : 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