Class RabbitMQJobRunner<T extends adams.multiprocess.Job>

  • All Implemented Interfaces:
    adams.core.CleanUpHandler, adams.core.Destroyable, adams.core.GlobalInfoSupporter, adams.core.logging.LoggingLevelHandler, adams.core.logging.LoggingSupporter, adams.core.option.OptionHandler, adams.core.Pausable, adams.core.QuickInfoSupporter, adams.core.SizeOfHandler, adams.multiprocess.JobRunner<T>, Serializable

    public class RabbitMQJobRunner<T extends adams.multiprocess.Job>
    extends adams.multiprocess.AbstractJobRunner<T>
    JobRunner distributing jobs via a RabbitMQ broker.
    Author:
    FracPete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Detail

      • m_PrefetchCount

        protected int m_PrefetchCount
        the prefetch count.
      • m_Queue

        protected String m_Queue
        the queue in use.
      • m_SendConverter

        protected AbstractConverter m_SendConverter
        the converter for sending.
      • m_ReceiveConverter

        protected AbstractConverter m_ReceiveConverter
        the converter for receiving.
      • m_DistributeJobs

        protected boolean m_DistributeJobs
        whether to distribute the jobs or run them on the same machine.
      • m_Connection

        protected transient com.rabbitmq.client.Connection m_Connection
        the connection.
      • m_Channel

        protected transient com.rabbitmq.client.Channel m_Channel
        the channel action to use.
      • m_JobCompleteListeners

        protected transient HashSet<adams.event.JobCompleteListener> m_JobCompleteListeners
        call when job complete.
      • m_CallbackQueue

        protected String m_CallbackQueue
        the callback queue.
      • m_Jobs

        protected List<T extends adams.multiprocess.Job> m_Jobs
        all the jobs.
      • m_Processing

        protected Set<Integer> m_Processing
        the jobs that are still being processed.
    • Constructor Detail

      • RabbitMQJobRunner

        public RabbitMQJobRunner()
    • Method Detail

      • globalInfo

        public String globalInfo()
        Returns a string describing the object.
        Specified by:
        globalInfo in interface adams.core.GlobalInfoSupporter
        Specified by:
        globalInfo in class adams.core.option.AbstractOptionHandler
        Returns:
        a description suitable for displaying in the gui
      • defineOptions

        public void defineOptions()
        Adds options to the internal list of options.
        Specified by:
        defineOptions in interface adams.core.option.OptionHandler
        Overrides:
        defineOptions in class adams.core.option.AbstractOptionHandler
      • initialize

        protected void initialize()
        Initializes the members.
        Overrides:
        initialize in class adams.multiprocess.AbstractJobRunner<T extends adams.multiprocess.Job>
      • setConnectionFactory

        public void setConnectionFactory​(AbstractConnectionFactory value)
        Sets the base connection factory to encrypt.
        Parameters:
        value - the factory
      • getConnectionFactory

        public AbstractConnectionFactory getConnectionFactory()
        Returns the base connection factory to encrypt.
        Returns:
        the factory
      • connectionFactoryTipText

        public String connectionFactoryTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setPrefetchCount

        public void setPrefetchCount​(int value)
        Sets the maximum number of unacked jobs a client can pull off a queue.
        Parameters:
        value - the count, 0 = unlimited, 1 = fair
      • getPrefetchCount

        public int getPrefetchCount()
        Returns the maximum number of unacked jobs a client can pull off a queue.
        Returns:
        the count, 0 = unlimited, 1 = fair
      • prefetchCountTipText

        public String prefetchCountTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setQueue

        public void setQueue​(String value)
        Sets the name of the queue.
        Parameters:
        value - the name
      • getQueue

        public String getQueue()
        Returns the name of the queue.
        Returns:
        the name
      • queueTipText

        public String queueTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setSendConverter

        public void setSendConverter​(AbstractConverter value)
        Sets the converter to use for sending.
        Parameters:
        value - the converter
      • getSendConverter

        public AbstractConverter getSendConverter()
        Returns the converter to use for sending.
        Returns:
        the converter
      • sendConverterTipText

        public String sendConverterTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setReceiveConverter

        public void setReceiveConverter​(AbstractConverter value)
        Sets the converter to use for receiving.
        Parameters:
        value - the converter
      • getReceiveConverter

        public AbstractConverter getReceiveConverter()
        Returns the converter to use for receiving.
        Returns:
        the converter
      • receiveConverterTipText

        public String receiveConverterTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setDistributeJobs

        public void setDistributeJobs​(boolean value)
        Sets whether to distribute the jobs via separate messages.
        Parameters:
        value - true if to distribute
      • getDistributeJobs

        public boolean getDistributeJobs()
        Returns whether to distribute the jobs via separate messages.
        Returns:
        true if to distribute
      • distributeJobsTipText

        public String distributeJobsTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • getQuickInfo

        public String getQuickInfo()
        Returns a quick info about the object, which can be displayed in the GUI.
        Returns:
        null if no info available, otherwise short string
      • retrieveConnection

        protected com.rabbitmq.client.Connection retrieveConnection()
        Returns the database connection in use. Reconnects the database, to make sure that the database connection is the correct one.
        Returns:
        the connection object
      • preStart

        protected String preStart()
        Before actual start up.
        Overrides:
        preStart in class adams.multiprocess.AbstractJobRunner<T extends adams.multiprocess.Job>
        Returns:
        null if successful, otherwise error message
      • doStart

        protected String doStart()
        Performing actual start up. Only gets executed if preStart() was successful.
        Specified by:
        doStart in class adams.multiprocess.AbstractJobRunner<T extends adams.multiprocess.Job>
        Returns:
        null if successful, otherwise error message
        See Also:
        preStart()
      • purgeQueue

        protected String purgeQueue()
        Purges the job queue.
        Returns:
        null if successful or no channel available, otherwise error message
      • deleteCallbackQueue

        protected String deleteCallbackQueue()
        Deletes the callback queue.
        Returns:
        null if successful or no channel available, otherwise error message
      • close

        protected void close()
        Closes the channel and connection.
      • doStop

        protected String doStop()
        Performing actual stop.
        Specified by:
        doStop in class adams.multiprocess.AbstractJobRunner<T extends adams.multiprocess.Job>
        Returns:
        null if successful, otherwise error message
      • doTerminate

        protected String doTerminate​(boolean wait)
        Performing actual terminate up.
        Specified by:
        doTerminate in class adams.multiprocess.AbstractJobRunner<T extends adams.multiprocess.Job>
        Parameters:
        wait - ignored
        Returns:
        null if successful, otherwise error message
      • addJobCompleteListener

        public void addJobCompleteListener​(adams.event.JobCompleteListener l)
        Adds the listener.
        Parameters:
        l - the listener to add
      • removeJobCompleteListener

        public void removeJobCompleteListener​(adams.event.JobCompleteListener l)
        Removes the listener.
        Parameters:
        l - the listener to remove
      • notifyJobCompleteListeners

        protected void notifyJobCompleteListeners​(adams.event.JobCompleteEvent e)
        Notifies all listeners with the given event.
        Parameters:
        e - the event to send to the listeners
      • clear

        public void clear()
        Clears all jobs.
      • add

        public void add​(T job)
        Adds the job to the execution queue.
        Parameters:
        job - the job to add
      • add

        public void add​(adams.multiprocess.JobList<T> jobs)
        Adds the jobs to the execution queue.
        Parameters:
        jobs - the jobs to add
      • getJobs

        public List<T> getJobs()
        Returns the list of queued jobs.
        Returns:
        the jobs
      • complete

        public void complete​(T j,
                             adams.multiprocess.JobResult jr)
        Job is complete, so check for more to add..
        Parameters:
        j - job
        jr - job result