App Engine Python SDK version 1.7.4 (2)
[gae.git] / java / src / main / com / google / appengine / api / taskqueue / DeferredTaskContext.java
blob4331f2ab55eefde95f0860821a42974f1a013ba2
1 // Copyright 2011 Google Inc. All Rights Reserved.
3 package com.google.appengine.api.taskqueue;
5 import com.google.apphosting.api.ApiProxy;
7 import java.util.Map;
9 import javax.servlet.http.HttpServlet;
10 import javax.servlet.http.HttpServletRequest;
11 import javax.servlet.http.HttpServletResponse;
13 /**
14 * Resources for managing {@link DeferredTask}.
17 public class DeferredTaskContext {
18 /**
19 * The content type of a serialized {@link DeferredTask}.
21 public static final String RUNNABLE_TASK_CONTENT_TYPE =
22 "application/x-binary-app-engine-java-runnable-task";
24 /**
25 * The URL the DeferredTask servlet is mapped to by default.
27 public static final String DEFAULT_DEFERRED_URL = "/_ah/queue/__deferred__";
29 static final String DEFERRED_TASK_SERVLET_KEY =
30 DeferredTaskContext.class.getName() + ".httpServlet";
31 static final String DEFERRED_TASK_REQUEST_KEY =
32 DeferredTaskContext.class.getName() + ".httpServletRequest";
33 static final String DEFERRED_TASK_RESPONSE_KEY =
34 DeferredTaskContext.class.getName() + ".httpServletResponse";
35 static final String DEFERRED_DO_NOT_RETRY_KEY =
36 DeferredTaskContext.class.getName() + ".doNotRetry";
38 /**
39 * Returns the {@link HttpServlet} instance for the current running
40 * deferred task for the current thread or {@code null} if there is
41 * no current deferred task active for this thread.
43 public static HttpServlet getCurrentServlet() {
44 Map<String, Object> attributes = ApiProxy.getCurrentEnvironment().getAttributes();
45 return (HttpServlet) attributes.get(DEFERRED_TASK_SERVLET_KEY);
48 /**
49 * Returns the {@link HttpServletRequest} instance for the current running
50 * deferred task for the current thread or {@code null} if there is
51 * no current deferred task active for this thread.
53 public static HttpServletRequest getCurrentRequest() {
54 Map<String, Object> attributes = ApiProxy.getCurrentEnvironment().getAttributes();
55 return (HttpServletRequest) attributes.get(DEFERRED_TASK_REQUEST_KEY);
58 /**
59 * Returns the {@link HttpServletResponse} instance for the current running
60 * deferred task for the current thread or {@code null} if there is
61 * no current deferred task active for this thread.
63 public static HttpServletResponse getCurrentResponse() {
64 Map<String, Object> attributes = ApiProxy.getCurrentEnvironment().getAttributes();
65 return (HttpServletResponse) attributes.get(DEFERRED_TASK_RESPONSE_KEY);
68 /**
69 * Sets the action on task failure. Normally when an exception is thrown,
70 * the task will be retried, however if {@link #setDoNotRetry}(false) is
71 * set, the task will not be retried.
73 public static void setDoNotRetry(boolean value) {
74 Map<String, Object> attributes = ApiProxy.getCurrentEnvironment().getAttributes();
75 attributes.put(DEFERRED_DO_NOT_RETRY_KEY, value);
78 private DeferredTaskContext() {}