Class LHTaskWorker

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class LHTaskWorker
    extends java.lang.Object
    implements java.io.Closeable
    The 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, java.util.Map<java.lang.String,​java.lang.String> valuesForPlaceholders)
      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, java.util.Map<java.lang.String,​java.lang.String> valuesForPlaceHolders, LHConfig config, io.littlehorse.sdk.worker.internal.LHServerConnectionManager manager)  
    • Field Detail

      • javaTypeToLHType

        public static java.util.HashMap<java.lang.Class<?>,​io.littlehorse.sdk.common.proto.VariableType> javaTypeToLHType
    • Constructor Detail

      • LHTaskWorker

        public 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.
        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.
      • LHTaskWorker

        public LHTaskWorker​(java.lang.Object executable,
                            java.lang.String taskDefName,
                            LHConfig config,
                            java.util.Map<java.lang.String,​java.lang.String> valuesForPlaceholders)
        Creates an LHTaskWorker given an Object that has an annotated LHTaskMethod, and a configuration Properties object. You can have placeholders in the taskDefName in the form of: a-task-name-${PLACEHOLDER_1}-${PLACEHOLDER-2}. Each placeholder should be replaced by its corresponding value coming from the valuesForPlaceHolders map. PLACEHOLDER_1: VALUE_1 PLACEHOLDER_2: VALUE_2 So after the values are replaced, you will have a taskDefName like: a-task-name-VALUE_1-VALUE_2
        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.
        valuesForPlaceholders - map of values that will replace the placeholders on the taskDefName
      • LHTaskWorker

        public LHTaskWorker​(java.lang.Object executable,
                            java.lang.String taskDefName,
                            java.util.Map<java.lang.String,​java.lang.String> valuesForPlaceHolders,
                            LHConfig config,
                            io.littlehorse.sdk.worker.internal.LHServerConnectionManager manager)
    • 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).
      • start

        public void start()
        Starts polling for and executing tasks.
      • close

        public void close()
        Cleanly shuts down the Task Worker.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable