Fields Summary |
---|
private javax.jms.Topic | topic_ |
private javax.jms.TopicSession | topicSession_ |
private javax.jms.TopicConnection | topicConn_ |
private javax.jms.JMSException | connectionException_ |
private javax.jms.TopicSubscriber | topicSub_ |
private javax.jms.TopicPublisher | topicPub_ |
private javax.jms.TextMessage | lastMessage_ |
private javax.jms.Queue | q_ |
private javax.jms.QueueConnection | qConn_ |
private javax.jms.QueueSession | qSession_ |
private javax.jms.QueueReceiver | qRecv_ |
private javax.jms.QueueSender | qSend_ |
private static Logger | log |
Methods Summary |
---|
public void | connect()
log.info("Connecting");
InitialContext iniCtx = new InitialContext();
Object tmp = iniCtx.lookup("HAILXAConnectionFactory");
TopicConnectionFactory tcf = (TopicConnectionFactory)tmp;
topicConn_ = tcf.createTopicConnection();
topic_ = (Topic)iniCtx.lookup("topic/testTopic");
topicSession_ = topicConn_.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
topicConn_.setExceptionListener(this);
topicSub_ = topicSession_.createSubscriber(topic_);
topicSub_.setMessageListener( this );
topicPub_ = topicSession_.createPublisher(topic_);
topicConn_.start();
QueueConnectionFactory qcf = (QueueConnectionFactory)tmp;
qConn_ = qcf.createQueueConnection();
q_ = (Queue)iniCtx.lookup("queue/testQueue");
qSession_ = qConn_.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
qRecv_ = qSession_.createReceiver(q_);
qRecv_.setMessageListener( this );
qSend_ = qSession_.createSender(q_);
qConn_.start();
log.info("Connected");
|
public void | disconnect()
if (topicConn_ == null) return;
log.info("Disconnecting");
connectionException_ = null;
try
{
topicConn_.setExceptionListener(null);
topicSub_.close();
topicPub_.close();
topicConn_.stop();
topicSession_.close();
qRecv_.close();
qSend_.close();
qConn_.stop();
qSession_.close();
}
finally
{
try
{
topicConn_.close();
}
finally
{
topicConn_ = null;
try
{
qConn_.close();
}
finally
{
qConn_ = null;
}
}
}
log.info("Disconnected");
|
public java.lang.String | getConnectionException()
if (connectionException_ == null) return null;
return connectionException_.toString();
|
public java.lang.String | getLastMessage()
if (lastMessage_ == null) return null;
return lastMessage_.getText();
|
public void | onException(javax.jms.JMSException connEx)Acknowledges connenction exception.
Should be invoked every time the HAIL singleton moves.
log.info("Notification received by ExceptionListener. Singleton Probably Moved.");
try
{
reconnect();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
connectionException_ = connEx;
}
|
public void | onMessage(javax.jms.Message msg)Handle JMS message
lastMessage_ = (TextMessage)msg;
log.info("Message received: " + msg);
|
public void | publishMessageToTopic(java.lang.String text)
TextMessage msg = topicSession_.createTextMessage(text);
topicPub_.publish(msg);
log.info("HA JMS message published to topic: " + text);
|
protected void | reconnect()
log.info("Reconnecting");
try
{
disconnect();
}
finally
{
connect();
}
|
public void | sendMessageToQueue(java.lang.String text)
TextMessage msg = qSession_.createTextMessage(text);
qSend_.send(msg);
log.info("HA JMS message sent to queue: " + text);
|
protected void | startService()create connection, sessions and subscribe for topic and queue
connect();
|
protected void | stopService()unsubscribe from topic, queue,
stop sessions and connection
disconnect();
|