Class TaskOptions
- java.lang.Object
-
- com.google.appengine.api.taskqueue.TaskOptions
-
- All Implemented Interfaces:
- java.io.Serializable
public final class TaskOptions extends java.lang.Object implements java.io.SerializableContains various options for a task following the builder pattern. Calls toTaskOptionsmethods may be chained to specify multiple options in the oneTaskOptionsobject.taskOptions can have either
TaskOptions.MethodPULL 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 aTaskOptionsobject is to statically importTaskOptions.Builder.* and invoke a static creation method followed by an instance mutator (if needed):import static com.google.appengine.api.taskqueue.TaskOptions.Builder.*; ...
QueueFactory.getDefaultQueue().add(withUrl(url).etaMillis(eta));- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classTaskOptions.BuilderProvides static creation methods forTaskOptions.static classTaskOptions.MethodMethods supported byQueue.
-
Constructor Summary
Constructors Constructor and Description TaskOptions(TaskOptions options)A copy constructor forTaskOptions.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description TaskOptionsclearParams()Clears the parameters.TaskOptionscountdownMillis(long countdownMillis)Set the number of milliseconds delay before execution of the task.booleanequals(java.lang.Object obj)TaskOptionsetaMillis(long etaMillis)Sets the approximate absolute time to execute.java.util.Map<java.lang.String,java.util.List<byte[]>>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.java.lang.LonggetCountdownMillis()Returns the delay to apply to the submitted time.java.lang.LonggetEtaMillis()Returns the specified ETA for a task.java.util.Map<java.lang.String,java.util.List<java.lang.String>>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.TaskOptions.MethodgetMethod()Returns the method used for this task.byte[]getPayload()Returns the live payload for the task, not a copy.RetryOptionsgetRetryOptions()Returns a copy of the retry options for a task.java.util.Map<java.lang.String,java.util.List<java.lang.String>>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.java.lang.StringgetTag()Returns the tag for a task.byte[]getTagAsBytes()Returns the live tag bytes for a task, not a copy.java.lang.StringgetTaskName()Returns the task name.java.lang.StringgetUrl()inthashCode()TaskOptionsheader(java.lang.String headerName, java.lang.String value)Adds a headername/valuepair.TaskOptionsheaders(java.util.Map<java.lang.String,java.lang.String> headers)Replaces the existing headers with the provided headername/valuemapping.TaskOptionsmethod(TaskOptions.Method method)Set the method used for this task.TaskOptionsparam(java.lang.String name, byte[] value)Add a namedbytearray parameter.TaskOptionsparam(java.lang.String name, java.lang.String value)Add a namedStringparameter.TaskOptionspayload(byte[] payload)Sets the payload directly without specifying the content-type.TaskOptionspayload(byte[] payload, java.lang.String contentType)Set the payload with the given content type.TaskOptionspayload(DeferredTask deferredTask)Sets the payload to the serialized form of the deferredTask object.TaskOptionspayload(java.lang.String payload)Set the payload byString.TaskOptionspayload(java.lang.String payload, java.lang.String charset)Sets the payload from aStringgiven a specific character set.TaskOptionsremoveHeader(java.lang.String headerName)Remove all headers with the given name.TaskOptionsremoveParam(java.lang.String paramName)Remove all parameters with the given name.TaskOptionsretryOptions(RetryOptions retryOptions)Sets retry options for this task.TaskOptionstag(byte[] tag)Sets the tag for a task.TaskOptionstag(java.lang.String tag)Sets the tag for a task.TaskOptionstaskName(java.lang.String taskName)Sets the task name.java.lang.StringtoString()TaskOptionsurl(java.lang.String url)Set the URL.
-
-
-
Constructor Detail
-
TaskOptions
public TaskOptions(TaskOptions options)
A copy constructor forTaskOptions.
-
-
Method Detail
-
taskName
public TaskOptions taskName(java.lang.String taskName)
Sets the task name.- Throws:
java.lang.IllegalArgumentException- The provided name is null, empty or doesn't match the regular expressionQueueConstants.TASK_NAME_REGEX
-
getTaskName
public java.lang.String getTaskName()
Returns the task name.
-
getPayload
public byte[] getPayload()
Returns the live payload for the task, not a copy. May benull.
-
payload
public TaskOptions payload(byte[] 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
public TaskOptions payload(DeferredTask deferredTask)
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.Methodis not PULL, the content type will be set toDeferredTaskContext.RUNNABLE_TASK_CONTENT_TYPE, the method will be forced toTaskOptions.Method.POSTand if otherwise not specified, the url will be set toDeferredTaskContext.DEFAULT_DEFERRED_URL; theDeferredTaskservlet 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
public TaskOptions payload(java.lang.String payload, java.lang.String charset)
Sets the payload from aStringgiven a specific character set.- Throws:
UnsupportedTranslationException
-
payload
public TaskOptions payload(byte[] payload, java.lang.String contentType)
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
public TaskOptions payload(java.lang.String 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
public java.util.Map<java.lang.String,java.util.List<java.lang.String>> 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
public TaskOptions headers(java.util.Map<java.lang.String,java.lang.String> headers)
Replaces the existing headers with the provided headername/valuemapping.- Parameters:
headers- The headers to copy.- Returns:
- TaskOptions object for chaining.
-
header
public TaskOptions header(java.lang.String headerName, java.lang.String value)
Adds a headername/valuepair.- Throws:
java.lang.IllegalArgumentException
-
removeHeader
public TaskOptions removeHeader(java.lang.String headerName)
Remove all headers with the given name.
-
getMethod
public TaskOptions.Method getMethod()
Returns the method used for this task.
-
method
public TaskOptions method(TaskOptions.Method method)
Set the method used for this task. Defaults toTaskOptions.Method.POST.
-
getStringParams
public java.util.Map<java.lang.String,java.util.List<java.lang.String>> 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
public java.util.Map<java.lang.String,java.util.List<byte[]>> 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
public TaskOptions clearParams()
Clears the parameters.
-
param
public TaskOptions param(java.lang.String name, java.lang.String value)
Add a namedStringparameter.- 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.valuemust not benull.- Throws:
java.lang.IllegalArgumentException
-
param
public TaskOptions param(java.lang.String name, byte[] value)
Add a namedbytearray 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).valuemust not benull.- Throws:
java.lang.IllegalArgumentException
-
removeParam
public TaskOptions removeParam(java.lang.String paramName)
Remove all parameters with the given name.- Parameters:
paramName- Name of the parameter. Must not be null or empty.
-
getUrl
public java.lang.String getUrl()
-
url
public TaskOptions url(java.lang.String url)
Set the URL.Default value is
null.- Parameters:
url- String containing URL.
-
getCountdownMillis
public java.lang.Long getCountdownMillis()
Returns the delay to apply to the submitted time. May benull.
-
countdownMillis
public TaskOptions countdownMillis(long countdownMillis)
Set the number of milliseconds delay before execution of the task.
-
getEtaMillis
public java.lang.Long getEtaMillis()
Returns the specified ETA for a task. May benullif not specified.
-
etaMillis
public TaskOptions etaMillis(long etaMillis)
Sets the approximate absolute time to execute. (i.e. etaMillis is comparable withSystem.currentTimeMillis()).
-
getRetryOptions
public RetryOptions getRetryOptions()
Returns a copy of the retry options for a task. May benullif not specified.
-
retryOptions
public TaskOptions retryOptions(RetryOptions 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 benullif tag is not specified.
-
getTag
public java.lang.String getTag() throws java.io.UnsupportedEncodingExceptionReturns the tag for a task. May benullif tag is not specified.- Throws:
java.io.UnsupportedEncodingException
-
tag
public TaskOptions tag(byte[] tag)
Sets the tag for a task. Ignores null or zero-length tags.
-
tag
public TaskOptions tag(java.lang.String tag)
Sets the tag for a task. Ignores null or empty tags.
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-