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.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
      void close()
      Cleanly shuts down the Task Worker.
      boolean doesTaskDefExist()
      Checks if the TaskDef exists
      java.lang.String getTaskDefName()
      `TaskDef` to execute
      void registerTaskDef()
      Deploys the TaskDef object to the LH Server.
      void registerTaskDef​(boolean swallowAlreadyExists)
      Deploys the TaskDef object to the LH Server.
      void start()
      Starts polling for and executing tasks.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • javaTypeToLHType

        public static java.util.HashMap<java.lang.Class<?>,​io.littlehorse.sdk.common.proto.VariableTypePb> javaTypeToLHType
    • 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.LHApiError
        Checks 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.LHApiError
        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).
        Throws:
        io.littlehorse.sdk.common.exception.LHApiError - if the call fails.
      • registerTaskDef

        public void registerTaskDef​(boolean swallowAlreadyExists)
                             throws io.littlehorse.sdk.common.exception.LHApiError
        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 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.LHApiError
        Starts 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:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable