in uimaj-as-jms/src/main/java/org/apache/uima/adapter/jms/client/BaseUIMAAsynchronousEngineCommon_impl.java [3272:3364]
public synchronized void retryConnectionUntilSuccessfull() {
// Check if the connection has been restored to the broker. Another thread
// may have previously recovered the connection here while we were blocked
// on entry to this method ( it is synchronized)
if ( isConnectionValid() ) {
//System.out.println("------------- BaseUIMAAsynchronousEngineCommon_impl.retryConnectionUntilSuccessfull() connection is valid");
return;
}
//System.out.println("------------- BaseUIMAAsynchronousEngineCommon_impl.retryConnectionUntilSuccessfull() connection Not valid");
// Change state of each client in this JVM that uses this shared connection.
for(BaseUIMAAsynchronousEngineCommon_impl client: clientList) {
client.state = ClientState.RECONNECTING;
client.producerInitialized = false;
}
//System.out.println("------------------------ stop1? "+stop);
if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.WARNING)) {
UIMAFramework.getLogger(CLASS_NAME).logrb(Level.WARNING, CLASS_NAME.getName(), "retryConnectionUntilSuccessfull",
JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_client_lost_connection_to_broker__WARNING",
new Object[] { brokerURL, (stop==true) });
}
// stop = false;
//System.out.println("------------------------ stop2? "+stop);
// This loop attempts to recover broker connection every 5 seconds and ends when all clients
// using this shared object terminate or a connection is recovered
boolean log = true;
while( !stop ) {
BaseUIMAAsynchronousEngineCommon_impl c = null;
if ( clientList.size() == 0 ) {
break; // no more active clients - break out of connection recovery
} else {
c = clientList.get(0);
if ( !c.running) {
break;
}
}
try {
// Attempt a new connection to a broker
create();
if ( c != null && !c.running) {
break;
}
// Got it, start the connection
start();
if ( c != null && !c.running) {
break;
}
// Forces clients to drop old Session, Temp Queue, and Consumer objects and create
// new ones. This is needs to be done after a new Connection is created.
reinitializeClientListeners();
synchronized( stateMonitor) {
state = ConnectionState.OPEN;
}
break;
} catch( Exception e) {
if ( log ) {
if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.INFO)) {
UIMAFramework.getLogger(CLASS_NAME).logrb(Level.INFO, CLASS_NAME.getName(), "retryConnectionUntilSuccessfull",
JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_client_connection_retry__INFO",
new Object[] { brokerURL });
}
if ( e instanceof JMSException && e.getMessage().indexOf("Connection refused") > 0) {
log = false;
System.out.println("Uima AS Client:"+e.getMessage()+" Retrying every 5 seconds until successfull");
} else {
e.printStackTrace();
}
}
synchronized( stateMonitor ) {
try {
stateMonitor.wait(5000); // retry every 5 secs
} catch( InterruptedException ie) {}
}
}
}
if ( !stop ) {
if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.INFO)) {
UIMAFramework.getLogger(CLASS_NAME).logrb(Level.INFO, CLASS_NAME.getName(), "retryConnectionUntilSuccessfull",
JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_client_recovered_connection__INFO",
new Object[] { brokerURL });
}
}
for(BaseUIMAAsynchronousEngineCommon_impl client: clientList) {
client.state = ClientState.RUNNING;
}
}