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, 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)
                     throws java.io.IOException
        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.
        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.IOException
        Starts 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:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable