Reorganize account manager timers
This commit is contained in:
parent
dc691daf54
commit
54a41b4f0a
|
@ -54,10 +54,6 @@ public class AccountsManager {
|
||||||
private static final Timer redisSetTimer = metricRegistry.timer(name(AccountsManager.class, "redisSet" ));
|
private static final Timer redisSetTimer = metricRegistry.timer(name(AccountsManager.class, "redisSet" ));
|
||||||
private static final Timer redisGetTimer = metricRegistry.timer(name(AccountsManager.class, "redisGet" ));
|
private static final Timer redisGetTimer = metricRegistry.timer(name(AccountsManager.class, "redisGet" ));
|
||||||
|
|
||||||
private static final Timer databaseCreateTimer = metricRegistry.timer(name(AccountsManager.class, "databaseCreate"));
|
|
||||||
private static final Timer databaseGetTimer = metricRegistry.timer(name(AccountsManager.class, "databaseGet" ));
|
|
||||||
private static final Timer databaseUpdateTimer = metricRegistry.timer(name(AccountsManager.class, "databaseUpdate"));
|
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(AccountsManager.class);
|
private final Logger logger = LoggerFactory.getLogger(AccountsManager.class);
|
||||||
|
|
||||||
private final Accounts accounts;
|
private final Accounts accounts;
|
||||||
|
@ -139,12 +135,13 @@ public class AccountsManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void redisSet(String number, Account account, boolean optional) {
|
private void redisSet(String number, Account account, boolean optional) {
|
||||||
try (Timer.Context context = redisSetTimer.time()) {
|
|
||||||
new HystrixCommand<Boolean>(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(GroupKeys.REDIS_CACHE))
|
new HystrixCommand<Boolean>(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(GroupKeys.REDIS_CACHE))
|
||||||
.andCommandKey(HystrixCommandKey.Factory.asKey(AccountsManager.class.getSimpleName() + ".redisSet"))) {
|
.andCommandKey(HystrixCommandKey.Factory.asKey(AccountsManager.class.getSimpleName() + ".redisSet"))) {
|
||||||
@Override
|
@Override
|
||||||
protected Boolean run() {
|
protected Boolean run() {
|
||||||
try (Jedis jedis = cacheClient.getWriteResource()) {
|
try (Jedis jedis = cacheClient.getWriteResource();
|
||||||
|
Timer.Context timer = redisSetTimer.time())
|
||||||
|
{
|
||||||
jedis.set(getKey(number), mapper.writeValueAsString(account));
|
jedis.set(getKey(number), mapper.writeValueAsString(account));
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
throw new HystrixBadRequestException("Json processing error", e);
|
throw new HystrixBadRequestException("Json processing error", e);
|
||||||
|
@ -160,16 +157,16 @@ public class AccountsManager {
|
||||||
}
|
}
|
||||||
}.execute();
|
}.execute();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private Optional<Account> redisGet(String number) {
|
private Optional<Account> redisGet(String number) {
|
||||||
try (Timer.Context context = redisGetTimer.time()) {
|
|
||||||
return new HystrixCommand<Optional<Account>>(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(GroupKeys.REDIS_CACHE))
|
return new HystrixCommand<Optional<Account>>(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(GroupKeys.REDIS_CACHE))
|
||||||
.andCommandKey(HystrixCommandKey.Factory.asKey(AccountsManager.class.getSimpleName() + ".redisGet")))
|
.andCommandKey(HystrixCommandKey.Factory.asKey(AccountsManager.class.getSimpleName() + ".redisGet")))
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
protected Optional<Account> run() {
|
protected Optional<Account> run() {
|
||||||
try (Jedis jedis = cacheClient.getReadResource()) {
|
try (Jedis jedis = cacheClient.getReadResource();
|
||||||
|
Timer.Context timer = redisGetTimer.time())
|
||||||
|
{
|
||||||
String json = jedis.get(getKey(number));
|
String json = jedis.get(getKey(number));
|
||||||
|
|
||||||
if (json != null) return Optional.of(mapper.readValue(json, Account.class));
|
if (json != null) return Optional.of(mapper.readValue(json, Account.class));
|
||||||
|
@ -186,10 +183,8 @@ public class AccountsManager {
|
||||||
}
|
}
|
||||||
}.execute();
|
}.execute();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private Optional<Account> databaseGet(String number) {
|
private Optional<Account> databaseGet(String number) {
|
||||||
try (Timer.Context context = databaseGetTimer.time()) {
|
|
||||||
return new HystrixCommand<Optional<Account>>(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(GroupKeys.DATABASE_ACCOUNTS))
|
return new HystrixCommand<Optional<Account>>(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(GroupKeys.DATABASE_ACCOUNTS))
|
||||||
.andCommandKey(HystrixCommandKey.Factory.asKey(AccountsManager.class.getSimpleName() + ".databaseGet")))
|
.andCommandKey(HystrixCommandKey.Factory.asKey(AccountsManager.class.getSimpleName() + ".databaseGet")))
|
||||||
{
|
{
|
||||||
|
@ -199,10 +194,8 @@ public class AccountsManager {
|
||||||
}
|
}
|
||||||
}.execute();
|
}.execute();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private boolean databaseCreate(Account account) {
|
private boolean databaseCreate(Account account) {
|
||||||
try (Timer.Context context = databaseCreateTimer.time()) {
|
|
||||||
return new HystrixCommand<Boolean>(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(GroupKeys.DATABASE_ACCOUNTS))
|
return new HystrixCommand<Boolean>(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(GroupKeys.DATABASE_ACCOUNTS))
|
||||||
.andCommandKey(HystrixCommandKey.Factory.asKey(AccountsManager.class.getSimpleName() + ".databaseCreate")))
|
.andCommandKey(HystrixCommandKey.Factory.asKey(AccountsManager.class.getSimpleName() + ".databaseCreate")))
|
||||||
{
|
{
|
||||||
|
@ -212,10 +205,8 @@ public class AccountsManager {
|
||||||
}
|
}
|
||||||
}.execute();
|
}.execute();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void databaseUpdate(Account account) {
|
private void databaseUpdate(Account account) {
|
||||||
try (Timer.Context context = databaseUpdateTimer.time()) {
|
|
||||||
new HystrixCommand<Void>(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(GroupKeys.DATABASE_ACCOUNTS))
|
new HystrixCommand<Void>(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(GroupKeys.DATABASE_ACCOUNTS))
|
||||||
.andCommandKey(HystrixCommandKey.Factory.asKey(AccountsManager.class.getSimpleName() + ".databaseUpdate")))
|
.andCommandKey(HystrixCommandKey.Factory.asKey(AccountsManager.class.getSimpleName() + ".databaseUpdate")))
|
||||||
{
|
{
|
||||||
|
@ -227,4 +218,3 @@ public class AccountsManager {
|
||||||
}.execute();
|
}.execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue