use of org.apache.oozie.jms.MessageHandler in project oozie by apache.
the class JMSAccessorService method retryConnection.
@VisibleForTesting
boolean retryConnection(JMSConnectionInfo connInfo) {
ConnectionRetryInfo connRetryInfo = retryConnectionsMap.get(connInfo);
if (connRetryInfo.getNumAttempt() >= retryMaxAttempts) {
LOG.info("Not attempting connection [{0}] again. Reached max attempts [{1}]", connInfo, retryMaxAttempts);
return false;
}
LOG.info("Attempting retry of connection [{0}]", connInfo);
connRetryInfo.setNumAttempt(connRetryInfo.getNumAttempt() + 1);
connRetryInfo.setNextDelay(connRetryInfo.getNextDelay() * retryMultiplier);
ConnectionContext connCtxt = createConnectionContext(connInfo);
boolean shouldRetry = false;
if (connCtxt == null) {
shouldRetry = true;
} else {
Map<String, MessageHandler> retryTopicsMap = connRetryInfo.getTopicsToRetry();
Map<String, MessageReceiver> listeningTopicsMap = getReceiversTopicsMap(connInfo);
List<String> topicsToRemoveList = new ArrayList<String>();
// For each topic in the retry list, try to register the MessageHandler for that topic
for (Entry<String, MessageHandler> topicEntry : retryTopicsMap.entrySet()) {
String topic = topicEntry.getKey();
if (listeningTopicsMap.containsKey(topic)) {
continue;
}
synchronized (listeningTopicsMap) {
if (!listeningTopicsMap.containsKey(topic)) {
MessageReceiver receiver = registerForTopic(connInfo, connCtxt, topic, topicEntry.getValue());
if (receiver == null) {
LOG.warn("Failed to register a listener for topic {0} on {1}", topic, connInfo);
} else {
listeningTopicsMap.put(topic, receiver);
topicsToRemoveList.add(topic);
LOG.info("Registered a listener for topic {0} on {1}", topic, connInfo);
}
}
}
}
for (String topic : topicsToRemoveList) {
retryTopicsMap.remove(topic);
}
if (retryTopicsMap.isEmpty()) {
shouldRetry = false;
}
}
if (shouldRetry) {
scheduleRetry(connInfo, connRetryInfo.getNextDelay());
} else {
retryConnectionsMap.remove(connInfo);
}
return true;
}
use of org.apache.oozie.jms.MessageHandler in project oozie by apache.
the class JMSAccessorService method reestablishConnection.
/**
* Reestablish connection for the given JMS connect information
* @param connInfo JMS connection info
*/
public void reestablishConnection(JMSConnectionInfo connInfo) {
// Queue the connection and topics for retry
connectionMap.remove(connInfo);
ConnectionRetryInfo connRetryInfo = queueConnectionForRetry(connInfo);
Map<String, MessageReceiver> listeningTopicsMap = receiversMap.remove(connInfo);
if (listeningTopicsMap != null) {
Map<String, MessageHandler> retryTopicsMap = connRetryInfo.getTopicsToRetry();
for (Entry<String, MessageReceiver> topicEntry : listeningTopicsMap.entrySet()) {
MessageReceiver receiver = topicEntry.getValue();
retryTopicsMap.put(topicEntry.getKey(), receiver.getMessageHandler());
}
}
}
Aggregations