Skip to content

Commit

Permalink
Simplifications.
Browse files Browse the repository at this point in the history
  • Loading branch information
anghelutar committed Feb 17, 2021
1 parent c664d1e commit e275a84
Showing 1 changed file with 5 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class AlfrescoStatusMetrics implements MeterBinder {

private RepoAdminService repoAdminService;
private RetryingTransactionHelper retryingTransactionHelper;

public AlfrescoStatusMetrics(RepoAdminService repoAdminService, RetryingTransactionHelper retryingTransactionHelper) {
this.repoAdminService = repoAdminService;
this.retryingTransactionHelper = retryingTransactionHelper;
Expand All @@ -27,9 +26,9 @@ public AlfrescoStatusMetrics(RepoAdminService repoAdminService, RetryingTransact
@Override
public void bindTo(@Nonnull MeterRegistry meterRegistry) {
LOGGER.info("Registering Alfresco Status metrics");
Gauge.builder(String.format("%s.%s", STATUS_PREFIX, "readonly"),
repoAdminService,
x -> getReadOnly(repoAdminService))
Gauge.builder(STATUS_PREFIX + ".readonly",
repoAdminService,
this::getReadOnly)
.description("Metric about Alfresco being in read-only mode")
.register(meterRegistry);

Expand All @@ -38,26 +37,11 @@ public void bindTo(@Nonnull MeterRegistry meterRegistry) {
private double getReadOnly(RepoAdminService repoAdminService) {
final boolean[] isReadOnly = {false};

retryingTransactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Object>() {

@Override
public Object execute() throws Throwable {
AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Object>() {

@Override
public Object doWork() throws Exception {
isReadOnly[0] = repoAdminService.getUsage().isReadOnly();

return null;
}
}, AuthenticationUtil.getAdminUserName());
return null;
}
},true);
retryingTransactionHelper.doInTransaction(()->AuthenticationUtil.runAsSystem(()->isReadOnly[0]=repoAdminService.getUsage().isReadOnly()),true);

if(isReadOnly[0])
return 1d;
else
return 0d;
}
}
}

0 comments on commit e275a84

Please sign in to comment.