Package com.github.ddth.queue.impl
Class ActiveMqQueue<ID,DATA>
- java.lang.Object
-
- com.github.ddth.queue.impl.AbstractQueue<ID,DATA>
-
- com.github.ddth.queue.impl.ActiveMqQueue<ID,DATA>
-
- All Implemented Interfaces:
IQueue<ID,DATA>
,AutoCloseable
- Direct Known Subclasses:
BaseUniversalActiveMqQueue
public abstract class ActiveMqQueue<ID,DATA> extends AbstractQueue<ID,DATA>
(Experimental) ActiveMQ implementation ofIQueue
.- Queue-size support: no
- Ephemeral storage support: no
- Since:
- 0.6.1
- Author:
- Thanh Ba Nguyen
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.github.ddth.queue.impl.AbstractQueue
AbstractQueue.PutToQueueCase
-
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_QUEUE_NAME
static String
DEFAULT_URI
-
Fields inherited from interface com.github.ddth.queue.IQueue
SIZE_NOT_SUPPORTED
-
-
Constructor Summary
Constructors Constructor Description ActiveMqQueue()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected org.apache.activemq.ActiveMQConnectionFactory
buildConnectionFactory()
protected void
closeQuietly(javax.jms.Connection connection)
protected void
closeQuietly(javax.jms.MessageConsumer consumer)
protected void
closeQuietly(javax.jms.MessageProducer producer)
protected void
closeQuietly(javax.jms.Session session)
protected javax.jms.Session
createSession(int acknowledgeMode)
void
destroy()
Destroy method.protected boolean
doPutToQueue(IQueueMessage<ID,DATA> msg, AbstractQueue.PutToQueueCase queueCase)
Put a message to the queue storage.int
ephemeralSize()
Get number of items currently in ephemeral storage.void
finish(IQueueMessage<ID,DATA> msg)
Called when finish processing the message to cleanup ephemeral storage.protected javax.jms.Connection
getConnection()
protected org.apache.activemq.ActiveMQConnectionFactory
getConnectionFactory()
Getter forconnectionFactory
.protected javax.jms.Session
getConsumerSession()
Get theSession
dedicated for consuming messages.protected javax.jms.MessageConsumer
getMessageConsumer()
protected javax.jms.MessageProducer
getMessageProducer()
Collection<IQueueMessage<ID,DATA>>
getOrphanMessages(long thresholdTimestampMs)
Get all orphan messages (messages that were left in ephemeral storage for a long time).String
getPassword()
Password to connect to ActiveMQ server.protected javax.jms.Session
getProducerSession()
Get theSession
dedicated for sending messages.String
getQueueName()
Name of ActiveMQ queue to send/receive messages.String
getUri()
ActiveMQ's connection URI (see http://activemq.apache.org/connection-configuration-uri.html).String
getUsername()
Username to connect to ActiveMQ server.ActiveMqQueue<ID,DATA>
init()
Init method.int
queueSize()
Get number of items currently in queue storage.ActiveMqQueue<ID,DATA>
setConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory connectionFactory)
Setter forconnectionFactory
.protected ActiveMqQueue<ID,DATA>
setConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory connectionFactory, boolean setMyOwnConnectionFactory)
Setter forconnectionFactory
.ActiveMqQueue<ID,DATA>
setPassword(String password)
Password to connect to ActiveMQ server.ActiveMqQueue<ID,DATA>
setQueueName(String queueName)
Name of ActiveMQ queue to send/receive messages.ActiveMqQueue<ID,DATA>
setUri(String uri)
ActiveMQ's connection URI (see http://activemq.apache.org/connection-configuration-uri.html).ActiveMqQueue<ID,DATA>
setUsername(String username)
Username to connect to ActiveMQ server.IQueueMessage<ID,DATA>
take()
Take a message out of queue.-
Methods inherited from class com.github.ddth.queue.impl.AbstractQueue
close, createMessage, createMessage, createMessage, deserialize, deserialize, getMessageFactory, getSerDeser, queue, requeue, requeueSilent, serialize, setMessageFactory, setSerDeser
-
-
-
-
Field Detail
-
DEFAULT_URI
public static final String DEFAULT_URI
- See Also:
- Constant Field Values
-
DEFAULT_QUEUE_NAME
public static final String DEFAULT_QUEUE_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
getUri
public String getUri()
ActiveMQ's connection URI (see http://activemq.apache.org/connection-configuration-uri.html).- Returns:
-
setUri
public ActiveMqQueue<ID,DATA> setUri(String uri)
ActiveMQ's connection URI (see http://activemq.apache.org/connection-configuration-uri.html).- Parameters:
uri
-- Returns:
-
getUsername
public String getUsername()
Username to connect to ActiveMQ server.- Returns:
-
setUsername
public ActiveMqQueue<ID,DATA> setUsername(String username)
Username to connect to ActiveMQ server.- Parameters:
username
-- Returns:
-
getPassword
public String getPassword()
Password to connect to ActiveMQ server.- Returns:
-
setPassword
public ActiveMqQueue<ID,DATA> setPassword(String password)
Password to connect to ActiveMQ server.- Parameters:
password
-- Returns:
-
getQueueName
public String getQueueName()
Name of ActiveMQ queue to send/receive messages.- Overrides:
getQueueName
in classAbstractQueue<ID,DATA>
- Returns:
-
setQueueName
public ActiveMqQueue<ID,DATA> setQueueName(String queueName)
Name of ActiveMQ queue to send/receive messages.- Overrides:
setQueueName
in classAbstractQueue<ID,DATA>
- Parameters:
queueName
-- Returns:
-
getConnectionFactory
protected org.apache.activemq.ActiveMQConnectionFactory getConnectionFactory()
Getter forconnectionFactory
.- Returns:
-
setConnectionFactory
protected ActiveMqQueue<ID,DATA> setConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory connectionFactory, boolean setMyOwnConnectionFactory)
Setter forconnectionFactory
.- Parameters:
connectionFactory
-setMyOwnConnectionFactory
-- Returns:
- Since:
- 0.7.1
-
setConnectionFactory
public ActiveMqQueue<ID,DATA> setConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory connectionFactory)
Setter forconnectionFactory
.- Parameters:
connectionFactory
-- Returns:
-
getConnection
protected javax.jms.Connection getConnection() throws javax.jms.JMSException
- Throws:
javax.jms.JMSException
-
createSession
protected javax.jms.Session createSession(int acknowledgeMode) throws javax.jms.JMSException
- Throws:
javax.jms.JMSException
-
getProducerSession
protected javax.jms.Session getProducerSession() throws javax.jms.JMSException
Get theSession
dedicated for sending messages.- Returns:
- Throws:
javax.jms.JMSException
-
getMessageProducer
protected javax.jms.MessageProducer getMessageProducer() throws javax.jms.JMSException
- Throws:
javax.jms.JMSException
-
getConsumerSession
protected javax.jms.Session getConsumerSession() throws javax.jms.JMSException
Get theSession
dedicated for consuming messages.- Returns:
- Throws:
javax.jms.JMSException
-
getMessageConsumer
protected javax.jms.MessageConsumer getMessageConsumer() throws javax.jms.JMSException
- Throws:
javax.jms.JMSException
-
buildConnectionFactory
protected org.apache.activemq.ActiveMQConnectionFactory buildConnectionFactory()
- Returns:
- Since:
- 0.6.2.6
-
init
public ActiveMqQueue<ID,DATA> init() throws Exception
Init method.- Overrides:
init
in classAbstractQueue<ID,DATA>
- Returns:
- Throws:
Exception
-
destroy
public void destroy()
Destroy method.- Overrides:
destroy
in classAbstractQueue<ID,DATA>
-
closeQuietly
protected void closeQuietly(javax.jms.Connection connection)
-
closeQuietly
protected void closeQuietly(javax.jms.Session session)
-
closeQuietly
protected void closeQuietly(javax.jms.MessageConsumer consumer)
-
closeQuietly
protected void closeQuietly(javax.jms.MessageProducer producer)
-
finish
public void finish(IQueueMessage<ID,DATA> msg)
Called when finish processing the message to cleanup ephemeral storage.Implementation flow:
- Remove message from ephemeral storage.
Note: ephemeral storage implementation is optional, depends on implementation.
-
doPutToQueue
protected boolean doPutToQueue(IQueueMessage<ID,DATA> msg, AbstractQueue.PutToQueueCase queueCase)
Put a message to the queue storage.Sub-class implements this method.
queueCase
is ignore as we always add new message to ActiveMQ.- Specified by:
doPutToQueue
in classAbstractQueue<ID,DATA>
- Returns:
-
take
public IQueueMessage<ID,DATA> take() throws QueueException.EphemeralIsFull
Take a message out of queue.Implementation flow:
- Read message from head of queue storage.
- Write message to ephemeral storage.
- Remove message from queue storage.
Note: ephemeral storage implementation is optional, depends on implementation.
- Returns:
- Throws:
QueueException.EphemeralIsFull
- if the ephemeral storage is full
-
getOrphanMessages
public Collection<IQueueMessage<ID,DATA>> getOrphanMessages(long thresholdTimestampMs)
Get all orphan messages (messages that were left in ephemeral storage for a long time).- Parameters:
thresholdTimestampMs
- message is orphan ifmessage's timestampMillis + thresholdTimestampMs < now
. Which meansgetOrphanMessages(10000)
will return orphan messages that have stayed in ephemeral storage for more than 10000 milliseconds.- Returns:
null
or empty collection if there is no orphan message
-
queueSize
public int queueSize()
Get number of items currently in queue storage.- Returns:
- negative number if queue size can not be queried
-
ephemeralSize
public int ephemeralSize()
Get number of items currently in ephemeral storage.Note: ephemeral storage implementation is optional, depends on implementation.
- Returns:
- negative number if ephemeral size can not be queried
-
-