/src/main/java/com/google/ie/common/taskqueue/TagWeightUpdationManager.java

http://thoughtsite.googlecode.com/ · Java · 81 lines · 34 code · 7 blank · 40 comment · 2 complexity · ecd5a3d21bc29ac2ac5345715348c9e8 MD5 · raw file

  1. /* Copyright 2010 Google Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS.
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License
  14. */
  15. package com.google.ie.common.taskqueue;
  16. import com.google.appengine.api.labs.taskqueue.Queue;
  17. import com.google.appengine.api.labs.taskqueue.QueueFactory;
  18. import com.google.appengine.api.labs.taskqueue.TaskOptions;
  19. import com.google.ie.common.constants.IdeaExchangeConstants;
  20. import org.apache.log4j.Logger;
  21. import org.springframework.stereotype.Component;
  22. /**
  23. * An object that helps manage the weight calculation of tags {@link Tag}.
  24. * This class is used to queue a task for incrementing the weight of tag when
  25. * tag is associated with a published idea.
  26. *
  27. * @author Charanjeet singh
  28. */
  29. @Component
  30. public class TagWeightUpdationManager {
  31. /** Logger for the class */
  32. private static Logger logger = Logger.getLogger(TagWeightUpdationManager.class);
  33. private final boolean isDebug = logger.isDebugEnabled();
  34. /**
  35. * Publishes the task of incrementing the weight of tags to a task queue.
  36. * It adds a task to increment the weight of tags passed as a comma
  37. * separated string.
  38. *
  39. * @param tagString a comma separated string.
  40. *
  41. */
  42. public void incrementWeight(String tagString) {
  43. /* Use Task Queue to queue the task to increment the weight of tags. */
  44. Queue queue = QueueFactory.getQueue(IdeaExchangeConstants.TAGS_WEIGHT_UPDATION_QUEUE);
  45. TaskOptions taskOptions = TaskOptions.Builder.url(
  46. IdeaExchangeConstants.TAGS_WEIGHT_UPDATION_URL)
  47. .param(IdeaExchangeConstants.COMMA_SEPARATED_TAG_STRING, tagString);
  48. queue.add(taskOptions);
  49. if (isDebug)
  50. logger.debug("Task to increment the weight of tag in tag string '" + tagString
  51. + "', added to queue :"
  52. + IdeaExchangeConstants.TAGS_WEIGHT_UPDATION_QUEUE);
  53. }
  54. /**
  55. * Publishes the task of decrementing the weight of tags to a task queue.
  56. * It adds a task to decrement the weight of tags passed as a comma
  57. * separated string.
  58. *
  59. * @param tagString a comma separated string.
  60. *
  61. */
  62. public void decrementWeight(String tagString) {
  63. /* Use Task Queue to queue the task to decrement the weight of tags. */
  64. Queue queue = QueueFactory.getQueue(IdeaExchangeConstants.TAGS_WEIGHT_UPDATION_QUEUE);
  65. TaskOptions taskOptions = TaskOptions.Builder.url(
  66. IdeaExchangeConstants.TAGS_WEIGHT_DECREMENT_URL)
  67. .param(IdeaExchangeConstants.COMMA_SEPARATED_TAG_STRING, tagString);
  68. queue.add(taskOptions);
  69. if (isDebug)
  70. logger.debug("Task to decrement the weight of tag in tag string '" + tagString
  71. + "', added to queue :"
  72. + IdeaExchangeConstants.TAGS_WEIGHT_UPDATION_QUEUE);
  73. }
  74. }