org.apache.synapse.commons.executors

## Class PriorityExecutor

- java.lang.Object
- - org.apache.synapse.commons.executors.PriorityExecutor

-     public class PriorityExecutor
      extends Object

  This is the class used for executing the tasks with a given priority. It is backed by a BlockingQueue and a ThreadPoolExecutor. The BlockingQueue is a custom implementation which has multiple internal queues for handling separate priorities.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `PriorityExecutor()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `destroy()` Destroy the executor.
    `void` | `execute(Runnable task, int priority)` Execute a given task with the priority specified.
    `BeforeExecuteHandler` | `getBeforeExecuteHandler()` Get the handler that is executed before the worker is put in to the queue
    `int` | `getCore()` Get the core number of threads
    `String` | `getFileName()` Get the file used to store this executor config
    `int` | `getKeepAlive()` Get the keep alive time for threads
    `int` | `getMax()` Get the max threads
    `String` | `getName()` Get the name of the executor
    `MultiPriorityBlockingQueue<Runnable>` | `getQueue()` Get the queue.
    `void` | `init()` Initialize the executor by using the properties.
    `void` | `setBeforeExecuteHandler(BeforeExecuteHandler beforeExecuteHandler)` Set a handler for execute before putting a worker in to the queues.
    `void` | `setCore(int core)` Set the core number of threads
    `void` | `setFileName(String fileName)` Set the file used to store the config
    `void` | `setKeepAlive(int keepAlive)` Set the keep alive time for threads
    `void` | `setMax(int max)` Set the max number of threads
    `void` | `setName(String name)` Set the name of the executor
    `void` | `setQueue(MultiPriorityBlockingQueue<Runnable> queue)` Set the queue.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### PriorityExecutor

          public PriorityExecutor()

  - ### Method Detail

    - #### execute

          public void execute(Runnable task,
                              int priority)

      Execute a given task with the priority specified. If the task throws an exception, it will be captured and logged to prevent the threads from dying.
      Parameters:
        `task` - task to be executed
        `priority` - priority of the task

    - #### init

          public void init()

      Initialize the executor by using the properties. Create the queues and ThreadPool executor.

    - #### destroy

          public void destroy()

      Destroy the executor. Stop all the threads running.

    - #### setName

          public void setName(String name)

      Set the name of the executor
      Parameters:
        `name` - of the executor

    - #### getName

          public String getName()

      Get the name of the executor
      Returns:
        name of the executor

    - #### setBeforeExecuteHandler

          public void setBeforeExecuteHandler(BeforeExecuteHandler beforeExecuteHandler)

      Set a handler for execute before putting a worker in to the queues. User can set some properties to the worker at this point. This allows users to get more control over the queue selection algorithm. This is an optional configuration.
      Parameters:
        `beforeExecuteHandler` - an object implementing the BeforeExecuteHandler

    - #### getBeforeExecuteHandler

          public BeforeExecuteHandler getBeforeExecuteHandler()

      Get the handler that is executed before the worker is put in to the queue
      Returns:
        an object of BeforeExecuteHandler

    - #### setQueue

          public void setQueue(MultiPriorityBlockingQueue<Runnable> queue)

      Set the queue.
      Parameters:
        `queue` - queue used for handling the priorities

    - #### getQueue

          public MultiPriorityBlockingQueue<Runnable> getQueue()

      Get the queue.
      Returns:
        queue used for handling multiple priorities

    - #### getCore

          public int getCore()

      Get the core number of threads
      Returns:
        core number of threads

    - #### getMax

          public int getMax()

      Get the max threads
      Returns:
        max thread

    - #### getKeepAlive

          public int getKeepAlive()

      Get the keep alive time for threads
      Returns:
        keep alive time for threads

    - #### setCore

          public void setCore(int core)

      Set the core number of threads
      Parameters:
        `core` - core number of threads

    - #### setMax

          public void setMax(int max)

      Set the max number of threads
      Parameters:
        `max` - max threads

    - #### setKeepAlive

          public void setKeepAlive(int keepAlive)

      Set the keep alive time for threads
      Parameters:
        `keepAlive` - keep alive threads

    - #### getFileName

          public String getFileName()

      Get the file used to store this executor config
      Returns:
        file used for storing the config

    - #### setFileName

          public void setFileName(String fileName)

      Set the file used to store the config
      Parameters:
        `fileName` - file name

Copyright © 2005–2018 Apache Software Foundation. All rights reserved.