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

http://thoughtsite.googlecode.com/ · Java · 58 lines · 24 code · 7 blank · 27 comment · 1 complexity · 20a1b392d3cb619550ed577721af015c 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.datastore.Key;
  17. import com.google.appengine.api.datastore.KeyFactory;
  18. import com.google.appengine.api.labs.taskqueue.Queue;
  19. import com.google.appengine.api.labs.taskqueue.QueueFactory;
  20. import com.google.appengine.api.labs.taskqueue.TaskOptions;
  21. import com.google.ie.common.constants.IdeaExchangeConstants;
  22. import org.apache.log4j.Logger;
  23. import org.springframework.stereotype.Component;
  24. /**
  25. * An object that manages the indexing queue of the system.
  26. * This class is used to queue a task for indexing an entity.
  27. *
  28. * @author asirohi
  29. *
  30. */
  31. @Component
  32. public class IndexQueueUpdater {
  33. /** Logger for the class */
  34. private static Logger log = Logger.getLogger(IndexQueueUpdater.class);
  35. /**
  36. * Add the task to a {@link Queue} to index entity.
  37. *
  38. */
  39. public void indexEntity(Key indexKey) {
  40. /* Use Task Queue to queue the task to index. */
  41. Queue queue = QueueFactory.getQueue(IdeaExchangeConstants.INDEX_QUEUE);
  42. String keyString = KeyFactory.keyToString(indexKey);
  43. TaskOptions taskOptions = TaskOptions.Builder.url(IdeaExchangeConstants.INDEX_URL
  44. + IdeaExchangeConstants.BACKSLASH + keyString);
  45. queue.add(taskOptions);
  46. if (log.isDebugEnabled()) {
  47. log.debug("Task for indexing added to queue :"
  48. + IdeaExchangeConstants.INDEX_QUEUE);
  49. }
  50. }
  51. }