PageRenderTime 159ms CodeModel.GetById 149ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

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