Class TaskOptions
- All Implemented Interfaces:
Serializable
TaskOptions
methods may be chained to specify multiple options in the one TaskOptions
object.
taskOptions can have either TaskOptions.Method
PULL or a PUSH-related method, e.g.
POST, GET, ... Tasks with PULL method can only be added into a PULL queue and PUSH tasks can only
be added into a PUSH queue.
Notes on usage:
The recommended way to instantiate a TaskOptions
object is to statically import TaskOptions.Builder
.* and invoke a static creation method followed by an instance mutator (if needed):
import static com.google.appengine.api.taskqueue.TaskOptions.Builder.*;
...
{@link QueueFactory#getDefaultQueue()}.add(withUrl(url).etaMillis(eta));
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
Provides static creation methods forTaskOptions
.static enum
Methods supported byQueue
. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionClears the parameters.countdownMillis
(long countdownMillis) Set the number of milliseconds delay before execution of the task.dispatchDeadline
(Duration dispatchDeadline) Sets the dispatch deadline for a task.boolean
etaMillis
(long etaMillis) Sets the approximate absolute time to execute.Returns a copy of the task's byte-array-valued parameters as a map from each parameter name to a list of values for that name.Returns the delay to apply to the submitted time.@Nullable Duration
Returns the dispatch deadline for a task.Returns the specified ETA for a task.Returns a copy of the task's headers as a map from each header name to a list of values for that header name.Returns the method used for this task.byte[]
Returns the live payload for the task, not a copy.Returns a copy of the retry options for a task.Returns a copy of the task's string-valued parameters as a map from each parameter name to a list of values for that name.getTag()
Returns the tag for a task.byte[]
Returns the live tag bytes for a task, not a copy.Returns the task name.getUrl()
int
hashCode()
Adds a headername/value
pair.Replaces the existing headers with the provided headername/value
mapping.method
(TaskOptions.Method method) Set the method used for this task.Add a namedbyte
array parameter.Add a namedString
parameter.payload
(byte[] payload) Sets the payload directly without specifying the content-type.Set the payload with the given content type.payload
(DeferredTask deferredTask) Sets the payload to the serialized form of the deferredTask object.Set the payload byString
.Sets the payload from aString
given a specific character set.removeHeader
(String headerName) Remove all headers with the given name.removeParam
(String paramName) Remove all parameters with the given name.retryOptions
(RetryOptions retryOptions) Sets retry options for this task.tag
(byte[] tag) Sets the tag for a task.Sets the tag for a task.Sets the task name.toString()
Set the URL.
-
Constructor Details
-
TaskOptions
A copy constructor forTaskOptions
.
-
-
Method Details
-
taskName
Sets the task name.- Throws:
IllegalArgumentException
- The provided name is null, empty or doesn't match the regular expressionQueueConstants.TASK_NAME_REGEX
-
getTaskName
Returns the task name. -
getPayload
public byte[] getPayload()Returns the live payload for the task, not a copy. May benull
. -
payload
Sets the payload directly without specifying the content-type. If this task is added to a push queue, the content-type will be set to 'application/octet-stream' by default.- Parameters:
payload
- The bytes representing the paylaod.- Returns:
- TaskOptions object for chaining.
-
payload
Sets the payload to the serialized form of the deferredTask object. The payload will be generated by serializing the deferredTask object usingObjectOutputStream.writeObject(Object)
. If the deferredTask'sTaskOptions.Method
is not PULL, the content type will be set toDeferredTaskContext.RUNNABLE_TASK_CONTENT_TYPE
, the method will be forced toTaskOptions.Method.POST
and if otherwise not specified, the url will be set toDeferredTaskContext.DEFAULT_DEFERRED_URL
; theDeferredTask
servlet is, by default, mapped to this url.Note: While this may be a convenient API, it requires careful control of the serialization compatibility of objects passed into
payload(DeferredTask)
method as objects placed in the task queue will survive revision updates of the application and hence may fail deserialization when the task is decoded with new revisions of the application. In particular, Java anonymous classes are convenient but may be particularly difficult to control or test for serialization compatibility.- Parameters:
deferredTask
- The object to serialize into the payload.- Throws:
DeferredTaskCreationException
- if there was an IOException serializing object.
-
payload
Sets the payload from aString
given a specific character set.- Throws:
UnsupportedTranslationException
-
payload
Set the payload with the given content type.- Parameters:
payload
- The bytes representing the paylaod.contentType
- The content-type of the bytes.- Returns:
- TaskOptions object for chaining.
-
payload
Set the payload byString
. The charset to convert the String to will be UTF-8 unless the method is PULL, in which case the String's bytes will be used directly.- Parameters:
payload
- The String to be used.- Returns:
- TaskOptions object for chaining.
-
getHeaders
Returns a copy of the task's headers as a map from each header name to a list of values for that header name. -
headers
Replaces the existing headers with the provided headername/value
mapping.- Parameters:
headers
- The headers to copy.- Returns:
- TaskOptions object for chaining.
-
header
Adds a headername/value
pair.- Throws:
IllegalArgumentException
-
removeHeader
Remove all headers with the given name. -
getMethod
Returns the method used for this task. -
method
Set the method used for this task. Defaults toTaskOptions.Method.POST
. -
getStringParams
Returns a copy of the task's string-valued parameters as a map from each parameter name to a list of values for that name. -
getByteArrayParams
Returns a copy of the task's byte-array-valued parameters as a map from each parameter name to a list of values for that name. -
clearParams
Clears the parameters. -
param
Add a namedString
parameter.- Parameters:
name
- Name of the parameter. Must not be null or empty.value
- The value of the parameter will undergo a "UTF-8" character encoding transformation upon being added to the queue.value
must not benull
.- Throws:
IllegalArgumentException
-
param
Add a namedbyte
array parameter.- Parameters:
name
- Name of the parameter. Must not be null or empty.value
- A byte array and encoded as-is (i.e. without character encoding transformations).value
must not benull
.- Throws:
IllegalArgumentException
-
removeParam
Remove all parameters with the given name.- Parameters:
paramName
- Name of the parameter. Must not be null or empty.
-
getUrl
-
url
Set the URL.Default value is
null
.- Parameters:
url
- String containing URL.
-
getCountdownMillis
Returns the delay to apply to the submitted time. May benull
. -
countdownMillis
Set the number of milliseconds delay before execution of the task. -
getEtaMillis
Returns the specified ETA for a task. May benull
if not specified. -
etaMillis
Sets the approximate absolute time to execute. (i.e. etaMillis is comparable withSystem.currentTimeMillis()
). -
getRetryOptions
Returns a copy of the retry options for a task. May benull
if not specified. -
retryOptions
Sets retry options for this task. Retry Options must be built withRetryOptions.Builder
. -
getTagAsBytes
public byte[] getTagAsBytes()Returns the live tag bytes for a task, not a copy. May benull
if tag is not specified. -
getTag
Returns the tag for a task. May benull
if tag is not specified.- Throws:
UnsupportedEncodingException
-
getDispatchDeadline
Returns the dispatch deadline for a task. The dispatch deadline determines how long the of a task should take. If a task exceeds its deadline, it will be canceled and retried based on retry configurations of the task and/or queue. -
tag
Sets the tag for a task. Ignores null or zero-length tags. -
tag
Sets the tag for a task. Ignores null or empty tags. -
dispatchDeadline
Sets the dispatch deadline for a task. The dispatch deadline should be no smaller than TaskOptions#MIN_DISPATCH_DEADLINE and no larger than TaskOptions#MAX_DISPATCH_DEADLINE. -
hashCode
public int hashCode() -
equals
-
toString
-