Package io.littlehorse.sdk.worker
Class LHTaskWorker
- java.lang.Object
-
- io.littlehorse.sdk.worker.LHTaskWorker
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class LHTaskWorker extends java.lang.Object implements java.io.CloseableThe LHTaskWorker talks to the LH Servers and executes a specified Task Method every time a Task is scheduled.
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.HashMap<java.lang.Class<?>,io.littlehorse.sdk.common.proto.VariableTypePb>javaTypeToLHType
-
Constructor Summary
Constructors Constructor Description LHTaskWorker(java.lang.Object executable, java.lang.String taskDefName, LHWorkerConfig config)Creates an LHTaskWorker given an Object that has an annotated LHTaskMethod, and a configuration Properties object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Cleanly shuts down the Task Worker.booleandoesTaskDefExist()Checks if the TaskDef existsjava.lang.StringgetTaskDefName()`TaskDef` to executevoidregisterTaskDef()Deploys the TaskDef object to the LH Server.voidregisterTaskDef(boolean swallowAlreadyExists)Deploys the TaskDef object to the LH Server.voidstart()Starts polling for and executing tasks.
-
-
-
Constructor Detail
-
LHTaskWorker
public LHTaskWorker(java.lang.Object executable, java.lang.String taskDefName, LHWorkerConfig config)Creates an LHTaskWorker given an Object that has an annotated LHTaskMethod, and a configuration Properties object.- Parameters:
executable- is any Object which has exactly one method annotated with '@LHTaskMethod'. That method will be used to execute the tasks.taskDefName- is the name of the `TaskDef` to execute.config- is a valid LHWorkerConfig.
-
-
Method Detail
-
getTaskDefName
public java.lang.String getTaskDefName()
`TaskDef` to execute- Returns:
- the name of the `TaskDef` to execute
-
doesTaskDefExist
public boolean doesTaskDefExist() throws io.littlehorse.sdk.common.exception.LHApiErrorChecks if the TaskDef exists- Returns:
- true if the task is registered or false otherwise
- Throws:
io.littlehorse.sdk.common.exception.LHApiError- if the call fails.
-
registerTaskDef
public void registerTaskDef() throws io.littlehorse.sdk.common.exception.LHApiErrorDeploys the TaskDef object to the LH Server. This is a convenience method, generally not recommended for production (in production you should manually use the PutTaskDef).- Throws:
io.littlehorse.sdk.common.exception.LHApiError- if the call fails.
-
registerTaskDef
public void registerTaskDef(boolean swallowAlreadyExists) throws io.littlehorse.sdk.common.exception.LHApiErrorDeploys the TaskDef object to the LH Server. This is a convenience method, generally not recommended for production (in production you should manually use the PutTaskDef).- Parameters:
swallowAlreadyExists- if true, then ignore ALREADY_EXISTS_ERROR when registering the TaskDef.- Throws:
io.littlehorse.sdk.common.exception.LHApiError- if the call fails.
-
start
public void start() throws io.littlehorse.sdk.common.exception.LHApiErrorStarts polling for and executing tasks.- Throws:
io.littlehorse.sdk.common.exception.LHApiError- if the schema from the TaskDef configured in the configProps is incompatible with the method signature from the provided executable Java object, or if the Worker cannot connect to the LH Server.
-
close
public void close()
Cleanly shuts down the Task Worker.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
-