class RuntimeResourceUsageTracker implements ResourceUsageTracker {

  @Override
  public Optional<Resource> getUsedResource(String accountId)
      throws NotFoundException, ServerException {
    final Account account = accountManager.getById(accountId);
    final long currentlyUsedRuntimes =
        Pages.stream(
                (maxItems, skipCount) ->
                    workspaceManagerProvider
                        .get()
                        .getByNamespace(account.getName(), false, maxItems, skipCount))
            .filter(ws -> STOPPED != ws.getStatus())
            .count();
    if (currentlyUsedRuntimes > 0) {
      return Optional.of(
          new ResourceImpl(
              RuntimeResourceType.ID, currentlyUsedRuntimes, RuntimeResourceType.UNIT));
    } else {
      return Optional.empty();
    }
  }

  @Inject public  RuntimeResourceUsageTracker(
      Provider<WorkspaceManager> workspaceManagerProvider, AccountManager accountManager);

}