|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectdk.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 | |
---|---|
(package private) static java.lang.String |
CONSUMER_KEY_SEPARATOR
Separator used in the consumerkey. |
protected java.util.Map<java.lang.String,javax.jms.MessageConsumer> |
consumers
Set for caching consumers (topic-subscribers and queue-receivers). |
(package private) static int |
JMS_MAXTRIES
The number to times to (re)try whenever a JMSException is thrown. |
protected static org.apache.commons.logging.Log |
log
The log. |
protected javax.jms.QueueConnection |
myQConn
The QueueConnection. |
protected javax.jms.QueueConnectionFactory |
myQConnFactory
The factory used to create QueueConnections. |
protected javax.jms.QueueSession |
myQSess
The Session handling messages sent to / received from the NetarchiveSuite queues. |
protected javax.jms.TopicConnection |
myTConn
The TopicConnection. |
protected javax.jms.TopicConnectionFactory |
myTConnFactory
The factory used to create TopicConnections. |
protected javax.jms.TopicSession |
myTSess
The Session handling messages sent to / received from the NetarchiveSuite topics. |
protected java.util.Map<java.lang.String,javax.jms.TopicPublisher> |
publishers
Map for caching Topic publishers. |
protected static java.util.concurrent.atomic.AtomicBoolean |
reconnectInProgress
Semaphore for whether or not a reconnect is in progress. |
protected java.util.Map<java.lang.String,javax.jms.QueueSender> |
senders
Map for caching Queue senders. |
Constructor Summary | |
---|---|
protected |
JMSConnection()
Class constructor. |
Method Summary | |
---|---|
void |
cleanup()
Clean up. |
protected void |
close()
Close all connections to the JMS broker. |
protected void |
establishConnectionAndSessions()
Helper method to establish one QueueConnection and associated Session, and one TopicConnection and associated Session. |
protected static java.lang.String |
getChannelName(java.lang.String consumerKey)
Get the channelName embedded in a consumerKey. |
java.lang.String |
getHost()
Get the hostname for the JMSBroker. |
java.lang.String |
getPort()
Get the port for the JMSBroker. |
protected abstract javax.jms.Queue |
getQueue(java.lang.String queueName)
Should be implemented according to a specific JMS broker. |
protected abstract javax.jms.QueueConnectionFactory |
getQueueConnectionFactory()
Should be implemented according to a specific JMS broker. |
protected abstract javax.jms.Topic |
getTopic(java.lang.String topicName)
Should be implemented according to a specific JMS broker. |
protected abstract javax.jms.TopicConnectionFactory |
getTopicConnectionFactory()
Should be implemented according to a specific JMS broker. |
protected void |
initConnection()
Initializes the JMS connection. |
abstract void |
onException(javax.jms.JMSException e)
Exceptionhandler for the JMSConnection. |
java.util.List<javax.jms.Message> |
removeAllMessages(ChannelID mq)
Deprecated. "Method does not work, See bugs 422 and 423. |
void |
removeListener(ChannelID mq,
javax.jms.MessageListener ml)
Removes the specified MessageListener from the given queue or topic. |
void |
reply(NetarkivetMessage nMsg)
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 nMsg)
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 org.apache.commons.logging.Log log
protected javax.jms.QueueConnectionFactory myQConnFactory
protected javax.jms.QueueConnection myQConn
protected javax.jms.QueueSession myQSess
protected javax.jms.TopicConnectionFactory myTConnFactory
protected javax.jms.TopicConnection myTConn
protected javax.jms.TopicSession myTSess
protected static java.util.concurrent.atomic.AtomicBoolean reconnectInProgress
protected java.util.Map<java.lang.String,javax.jms.QueueSender> senders
protected java.util.Map<java.lang.String,javax.jms.TopicPublisher> publishers
protected java.util.Map<java.lang.String,javax.jms.MessageConsumer> consumers
static final java.lang.String CONSUMER_KEY_SEPARATOR
static final int JMS_MAXTRIES
Constructor Detail |
---|
protected JMSConnection()
Method Detail |
---|
protected void initConnection()
IOFailure
- if initialization fails.protected void establishConnectionAndSessions() throws javax.jms.JMSException
javax.jms.JMSException
protected abstract javax.jms.QueueConnectionFactory getQueueConnectionFactory() throws javax.jms.JMSException
javax.jms.JMSException
protected abstract javax.jms.TopicConnectionFactory getTopicConnectionFactory() throws javax.jms.JMSException
javax.jms.JMSException
protected abstract javax.jms.Queue getQueue(java.lang.String queueName) throws javax.jms.JMSException
queueName
- the name of the wanted Queue
javax.jms.JMSException
protected abstract javax.jms.Topic getTopic(java.lang.String topicName) throws javax.jms.JMSException
topicName
- The name of the wanted Topic
javax.jms.JMSException
public final void send(NetarkivetMessage nMsg)
nMsg
- The NetarkivetMessage to send to the destination queue (null
not allowed)
ArgumentNotValid
- if nMsg is null.
IOFailure
- if the operation failed.public void reply(NetarkivetMessage nMsg)
nMsg
- 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.protected 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.public final void resend(NetarkivetMessage msg, ChannelID to)
msg
- Message to be sentto
- The destination channelprotected void close()
IOFailure
- if closing one of the internal connection objects failed.public 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 reply from JMS server is invalidpublic 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
public java.util.List<javax.jms.Message> removeAllMessages(ChannelID mq)
mq
- The queue/topic to remove messages from
protected static java.lang.String getChannelName(java.lang.String consumerKey)
consumerKey
- a consumerKey
public java.lang.String getHost()
public java.lang.String getPort()
public abstract void onException(javax.jms.JMSException e)
onException
in interface javax.jms.ExceptionListener
e
- an JMSException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |