You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IsQueueEmptyWs.java 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * SonarQube, open source software quality management tool.
  3. * Copyright (C) 2008-2014 SonarSource
  4. * mailto:contact AT sonarsource DOT com
  5. *
  6. * SonarQube is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * SonarQube is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.server.computation.ws;
  21. import org.apache.commons.io.IOUtils;
  22. import org.sonar.api.server.ws.Request;
  23. import org.sonar.api.server.ws.RequestHandler;
  24. import org.sonar.api.server.ws.Response;
  25. import org.sonar.api.server.ws.WebService;
  26. import org.sonar.db.compute.AnalysisReportDto;
  27. import org.sonar.server.computation.ReportQueue;
  28. import java.util.List;
  29. /**
  30. * Internal WebService with one action
  31. */
  32. public class IsQueueEmptyWs implements WebService {
  33. public static final String API_ENDPOINT = "api/analysis_reports";
  34. private final IsQueueEmptyAction action;
  35. public IsQueueEmptyWs(ReportQueue queue) {
  36. this.action = new IsQueueEmptyAction(queue);
  37. }
  38. @Override
  39. public void define(Context context) {
  40. NewController controller = context
  41. .createController(API_ENDPOINT)
  42. .setDescription("Analysis reports processed");
  43. action.define(controller);
  44. controller.done();
  45. }
  46. static class IsQueueEmptyAction implements RequestHandler {
  47. private final ReportQueue queue;
  48. public IsQueueEmptyAction(ReportQueue queue) {
  49. this.queue = queue;
  50. }
  51. public void define(WebService.NewController controller) {
  52. controller
  53. .createAction("is_queue_empty")
  54. .setDescription("Check if the analysis report queue is empty")
  55. .setInternal(true)
  56. .setHandler(this);
  57. }
  58. @Override
  59. public void handle(Request request, Response response) throws Exception {
  60. List<AnalysisReportDto> reports = queue.all();
  61. boolean isQueueEmpty = reports.isEmpty();
  62. IOUtils.write(String.valueOf(isQueueEmpty), response.stream().output());
  63. }
  64. }
  65. }