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 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 Accounts accounts;
|
||||
|
@ -139,12 +135,13 @@ public class AccountsManager {
|
|||
}
|
||||
|
||||
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))
|
||||
.andCommandKey(HystrixCommandKey.Factory.asKey(AccountsManager.class.getSimpleName() + ".redisSet"))) {
|
||||
@Override
|
||||
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));
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new HystrixBadRequestException("Json processing error", e);
|
||||
|
@ -160,16 +157,16 @@ public class AccountsManager {
|
|||
}
|
||||
}.execute();
|
||||
}
|
||||
}
|
||||
|
||||
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))
|
||||
.andCommandKey(HystrixCommandKey.Factory.asKey(AccountsManager.class.getSimpleName() + ".redisGet")))
|
||||
{
|
||||
@Override
|
||||
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));
|
||||
|
||||
if (json != null) return Optional.of(mapper.readValue(json, Account.class));
|
||||
|
@ -186,10 +183,8 @@ public class AccountsManager {
|
|||
}
|
||||
}.execute();
|
||||
}
|
||||
}
|
||||
|
||||
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))
|
||||
.andCommandKey(HystrixCommandKey.Factory.asKey(AccountsManager.class.getSimpleName() + ".databaseGet")))
|
||||
{
|
||||
|
@ -199,10 +194,8 @@ public class AccountsManager {
|
|||
}
|
||||
}.execute();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean databaseCreate(Account account) {
|
||||
try (Timer.Context context = databaseCreateTimer.time()) {
|
||||
return new HystrixCommand<Boolean>(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(GroupKeys.DATABASE_ACCOUNTS))
|
||||
.andCommandKey(HystrixCommandKey.Factory.asKey(AccountsManager.class.getSimpleName() + ".databaseCreate")))
|
||||
{
|
||||
|
@ -212,10 +205,8 @@ public class AccountsManager {
|
|||
}
|
||||
}.execute();
|
||||
}
|
||||
}
|
||||
|
||||
private void databaseUpdate(Account account) {
|
||||
try (Timer.Context context = databaseUpdateTimer.time()) {
|
||||
new HystrixCommand<Void>(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(GroupKeys.DATABASE_ACCOUNTS))
|
||||
.andCommandKey(HystrixCommandKey.Factory.asKey(AccountsManager.class.getSimpleName() + ".databaseUpdate")))
|
||||
{
|
||||
|
@ -226,5 +217,4 @@ public class AccountsManager {
|
|||
}
|
||||
}.execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue