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.VariableType>javaTypeToLHType
-
Constructor Summary
Constructors Constructor Description LHTaskWorker(java.lang.Object executable, java.lang.String taskDefName, LHConfig config)Creates an LHTaskWorker given an Object that has an annotated LHTaskMethod, and a configuration Properties object.LHTaskWorker(java.lang.Object executable, java.lang.String taskDefName, LHConfig config, io.littlehorse.sdk.worker.internal.LHServerConnectionManager manager)
-
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 executeLHTaskWorkerHealthhealthStatus()voidregisterTaskDef()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, LHConfig config) throws java.io.IOExceptionCreates 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 LHConfig.- Throws:
java.io.IOException
-
LHTaskWorker
public LHTaskWorker(java.lang.Object executable, java.lang.String taskDefName, LHConfig config, io.littlehorse.sdk.worker.internal.LHServerConnectionManager manager) throws java.io.IOException- Throws:
java.io.IOException
-
-
Method Detail
-
getTaskDefName
public java.lang.String getTaskDefName()
`TaskDef` to execute- Returns:
- the name of the `TaskDef` to execute
-
doesTaskDefExist
public boolean doesTaskDefExist()
Checks if the TaskDef exists- Returns:
- true if the task is registered or false otherwise
-
registerTaskDef
public void registerTaskDef()
Deploys 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).
-
registerTaskDef
public void registerTaskDef(boolean swallowAlreadyExists)
Deploys 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 grpc ALREADY_EXISTS error when registering the TaskDef.
-
start
public void start() throws java.io.IOExceptionStarts polling for and executing tasks.- Throws:
java.io.IOException- if unexpected error occurs opening connections.
-
close
public void close()
Cleanly shuts down the Task Worker.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
healthStatus
public LHTaskWorkerHealth healthStatus()
-
-