use of org.apache.activemq.artemis.utils.FutureLatch in project activemq-artemis by apache.
the class ClusterConnectionImpl method flushExecutor.
@Override
public void flushExecutor() {
FutureLatch future = new FutureLatch();
executor.execute(future);
if (!future.await(10000)) {
ActiveMQServerLogger.LOGGER.couldNotFinishExecutor(this.toString());
server.threadDump();
}
}
use of org.apache.activemq.artemis.utils.FutureLatch in project activemq-artemis by apache.
the class ClusterManager method flushExecutor.
public void flushExecutor() {
FutureLatch future = new FutureLatch();
executor.execute(future);
if (!future.await(10000)) {
ActiveMQServerLogger.LOGGER.couldNotFlushClusterManager(this.toString());
server.threadDump();
}
}
use of org.apache.activemq.artemis.utils.FutureLatch in project activemq-artemis by apache.
the class ActiveMQActivation method teardown.
/**
* Teardown the activation
*/
protected synchronized void teardown() {
logger.debug("Tearing down " + spec);
long timeout = factory == null ? ActiveMQClient.DEFAULT_CALL_TIMEOUT : factory.getCallTimeout();
if (resourceRecovery != null) {
ra.getRecoveryManager().unRegister(resourceRecovery);
}
final ActiveMQMessageHandler[] handlersCopy = new ActiveMQMessageHandler[handlers.size()];
// So we invert the handlers here
for (int i = 0; i < handlers.size(); i++) {
// The index here is the complimentary so it's inverting the array
handlersCopy[i] = handlers.get(handlers.size() - i - 1);
}
handlers.clear();
FutureLatch future = new FutureLatch(handlersCopy.length);
List<Thread> interruptThreads = new ArrayList<>();
for (ActiveMQMessageHandler handler : handlersCopy) {
Thread thread = handler.interruptConsumer(future);
if (thread != null) {
interruptThreads.add(thread);
}
}
// wait for all the consumers to complete any onmessage calls
boolean stuckThreads = !future.await(timeout);
// if any are stuck then we need to interrupt them
if (stuckThreads) {
for (Thread interruptThread : interruptThreads) {
try {
interruptThread.interrupt();
} catch (Exception e) {
// ok
}
}
}
Thread threadTearDown = new Thread("TearDown/ActiveMQActivation") {
@Override
public void run() {
for (ActiveMQMessageHandler handler : handlersCopy) {
handler.teardown();
}
}
};
// We will first start a new thread that will call tearDown on all the instances, trying to graciously shutdown everything.
// We will then use the call-timeout to determine a timeout.
// if that failed we will then close the connection factory, and interrupt the thread
threadTearDown.start();
try {
threadTearDown.join(timeout);
} catch (InterruptedException e) {
// nothing to be done on this context.. we will just keep going as we need to send an interrupt to threadTearDown and give up
}
if (factory != null) {
try {
// closing the factory will help making sure pending threads are closed
factory.close();
} catch (Throwable e) {
ActiveMQRALogger.LOGGER.unableToCloseFactory(e);
}
factory = null;
}
if (threadTearDown.isAlive()) {
threadTearDown.interrupt();
try {
threadTearDown.join(5000);
} catch (InterruptedException e) {
// nothing to be done here.. we are going down anyways
}
if (threadTearDown.isAlive()) {
ActiveMQRALogger.LOGGER.threadCouldNotFinish(threadTearDown.toString());
}
}
nodes.clear();
lastReceived = false;
logger.debug("Tearing down complete " + this);
}
Aggregations