|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object dk.netarkivet.common.distribute.JMSConnection
public abstract class JMSConnection
Handles the communication with a JMS broker. Note on Thread-safety: the methods and fields of JMSConnection are not accessed by multiple threads (though JMSConnection itself creates threads). Thus no synchronization is needed on methods and fields of JMSConnection. A shutdown hook is also added, which closes the connection. Class JMSConnection is now also a exceptionhandler for the JMS Connections
Field Summary | |
---|---|
protected java.lang.Thread |
closeHook
Shutdown hook that closes the JMS connection. |
protected javax.jms.Connection |
connection
The JMS Connection. |
protected java.util.concurrent.locks.ReentrantReadWriteLock |
connectionLock
Lock for the connection. |
protected static java.lang.String |
CONSUMER_KEY_SEPARATOR
Separator used in the consumer key. |
protected java.util.Map<java.lang.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. |
(package private) static int |
JMS_MAXTRIES
The number to times to (re)try whenever a JMSException is thrown. |
protected java.util.Map<java.lang.String,javax.jms.MessageListener> |
listeners
Map for caching message listeners (topic-subscribers and queue-receivers). |
protected java.util.Map<java.lang.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. |
Constructor Summary | |
---|---|
protected |
JMSConnection()
Class constructor. |
Method Summary | |
---|---|
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 java.lang.String |
getConsumerKey(java.lang.String channel,
javax.jms.MessageListener messageListener)
Generate a consumerkey based on the given channel name and messageListener. |
protected abstract javax.jms.Destination |
getDestination(java.lang.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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final java.lang.String CONSUMER_KEY_SEPARATOR
static final int JMS_MAXTRIES
protected javax.jms.Connection connection
protected javax.jms.Session session
protected final java.util.Map<java.lang.String,javax.jms.MessageProducer> producers
protected final java.util.Map<java.lang.String,javax.jms.MessageConsumer> consumers
protected final java.util.Map<java.lang.String,javax.jms.MessageListener> listeners
protected final java.util.concurrent.locks.ReentrantReadWriteLock connectionLock
protected java.lang.Thread closeHook
protected static JMSConnection instance
Constructor Detail |
---|
protected JMSConnection()
Method Detail |
---|
protected abstract javax.jms.ConnectionFactory getConnectionFactory() throws javax.jms.JMSException
javax.jms.JMSException
- If unable to get QueueConnectionFactoryprotected abstract javax.jms.Destination getDestination(java.lang.String destinationName) throws javax.jms.JMSException
destinationName
- the name of the wanted Queue
Channels.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 final 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 messagelistener
IOFailure
- if the operation failed.public void removeListener(ChannelID mq, javax.jms.MessageListener ml) throws IOFailure
mq
- the given queue or topicml
- a messagelistener
IOFailure
- 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
broker
javax.jms.JMSException
- Failure to retrieve the QueueBrowser
JMS
Browserpublic void cleanup()
cleanup
in interface CleanupIF
public static NetarkivetMessage unpack(javax.jms.Message msg) throws ArgumentNotValid
msg
- a javax.jms.ObjectMessage
ArgumentNotValid
- 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 channel
IOFailure
- if message failed to be sent.protected void reconnect()
protected static java.lang.String getConsumerKey(java.lang.String channel, javax.jms.MessageListener messageListener)
channel
- Channel namemessageListener
- a messageListener
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |