PageRenderTime 18ms CodeModel.GetById 9ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/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
16package com.google.ie.common.taskqueue;
17
18import com.google.appengine.api.labs.taskqueue.Queue;
19import com.google.appengine.api.labs.taskqueue.QueueFactory;
20import com.google.appengine.api.labs.taskqueue.TaskOptions;
21import com.google.ie.common.constants.IdeaExchangeConstants;
22
23import org.apache.log4j.Logger;
24import org.springframework.stereotype.Component;
25
26/**
27 * An object that helps manage the weight calculation of tags {@link Tag}.
28 * This class is used to queue a task for incrementing the weight of tag when
29 * tag is associated with a published idea.
30 * 
31 * @author Charanjeet singh
32 */
33@Component
34public class TagWeightUpdationManager {
35    /** Logger for the class */
36    private static Logger logger = Logger.getLogger(TagWeightUpdationManager.class);
37    private final boolean isDebug = logger.isDebugEnabled();
38
39    /**
40     * Publishes the task of incrementing the weight of tags to a task queue.
41     * It adds a task to increment the weight of tags passed as a comma
42     * separated string.
43     * 
44     * @param tagString a comma separated string.
45     * 
46     */
47    public void incrementWeight(String tagString) {
48        /* Use Task Queue to queue the task to increment the weight of tags. */
49        Queue queue = QueueFactory.getQueue(IdeaExchangeConstants.TAGS_WEIGHT_UPDATION_QUEUE);
50        TaskOptions taskOptions = TaskOptions.Builder.url(
51                        IdeaExchangeConstants.TAGS_WEIGHT_UPDATION_URL)
52                        .param(IdeaExchangeConstants.COMMA_SEPARATED_TAG_STRING, tagString);
53        queue.add(taskOptions);
54        if (isDebug)
55            logger.debug("Task to increment the weight of tag in tag string '" + tagString
56                            + "', added to queue :"
57                            + IdeaExchangeConstants.TAGS_WEIGHT_UPDATION_QUEUE);
58    }
59
60    /**
61     * Publishes the task of decrementing the weight of tags to a task queue.
62     * It adds a task to decrement the weight of tags passed as a comma
63     * separated string.
64     * 
65     * @param tagString a comma separated string.
66     * 
67     */
68    public void decrementWeight(String tagString) {
69        /* Use Task Queue to queue the task to decrement the weight of tags. */
70        Queue queue = QueueFactory.getQueue(IdeaExchangeConstants.TAGS_WEIGHT_UPDATION_QUEUE);
71        TaskOptions taskOptions = TaskOptions.Builder.url(
72                        IdeaExchangeConstants.TAGS_WEIGHT_DECREMENT_URL)
73                        .param(IdeaExchangeConstants.COMMA_SEPARATED_TAG_STRING, tagString);
74        queue.add(taskOptions);
75        if (isDebug)
76            logger.debug("Task to decrement the weight of tag in tag string '" + tagString
77                            + "', added to queue :"
78                            + IdeaExchangeConstants.TAGS_WEIGHT_UPDATION_QUEUE);
79    }
80}
81