class LimitsCheckingWorkspaceManager extends WorkspaceManager {

  @VisibleForTesting
  void checkMaxEnvironmentRam(WorkspaceConfig config) throws ServerException {
    if (maxRamPerEnvMB < 0) {
      return;
    }
    if (config.getEnvironments().isEmpty()) {
      return;
    }
    for (Map.Entry<String, ? extends Environment> envEntry : config.getEnvironments().entrySet()) {
      Environment env = envEntry.getValue();
      final long workspaceRam = environmentRamCalculator.calculate(env);
      if (workspaceRam > maxRamPerEnvMB) {
        throw new LimitExceededException(
            format("You are only allowed to use %d mb. RAM per workspace.", maxRamPerEnvMB),
            ImmutableMap.of(
                "environment_max_ram",
                Long.toString(maxRamPerEnvMB),
                "environment_max_ram_unit",
                "mb",
                "environment_ram",
                Long.toString(workspaceRam),
                "environment_ram_unit",
                "mb"));
      }
    }
  }

  @Inject public  LimitsCheckingWorkspaceManager(
      WorkspaceDao workspaceDao,
      WorkspaceRuntimes runtimes,
      EventService eventService,
      AccountManager accountManager,
      PreferenceManager preferenceManager,
      WorkspaceValidator workspaceValidator,
      // own injects
      @Named("che.limits.workspace.env.ram") String maxRamPerEnv,
      EnvironmentRamCalculator environmentRamCalculator,
      ResourceManager resourceManager,
      ResourcesLocks resourcesLocks,
      DevfileIntegrityValidator devfileIntegrityValidator);

}