public abstract class JMSConnection extends Object implements javax.jms.ExceptionListener, CleanupIF
Modifier and Type | Field and Description |
---|---|
protected Thread |
closeHook
Shutdown hook that closes the JMS connection.
|
protected javax.jms.Connection |
connection
The JMS Connection.
|
protected ReentrantReadWriteLock |
connectionLock
Lock for the connection.
|
protected static String |
CONSUMER_KEY_SEPARATOR
Separator used in the consumer key.
|
protected Map<String,javax.jms.MessageConsumer> |
consumers
Map for caching message consumers (topic-subscribers and queue-receivers).
|
protected static JMSConnection |
instance
Singleton pattern is be used for this class.
|
protected Map<String,javax.jms.MessageListener> |
listeners
Map for caching message listeners (topic-subscribers and queue-receivers).
|
protected Map<String,javax.jms.MessageProducer> |
producers
Map for caching message producers.
|
protected javax.jms.Session |
session
The Session handling messages sent to / received from the NetarchiveSuite queues and topics.
|
Modifier | Constructor and Description |
---|---|
protected |
JMSConnection()
Class constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
cleanup()
Clean up.
|
javax.jms.QueueBrowser |
createQueueBrowser(ChannelID queueID)
Creates a QueueBrowser object to peek at the messages on the specified queue.
|
protected abstract javax.jms.ConnectionFactory |
getConnectionFactory()
Should be implemented according to a specific JMS broker.
|
protected static String |
getConsumerKey(String channel,
javax.jms.MessageListener messageListener)
Generate a consumerkey based on the given channel name and messageListener.
|
protected abstract javax.jms.Destination |
getDestination(String destinationName)
Should be implemented according to a specific JMS broker.
|
abstract javax.jms.QueueSession |
getQueueSession()
Provides a QueueSession instance.
|
protected void |
initConnection()
Initializes the JMS connection.
|
abstract void |
onException(javax.jms.JMSException e)
Exceptionhandler for the JMSConnection.
|
protected void |
reconnect()
Do a reconnect to the JMSbroker.
|
void |
removeListener(ChannelID mq,
javax.jms.MessageListener ml)
Removes the specified MessageListener from the given queue or topic.
|
void |
reply(NetarkivetMessage msg)
Submit an object to the reply queue.
|
void |
resend(NetarkivetMessage msg,
ChannelID to)
Sends a message msg to the channel defined by the parameter to - NOT the channel defined in the message.
|
void |
send(NetarkivetMessage msg)
Submit an object to the destination queue.
|
protected void |
sendMessage(NetarkivetMessage nMsg,
ChannelID to)
Submit an ObjectMessage to the destination channel.
|
void |
setListener(ChannelID mq,
javax.jms.MessageListener ml)
Method adds a listener to the given queue or topic.
|
static NetarkivetMessage |
unpack(javax.jms.Message msg)
Unwraps a NetarkivetMessage from an ObjectMessage.
|
protected static final String CONSUMER_KEY_SEPARATOR
protected javax.jms.Connection connection
protected javax.jms.Session session
protected final Map<String,javax.jms.MessageProducer> producers
protected final Map<String,javax.jms.MessageConsumer> consumers
protected final Map<String,javax.jms.MessageListener> listeners
protected final ReentrantReadWriteLock connectionLock
protected static JMSConnection instance
protected JMSConnection()
protected abstract javax.jms.ConnectionFactory getConnectionFactory() throws javax.jms.JMSException
javax.jms.JMSException
- If unable to get QueueConnectionFactoryprotected abstract javax.jms.Destination getDestination(String destinationName) throws javax.jms.JMSException
destinationName
- the name of the wanted QueueChannels.isTopic(String)
javax.jms.JMSException
- If unable to get a destination.public abstract void onException(javax.jms.JMSException e)
onException
in interface javax.jms.ExceptionListener
e
- a JMSExceptionprotected void initConnection() throws IOFailure
IOFailure
- if initialization fails.public void send(NetarkivetMessage msg)
msg
- The NetarkivetMessage to send to the destination queue (null not allowed)ArgumentNotValid
- if nMsg is null.IOFailure
- if the operation failed.public final void resend(NetarkivetMessage msg, ChannelID to)
msg
- Message to be sentto
- The destination channelpublic final void reply(NetarkivetMessage msg)
msg
- The NetarkivetMessage to send to the reply queue (null not allowed)ArgumentNotValid
- if nMsg is null.PermissionDenied
- if message nMsg has not been sent yet.IOFailure
- if unable to reply.public void setListener(ChannelID mq, javax.jms.MessageListener ml) throws IOFailure
mq
- the messagequeue to listen toml
- the messagelistenerIOFailure
- if the operation failed.public void removeListener(ChannelID mq, javax.jms.MessageListener ml) throws IOFailure
mq
- the given queue or topicml
- a messagelistenerIOFailure
- On network troublepublic javax.jms.QueueBrowser createQueueBrowser(ChannelID queueID) throws javax.jms.JMSException
queueID
- The ChannelID for a specified queue.javax.jms.JMSException
- If unable to create the specified queue browserpublic abstract javax.jms.QueueSession getQueueSession() throws javax.jms.JMSException
QueueSession
object isen't
available on the generic JMSConnectionFactory
QueueSession
object connected to the current JMS brokerjavax.jms.JMSException
- Failure to retrieve the QueueBrowser
JMS Browserpublic void cleanup()
public static NetarkivetMessage unpack(javax.jms.Message msg) throws ArgumentNotValid
msg
- a javax.jms.ObjectMessageArgumentNotValid
- when msg in valid or format of JMS Object message is invalidprotected void sendMessage(NetarkivetMessage nMsg, ChannelID to) throws IOFailure
nMsg
- the NetarkivetMessage to be wrapped and send as an ObjectMessageto
- the destination channelIOFailure
- if message failed to be sent.protected void reconnect()
protected static String getConsumerKey(String channel, javax.jms.MessageListener messageListener)
channel
- Channel namemessageListener
- a messageListenerCopyright © 2005–2018 The Royal Danish Library, the National Library of France and the Austrian National Library.. All rights reserved.