Package adams.multiprocess
Class RabbitMQJobRunner<T extends adams.multiprocess.Job>
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- adams.multiprocess.AbstractJobRunner<T>
-
- adams.multiprocess.RabbitMQJobRunner<T>
-
- 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 Summary
Fields Modifier and Type Field Description protected String
m_CallbackQueue
the callback queue.protected com.rabbitmq.client.Channel
m_Channel
the channel action to use.protected com.rabbitmq.client.Connection
m_Connection
the connection.protected AbstractConnectionFactory
m_ConnectionFactory
the connection to use.protected boolean
m_DistributeJobs
whether to distribute the jobs or run them on the same machine.protected HashSet<adams.event.JobCompleteListener>
m_JobCompleteListeners
call when job complete.protected List<T>
m_Jobs
all the jobs.protected int
m_PrefetchCount
the prefetch count.protected Set<Integer>
m_Processing
the jobs that are still being processed.protected String
m_Queue
the queue in use.protected AbstractConverter
m_ReceiveConverter
the converter for receiving.protected AbstractConverter
m_SendConverter
the converter for sending.
-
Constructor Summary
Constructors Constructor Description RabbitMQJobRunner()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(adams.multiprocess.JobList<T> jobs)
Adds the jobs to the execution queue.void
add(T job)
Adds the job to the execution queue.void
addJobCompleteListener(adams.event.JobCompleteListener l)
Adds the listener.void
clear()
Clears all jobs.protected void
close()
Closes the channel and connection.void
complete(T j, adams.multiprocess.JobResult jr)
Job is complete, so check for more to add..String
connectionFactoryTipText()
Returns the tip text for this property.void
defineOptions()
Adds options to the internal list of options.protected String
deleteCallbackQueue()
Deletes the callback queue.String
distributeJobsTipText()
Returns the tip text for this property.protected String
doStart()
Performing actual start up.protected String
doStop()
Performing actual stop.protected String
doTerminate(boolean wait)
Performing actual terminate up.AbstractConnectionFactory
getConnectionFactory()
Returns the base connection factory to encrypt.boolean
getDistributeJobs()
Returns whether to distribute the jobs via separate messages.List<T>
getJobs()
Returns the list of queued jobs.int
getPrefetchCount()
Returns the maximum number of unacked jobs a client can pull off a queue.String
getQueue()
Returns the name of the queue.String
getQuickInfo()
Returns a quick info about the object, which can be displayed in the GUI.AbstractConverter
getReceiveConverter()
Returns the converter to use for receiving.AbstractConverter
getSendConverter()
Returns the converter to use for sending.String
globalInfo()
Returns a string describing the object.protected void
initialize()
Initializes the members.protected void
notifyJobCompleteListeners(adams.event.JobCompleteEvent e)
Notifies all listeners with the given event.String
prefetchCountTipText()
Returns the tip text for this property.protected String
preStart()
Before actual start up.protected String
purgeQueue()
Purges the job queue.String
queueTipText()
Returns the tip text for this property.String
receiveConverterTipText()
Returns the tip text for this property.void
removeJobCompleteListener(adams.event.JobCompleteListener l)
Removes the listener.protected com.rabbitmq.client.Connection
retrieveConnection()
Returns the database connection in use.String
sendConverterTipText()
Returns the tip text for this property.void
setConnectionFactory(AbstractConnectionFactory value)
Sets the base connection factory to encrypt.void
setDistributeJobs(boolean value)
Sets whether to distribute the jobs via separate messages.void
setPrefetchCount(int value)
Sets the maximum number of unacked jobs a client can pull off a queue.void
setQueue(String value)
Sets the name of the queue.void
setReceiveConverter(AbstractConverter value)
Sets the converter to use for receiving.void
setSendConverter(AbstractConverter value)
Sets the converter to use for sending.-
Methods inherited from class adams.multiprocess.AbstractJobRunner
cleanUp, getFlowContext, isPaused, isRunning, pauseExecution, postStart, postStop, postTerminate, preStop, preTerminate, resumeExecution, setFlowContext, start, stop, terminate, terminate
-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, destroy, finishInit, getDefaultLoggingLevel, getOptionManager, loggingLevelTipText, newOptionManager, reset, setLoggingLevel, toCommandLine, toString
-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
-
-
-
Field Detail
-
m_ConnectionFactory
protected AbstractConnectionFactory m_ConnectionFactory
the connection to use.
-
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.
-
-
Method Detail
-
globalInfo
public String globalInfo()
Returns a string describing the object.- Specified by:
globalInfo
in interfaceadams.core.GlobalInfoSupporter
- Specified by:
globalInfo
in classadams.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 interfaceadams.core.option.OptionHandler
- Overrides:
defineOptions
in classadams.core.option.AbstractOptionHandler
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initialize
in classadams.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 classadams.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 ifpreStart()
was successful.- Specified by:
doStart
in classadams.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 classadams.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 classadams.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
-
complete
public void complete(T j, adams.multiprocess.JobResult jr)
Job is complete, so check for more to add..- Parameters:
j
- jobjr
- job result
-
-