wy96f commented on a change in pull request #2547: Patched with live lock
evaluation
URL: https://github.com/apache/activemq-artemis/pull/2547#discussion_r319468789
##########
File path:
artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedStoreLiveActivation.java
##########
@@ -82,17 +91,76 @@ public void run() {
}
}
+ private void addLockListener(ActiveMQServerImpl activeMQServer, NodeManager
nodeManager) {
+ if (nodeManager instanceof FileLockNodeManager) {
+ FileLockNodeManager fileNodeManager = (FileLockNodeManager)
nodeManager;
+
+ activeLockListener = fileNodeManager.new LockListener() {
+
+ @Override
+ public void lostLock() {
+ stopStartServerInSeperateThread(activeMQServer);
+ }
+
+ };
+ fileNodeManager.registerLockListener(activeLockListener);
+ } // else no business registering a listener
+ }
+
+ /**
+ * We need to do this in a new thread because this takes to long to finish
in
+ * the scheduled thread Also this is not the responsibility of the scheduled
+ * thread
+ * @param activeMQServer
+ */
+ private void stopStartServerInSeperateThread(ActiveMQServerImpl
activeMQServer) {
+ try {
+
+ Runnable startServerRunnable = new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+ activeMQServer.stop(true, false);
+ } catch (Exception e) {
+ logger.warn("Failed to stop artemis server after loosing the
lock", e);
+ }
+
+ try {
+ activeMQServer.start();
+ } catch (Exception e) {
+ logger.error("Failed to start artemis server after
recovering from loosing the lock", e);
+ }
+ }
+
+ };
+ Thread startServer = new Thread(startServerRunnable);
+ startServer.start();
+ } catch (Exception e) {
+ logger.error(e.getMessage());
+ }
+ }
+
@Override
public void close(boolean permanently, boolean restarting) throws Exception
{
// TO avoid a NPE from stop
NodeManager nodeManagerInUse = activeMQServer.getNodeManager();
if (nodeManagerInUse != null) {
+ LockListener closeLockListener = activeLockListener;
+ if (closeLockListener != null) {
+ closeLockListener.unregisterListener();
+ }
+ ActivateCallback activateCallback = nodeManagerActivateCallback;
+ if (activateCallback != null) {
+ activeMQServer.unregisterActivateCallback(activateCallback);
Review comment:
Why we add this? NodeManagerActivateCallback is a CleaningActivateCallback
which would be unregistered in ActiveMQServerImpl::stop.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services