Class GearmanWorkerImpl

    • Constructor Detail

      • GearmanWorkerImpl

        public GearmanWorkerImpl()
      • GearmanWorkerImpl

        public GearmanWorkerImpl​(ExecutorService executorService)
    • Method Detail

      • work

        public void work()
        Description copied from interface: GearmanWorker
        This method is executed once the worker is ready to accept jobs from the Gearman Job Server. It should be called after all the GearmanJobServerConnection have been added to the worker and all the applicable GearmanFunction have been registered with the worker. After this method is executed, the Worker should be capable of receiving jobs from the Gearman Job Server and executing thus jobs.
        Specified by:
        work in interface GearmanWorker
      • addServer

        public boolean addServer​(String host,
                                 int port)
      • hasServer

        public boolean hasServer​(GearmanJobServerConnection conn)
        Description copied from interface: GearmanWorker
        Has a connection to the specified Gearman Job Server been registered with this worker.
        Specified by:
        hasServer in interface GearmanWorker
        Parameters:
        conn - The connection to the specified Gearman Job Server.
        Returns:
        True if the Gearman Job Server has been registered with the worker, otherwise false.
      • echo

        public String echo​(String text,
                           GearmanJobServerConnection conn)
        Description copied from interface: GearmanWorker
        Send an echo request to the specified GearmanJobServerConnection, the Gearman Job Server should echo the contents of the echo request back to the Worker. This is can be used to verify the connection between a Worker and a Server.
        Specified by:
        echo in interface GearmanWorker
        Parameters:
        text - the text to include in the echo request.
        conn - A connection to Gearman Job Server to which the request should be sent.
        Returns:
        a string which should be equal to text sent to the server.
      • registerFunction

        public void registerFunction​(String function,
                                     long timeout)
      • registerFunction

        public void registerFunction​(String function)
      • registerFunction

        public void registerFunction​(Class<? extends GearmanFunction> function)
        Description copied from interface: GearmanWorker
        Registers a particular GearmanFunction with the worker. Once a function has been registered with a worker, the worker is capable of executing any GearmanJob that matches the registered function. Upon registering a function, the Worker notifies all Gearman Job Servers that is can accept any job that contains the applicable function.
        Specified by:
        registerFunction in interface GearmanWorker
        Parameters:
        function - The function being registered with the Worker.
      • registerFunction

        public void registerFunction​(Class<? extends GearmanFunction> function,
                                     long timeout)
        Description copied from interface: GearmanWorker
        Registers a particular GearmanFunction with the worker. Once a function has been registered with a worker, the worker is capable of executing any GearmanJob that matches the registered function. Upon registering a function, the Worker notifies all Gearman Job Servers that it can accept any job that contains the applicable function.
        Specified by:
        registerFunction in interface GearmanWorker
        Parameters:
        function - The function being registered with the Worker.
        timeout - The amount of time the Worker will allow a job to execute the particular function. If the execution of the function exceeds the timeout value, the job will be marked as failed.
      • registerFunctionFactory

        public void registerFunctionFactory​(GearmanFunctionFactory factory,
                                            long timeout)
        Description copied from interface: GearmanWorker
        Registers a GearmanFunctionFactory with the worker and specifies the timeout associated with any functions generated by this factory.
        Specified by:
        registerFunctionFactory in interface GearmanWorker
        Parameters:
        factory - A function factory is factory that the worker will use to create the instance of a function when the worker needs a function of the type specified by the factory.
        timeout - The amount of time the Worker will allow a job to execute the particular function. If the execution of the function exceeds the timeout value, the job will be marked as failed.
      • getRegisteredFunctions

        public Set<String> getRegisteredFunctions()
        Description copied from interface: GearmanWorker
        Retrieve the names of all functions that have been registered with this worker. If no functions have been registered, any empty set should be returned.
        Specified by:
        getRegisteredFunctions in interface GearmanWorker
        Returns:
        The name of all registered functions.
      • setWorkerID

        public void setWorkerID​(String id,
                                GearmanJobServerConnection conn)
        Description copied from interface: GearmanWorker
        Set the ID used by a particular Gearman Job Server to identify a particular Worker. This enables monitoring and reporting commands to uniquely identify specific workers.
        Specified by:
        setWorkerID in interface GearmanWorker
        Parameters:
        id - The ID.
        conn - The Gearman Job Server to which this worker ID applies.
      • unregisterFunction

        public void unregisterFunction​(String functionName)
        Description copied from interface: GearmanWorker
        Unregisters a particular GearmanFunction from the worker. Once a function has been unregistered from the Worker, a Worker will no longer accept jobs which require the execution of the unregistered function.
        Specified by:
        unregisterFunction in interface GearmanWorker
      • unregisterAll

        public void unregisterAll()
        Description copied from interface: GearmanWorker
        Unregisters allGearmanFunction from the worker. The effect of which is that the worker will not execute any new jobs.
        Specified by:
        unregisterAll in interface GearmanWorker
      • stop

        public void stop()
        Description copied from interface: GearmanWorker
        Stops the work loop and requests a shutdown.
        Specified by:
        stop in interface GearmanWorker
      • shutdown

        public List<Exception> shutdown()
        Description copied from interface: GearmanWorker
        Stops the work loop and closes all open connections.
        Specified by:
        shutdown in interface GearmanWorker
        Returns:
        a List of any Exceptions thrown when closing connections
      • isRunning

        public boolean isRunning()
        Description copied from interface: GearmanWorker
        Determine if the worker is currently executing the work loop.
        Specified by:
        isRunning in interface GearmanWorker
        Returns:
        True if the work loop is executing, else false.
      • setJobUniqueIdRequired

        public void setJobUniqueIdRequired​(boolean requiresJobUUID)
        Description copied from interface: GearmanWorker
        Should worker only ask for jobs which contain a Unique Id.
        Specified by:
        setJobUniqueIdRequired in interface GearmanWorker
        Parameters:
        requiresJobUUID - True if should worker only ask for jobs which contain a Unique Id.
      • isJobUniqueIdRequired

        public boolean isJobUniqueIdRequired()
        Description copied from interface: GearmanWorker
        Does worker only ask for jobs which contain a Unique Id.
        Specified by:
        isJobUniqueIdRequired in interface GearmanWorker
        Returns:
        true if worker only asks for jobs which contain a Unique Id, else false.