Search in sources :

Example 56 with StopWatch

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

the class RedisHashImpl method get.

@Override
public String get(String key, String field) {
    StopWatch watch = new StopWatch();
    PoolItem<RedisConnection> item = redis.pool.borrowItem();
    try {
        RedisConnection connection = item.resource;
        connection.write(HGET, encode(key), encode(field));
        return decode(connection.readBulkString());
    } 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("hget, key={}, field={}, elapsedTime={}", key, field, elapsedTime);
        redis.checkSlowOperation(elapsedTime);
    }
}
Also used : UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) StopWatch(core.framework.util.StopWatch)

Example 57 with StopWatch

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

the class RedisImpl method set.

public void set(String key, byte[] value, Duration expiration) {
    StopWatch watch = new StopWatch();
    PoolItem<RedisConnection> item = pool.borrowItem();
    try {
        RedisConnection connection = item.resource;
        connection.write(Protocol.Command.SETEX, encode(key), encode(expiration.getSeconds()), value);
        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, 1);
        logger.debug("set, key={}, value={}, expiration={}, elapsedTime={}", key, new BytesParam(value), expiration, elapsedTime);
        checkSlowOperation(elapsedTime);
    }
}
Also used : BytesParam(core.framework.impl.log.filter.BytesParam) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) StopWatch(core.framework.util.StopWatch)

Example 58 with StopWatch

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

the class RedisImpl method increaseBy.

@Override
public long increaseBy(String key, long increment) {
    StopWatch watch = new StopWatch();
    PoolItem<RedisConnection> item = pool.borrowItem();
    try {
        RedisConnection connection = item.resource;
        connection.write(Protocol.Command.INCRBY, encode(key), encode(increment));
        return connection.readLong();
    } 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("increaseBy, key={}, increment={}, elapsedTime={}", key, increment, elapsedTime);
        checkSlowOperation(elapsedTime);
    }
}
Also used : UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) StopWatch(core.framework.util.StopWatch)

Example 59 with StopWatch

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

the class RedisImpl method getBytes.

public byte[] getBytes(String key) {
    StopWatch watch = new StopWatch();
    PoolItem<RedisConnection> item = pool.borrowItem();
    try {
        RedisConnection connection = item.resource;
        connection.write(Protocol.Command.GET, encode(key));
        return connection.readBulkString();
    } catch (IOException e) {
        item.broken = true;
        throw new UncheckedIOException(e);
    } finally {
        pool.returnItem(item);
        long elapsedTime = watch.elapsedTime();
        ActionLogContext.track("redis", elapsedTime, 1, 0);
        logger.debug("get, key={}, elapsedTime={}", key, elapsedTime);
        checkSlowOperation(elapsedTime);
    }
}
Also used : UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) StopWatch(core.framework.util.StopWatch)

Example 60 with StopWatch

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

the class RedisImpl method multiSet.

public void multiSet(Map<String, byte[]> values, Duration expiration) {
    StopWatch watch = new StopWatch();
    byte[] expirationValue = encode(expiration.getSeconds());
    PoolItem<RedisConnection> item = pool.borrowItem();
    int size = values.size();
    try {
        RedisConnection connection = item.resource;
        for (Map.Entry<String, byte[]> entry : values.entrySet()) {
            connection.write(Protocol.Command.SETEX, encode(entry.getKey()), expirationValue, entry.getValue());
        }
        connection.readAll(size);
    } catch (IOException e) {
        item.broken = true;
        throw new UncheckedIOException(e);
    } finally {
        pool.returnItem(item);
        long elapsedTime = watch.elapsedTime();
        ActionLogContext.track("redis", elapsedTime, 0, size);
        logger.debug("mset, values={}, expiration={}, elapsedTime={}", values, expiration, elapsedTime);
        checkSlowOperation(elapsedTime);
    }
}
Also used : UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) Map(java.util.Map) 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