public class ZkTaskQueue
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_SUB_QUEUE
use this as a default for identifying the right (sub) queue if no property is given in the task.
|
static java.lang.String |
DELIVERY_PREFIX
zk path for delayed task delivery data.
|
static java.lang.String |
INPROGRESSDIR_SUFFIX
prefix for task-in-progress directories.
|
static java.lang.String |
OWNER_PROP
Property identifying owner of this task.
|
static java.lang.String |
ROOT_DIR_PREFIX
prefix for task directories.
|
static java.lang.String |
SECTION_INPROGRESS
Property for task-in-progress.
|
static java.lang.String |
SECTION_TODO
Property for tasks-todo.
|
static java.lang.String |
SECTION_TODOQUALIFIED
Property for qualified-tasks-todo.
|
static java.lang.String |
TASKDIR_PREFIX
prefix for task directories.
|
static java.lang.String |
TODODIR_SUFFIX
prefix for tasks-todo directories.
|
static java.lang.String |
TODOQUALIFIEDDIR_SUFFIX
prefix for qualified-tasks-todo directories.
|
Constructor and Description |
---|
ZkTaskQueue(ZooKeeperService service,
java.lang.String workerName,
java.lang.String localhost) |
ZkTaskQueue(ZooKeeperService service,
java.lang.String workerName,
java.lang.String localhost,
long maxNoOfTasksPerHost) |
Modifier and Type | Method and Description |
---|---|
void |
cleanEmptyNodes(long timeToLiveMs)
Remove
empty task nodes in the todo(_qualified) directories (leftovers from failed create operations)
empty todo_qualified directories that seem not to be in use anymore.
|
void |
delete(java.lang.String taskId)
Deletes the given task from the inprogress section.
|
void |
disconnectZkSession()
for testing only!
|
java.util.List<Task> |
filterDuplicates(java.util.List<Task> tasks)
return new list of tasks with only those tasks from the given task list
that do not have property
Task.PROPERTY_UNIQUENESS_TAG set or
for which currently no task is in the Todo queue that has the same uniqueness tag. |
Task |
get(java.util.Collection<java.lang.String> qualifiers,
java.lang.String host)
Return next task that can be processed.
|
Task |
getInProgressTask(java.lang.String taskId)
read the task content of an in-progress task.
|
long |
getMaxNoOfTasksPerHost() |
TaskCounter |
getTaskCounter() |
AnyMap |
getTaskInfo(java.lang.String section,
java.lang.String taskName)
Prepares information on a task stored in the task storage.
|
TaskList |
getTaskList(java.lang.String section,
int maxCount)
Get task list for current task pipe and sub-type.
|
java.util.Collection<java.lang.String> |
getTimedOutTasks(long timeToLiveMs) |
java.lang.String |
getWorkerName()
return worker name.
|
boolean |
hasQualifiedTasks() |
void |
keepAlive(java.lang.String taskId)
Process isAlive call for given task.
|
void |
purge()
Remove all task (and todo sub queue) nodes.
|
void |
put(Task task)
Puts a task in our task pipe.
|
java.lang.String |
putInProgress(Task task)
write task to in-progress section of the queue.
|
void |
removeTasks(AnyMap filterMap)
Remove canceled tasks identified by the filter map.
|
void |
setMaxNoOfTasksPerHost(long maxNoOfTasksPerHost)
set new scale-up limit.
|
public static final java.lang.String ROOT_DIR_PREFIX
public static final java.lang.String TASKDIR_PREFIX
public static final java.lang.String TODODIR_SUFFIX
public static final java.lang.String TODOQUALIFIEDDIR_SUFFIX
public static final java.lang.String INPROGRESSDIR_SUFFIX
public static final java.lang.String DELIVERY_PREFIX
public static final java.lang.String OWNER_PROP
public static final java.lang.String SECTION_TODO
public static final java.lang.String SECTION_TODOQUALIFIED
public static final java.lang.String SECTION_INPROGRESS
public static final java.lang.String DEFAULT_SUB_QUEUE
public ZkTaskQueue(ZooKeeperService service, java.lang.String workerName, java.lang.String localhost)
service
- zookeeper service needed to get zookeeper clientworkerName
- name of worker for which we are managing taskslocalhost
- local host namepublic ZkTaskQueue(ZooKeeperService service, java.lang.String workerName, java.lang.String localhost, long maxNoOfTasksPerHost)
service
- zookeeper service needed to get zookeeper clientworkerName
- name of worker for which we are managing taskslocalhost
- local host namemaxNoOfTasksPerHost
- public void disconnectZkSession() throws TaskmanagerException
TaskmanagerException
public long getMaxNoOfTasksPerHost()
public void setMaxNoOfTasksPerHost(long maxNoOfTasksPerHost)
public java.lang.String getWorkerName()
public void put(Task task) throws TaskmanagerException
task
- the taskTaskmanagerException
- errorpublic java.lang.String putInProgress(Task task) throws TaskmanagerException
task
- taskOWNER_PROP
property.TaskmanagerException
public Task get(java.util.Collection<java.lang.String> qualifiers, java.lang.String host) throws TaskmanagerException
qualifiers
- optional task qualifiershost
- host name where the worker is running that requested the task, to be stored as property in the taskTaskmanagerException
- errorpublic Task getInProgressTask(java.lang.String taskId) throws TaskmanagerException
taskId
- task IdTaskmanagerException
- if task is not in-progress or other errors.public void delete(java.lang.String taskId) throws TaskmanagerException
taskId
- identifies the taskTaskmanagerException
- error; BadParameterTaskmanagerException if taskId isn't foundpublic void keepAlive(java.lang.String taskId) throws TaskmanagerException
taskId
- identifies the taskTaskmanagerException
- error; BadParameterTaskmanagerException if taskId isn't foundpublic boolean hasQualifiedTasks() throws KeeperException
KeeperException
public TaskCounter getTaskCounter() throws TaskmanagerException
TaskmanagerException
- errorpublic java.util.Collection<java.lang.String> getTimedOutTasks(long timeToLiveMs)
timeToLiveMs
- the maximum processing timepublic void purge()
public void cleanEmptyNodes(long timeToLiveMs)
timeToLiveMs
- time in milliseconds after which to clean up stale tasks or empty todo_qualified dirs.public TaskList getTaskList(java.lang.String section, int maxCount) throws TaskmanagerException
section
- task pipe sub-type: "inprogress" or "todo".maxCount
- max. number of tasks in return listTaskmanagerException
- errorpublic AnyMap getTaskInfo(java.lang.String section, java.lang.String taskName) throws TaskmanagerException
section
- queue section ("todo" or "inprogress")taskName
- task identifierTaskmanagerException
- on errorpublic void removeTasks(AnyMap filterMap)
filterMap
- map to identify tasks to be removedpublic java.util.List<Task> filterDuplicates(java.util.List<Task> tasks) throws TaskmanagerException
Task.PROPERTY_UNIQUENESS_TAG
set or
tasks
- to filter for this task queueTaskmanagerException