activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject [activemq-artemis] 01/03: ARTEMIS-2438 Activation cleaning
Date Fri, 02 Aug 2019 17:26:29 GMT
This is an automated email from the ASF dual-hosted git repository.

clebertsuconic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git

commit 73e2d4709d5ed18c10de3cc1bad3005c2d08d29a
Author: Clebert Suconic <clebertsuconic@apache.org>
AuthorDate: Thu Aug 1 15:54:06 2019 -0400

    ARTEMIS-2438 Activation cleaning
---
 .../apache/activemq/artemis/cli/commands/Run.java  |  4 +-
 .../jms/server/impl/JMSServerManagerImpl.java      |  4 +-
 .../artemis/core/server/ActivateCallback.java      | 11 +++++
 .../core/server/impl/ActiveMQServerImpl.java       |  8 ++++
 .../CleaningActivateCallback.java}                 | 33 ++++++--------
 .../artemis/core/server/impl/InVMNodeManager.java  |  2 +-
 .../core/server/impl/jdbc/JdbcNodeManager.java     |  3 +-
 .../management/impl/ManagementServiceImpl.java     |  4 +-
 .../cluster/bridge/BridgeReconnectTest.java        |  1 -
 .../integration/discovery/DiscoveryBaseTest.java   |  3 +-
 .../integration/server/ActivationCallbackTest.java | 51 ++++++++++++++++++++++
 11 files changed, 94 insertions(+), 30 deletions(-)

diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Run.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Run.java
index 759815c..d7a26cb 100644
--- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Run.java
+++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Run.java
@@ -29,7 +29,7 @@ import org.apache.activemq.artemis.cli.factory.BrokerFactory;
 import org.apache.activemq.artemis.cli.factory.jmx.ManagementFactory;
 import org.apache.activemq.artemis.cli.factory.security.SecurityManagerFactory;
 import org.apache.activemq.artemis.components.ExternalComponent;
-import org.apache.activemq.artemis.core.server.ActivateCallback;
+import org.apache.activemq.artemis.core.server.impl.CleaningActivateCallback;
 import org.apache.activemq.artemis.core.server.management.ManagementContext;
 import org.apache.activemq.artemis.dto.BrokerDTO;
 import org.apache.activemq.artemis.dto.ComponentDTO;
@@ -83,7 +83,7 @@ public class Run extends LockAbstract {
 
          managementContext.start();
          server.start();
-         server.getServer().registerActivateCallback(new ActivateCallback() {
+         server.getServer().registerActivateCallback(new CleaningActivateCallback() {
             @Override
             public void deActivate() {
                try {
diff --git a/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/server/impl/JMSServerManagerImpl.java
b/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/server/impl/JMSServerManagerImpl.java
index a05ed27..a5e6339 100644
--- a/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/server/impl/JMSServerManagerImpl.java
+++ b/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/server/impl/JMSServerManagerImpl.java
@@ -46,10 +46,10 @@ import org.apache.activemq.artemis.core.postoffice.BindingType;
 import org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory;
 import org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants;
 import org.apache.activemq.artemis.core.security.Role;
-import org.apache.activemq.artemis.core.server.ActivateCallback;
 import org.apache.activemq.artemis.core.server.ActiveMQServer;
 import org.apache.activemq.artemis.core.server.ActiveMQServerLogger;
 import org.apache.activemq.artemis.core.server.impl.AddressInfo;
+import org.apache.activemq.artemis.core.server.impl.CleaningActivateCallback;
 import org.apache.activemq.artemis.core.server.management.Notification;
 import org.apache.activemq.artemis.core.server.reload.ReloadCallback;
 import org.apache.activemq.artemis.core.server.reload.ReloadManager;
@@ -97,7 +97,7 @@ import org.w3c.dom.NodeList;
  * redeployed.
  */
 @Deprecated
-public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback {
+public class JMSServerManagerImpl extends CleaningActivateCallback implements JMSServerManager
{
 
    private static final String REJECT_FILTER = Filter.GENERIC_IGNORED_FILTER;
 
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActivateCallback.java
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActivateCallback.java
index f3d3820..9a646d4 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActivateCallback.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActivateCallback.java
@@ -42,4 +42,15 @@ public interface ActivateCallback {
     */
    default void activationComplete() {
    }
+
+   /*
+    * This is called when the broker is stopped (no shutdown in place)
+    */
+   default void stop(ActiveMQServer server) {
+   }
+
+   default void shutdown(ActiveMQServer server) {
+   }
+
+
 }
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java
index 68ca620..70a4fbf 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java
@@ -1269,6 +1269,14 @@ public class ActiveMQServerImpl implements ActiveMQServer {
          this.analyzer = null;
       }
 
+      for (ActivateCallback callback: activateCallbacks) {
+         if (isShutdown) {
+            callback.shutdown(this);
+         } else {
+            callback.stop(this);
+         }
+      }
+
       if (identity != null) {
          ActiveMQServerLogger.LOGGER.serverStopped("identity=" + identity + ",version=" +
getVersion().getFullVersion(), tempNodeID, getUptime());
       } else {
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActivateCallback.java
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/CleaningActivateCallback.java
similarity index 53%
copy from artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActivateCallback.java
copy to artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/CleaningActivateCallback.java
index f3d3820..f02e30e 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActivateCallback.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/CleaningActivateCallback.java
@@ -14,32 +14,25 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.activemq.artemis.core.server;
 
-public interface ActivateCallback {
+package org.apache.activemq.artemis.core.server.impl;
 
-   /*
-    * this is called before any services are started when the server first initialised
-    */
-   default void preActivate() {
-   }
+import org.apache.activemq.artemis.core.server.ActivateCallback;
+import org.apache.activemq.artemis.core.server.ActiveMQServer;
+
+/** This is an abstract ActivateCallback that will cleanup itself when the broker is shutodwn
*/
+public abstract class CleaningActivateCallback implements ActivateCallback {
 
-   /*
-    * this is called after most of the services have been started but before any cluster
resources or JMS resources have been
-    */
-   default void activated() {
+   public CleaningActivateCallback() {
    }
 
-   /*
-    * this is called when the server is stopping, after any network resources and clients
are closed but before the rest
-    * of the resources
-    */
-   default void deActivate() {
+   @Override
+   public void stop(ActiveMQServer server) {
+      server.unregisterActivateCallback(this);
    }
 
-   /*
-    * this is called when all resources have been started including any JMS resources
-    */
-   default void activationComplete() {
+   @Override
+   public void shutdown(ActiveMQServer server) {
+      server.unregisterActivateCallback(this);
    }
 }
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/InVMNodeManager.java
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/InVMNodeManager.java
index a3bce41..a0e7601 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/InVMNodeManager.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/InVMNodeManager.java
@@ -107,7 +107,7 @@ public final class InVMNodeManager extends NodeManager {
    public ActivateCallback startLiveNode() throws Exception {
       state = FAILING_BACK;
       liveLock.acquire();
-      return new ActivateCallback() {
+      return new CleaningActivateCallback() {
          @Override
          public void activationComplete() {
             try {
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/jdbc/JdbcNodeManager.java
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/jdbc/JdbcNodeManager.java
index 322ea38..b98fd85 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/jdbc/JdbcNodeManager.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/jdbc/JdbcNodeManager.java
@@ -28,6 +28,7 @@ import org.apache.activemq.artemis.core.io.IOCriticalErrorListener;
 import org.apache.activemq.artemis.core.server.ActivateCallback;
 import org.apache.activemq.artemis.core.server.ActiveMQServerLogger;
 import org.apache.activemq.artemis.core.server.NodeManager;
+import org.apache.activemq.artemis.core.server.impl.CleaningActivateCallback;
 import org.apache.activemq.artemis.jdbc.store.drivers.JDBCUtils;
 import org.apache.activemq.artemis.jdbc.store.sql.PropertySQLProvider;
 import org.apache.activemq.artemis.jdbc.store.sql.SQLProvider;
@@ -429,7 +430,7 @@ public final class JdbcNodeManager extends NodeManager {
 
          ActiveMQServerLogger.LOGGER.obtainedLiveLock();
 
-         return new ActivateCallback() {
+         return new CleaningActivateCallback() {
             @Override
             public void activationComplete() {
                LOGGER.debug("ENTER activationComplete");
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/impl/ManagementServiceImpl.java
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/impl/ManagementServiceImpl.java
index 2ba8e4e..aa1479a 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/impl/ManagementServiceImpl.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/impl/ManagementServiceImpl.java
@@ -71,7 +71,6 @@ import org.apache.activemq.artemis.core.postoffice.PostOffice;
 import org.apache.activemq.artemis.core.remoting.server.RemotingService;
 import org.apache.activemq.artemis.core.security.Role;
 import org.apache.activemq.artemis.core.security.SecurityStore;
-import org.apache.activemq.artemis.core.server.ActivateCallback;
 import org.apache.activemq.artemis.core.server.ActiveMQMessageBundle;
 import org.apache.activemq.artemis.core.server.ActiveMQServer;
 import org.apache.activemq.artemis.core.server.ActiveMQServerLogger;
@@ -82,6 +81,7 @@ import org.apache.activemq.artemis.core.server.cluster.Bridge;
 import org.apache.activemq.artemis.core.server.cluster.BroadcastGroup;
 import org.apache.activemq.artemis.core.server.cluster.ClusterConnection;
 import org.apache.activemq.artemis.core.server.impl.AddressInfo;
+import org.apache.activemq.artemis.core.server.impl.CleaningActivateCallback;
 import org.apache.activemq.artemis.core.server.management.ManagementService;
 import org.apache.activemq.artemis.core.server.management.Notification;
 import org.apache.activemq.artemis.core.server.management.NotificationListener;
@@ -553,7 +553,7 @@ public class ManagementServiceImpl implements ManagementService {
        * Ensure the management notification address is created otherwise if auto-create-address
= false then cluster
        * bridges won't be able to connect.
        */
-      messagingServer.registerActivateCallback(new ActivateCallback() {
+      messagingServer.registerActivateCallback(new CleaningActivateCallback() {
          @Override
          public void activated() {
             try {
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/bridge/BridgeReconnectTest.java
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/bridge/BridgeReconnectTest.java
index 88c0e81..23ce8a7 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/bridge/BridgeReconnectTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/bridge/BridgeReconnectTest.java
@@ -480,7 +480,6 @@ public class BridgeReconnectTest extends BridgeTestBase {
          ClientMessage r1 = cons1.receive(30000);
          assertNotNull("received expected msg", r1);
          assertEquals("property value matches", i, r1.getObjectProperty(propKey));
-         BridgeReconnectTest.log.info("got message " + r1.getObjectProperty(propKey));
       }
 
       BridgeReconnectTest.log.info("got messages");
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/discovery/DiscoveryBaseTest.java
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/discovery/DiscoveryBaseTest.java
index 17128c7..650694f 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/discovery/DiscoveryBaseTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/discovery/DiscoveryBaseTest.java
@@ -34,6 +34,7 @@ import org.apache.activemq.artemis.core.server.ActivateCallback;
 import org.apache.activemq.artemis.core.server.NodeManager;
 import org.apache.activemq.artemis.core.server.cluster.BroadcastGroup;
 import org.apache.activemq.artemis.core.server.cluster.impl.BroadcastGroupImpl;
+import org.apache.activemq.artemis.core.server.impl.CleaningActivateCallback;
 import org.apache.activemq.artemis.core.server.management.NotificationService;
 import org.apache.activemq.artemis.tests.integration.IntegrationTestLogger;
 import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
@@ -194,7 +195,7 @@ public class DiscoveryBaseTest extends ActiveMQTestBase {
 
       @Override
       public ActivateCallback startLiveNode() throws Exception {
-         return new ActivateCallback() {
+         return new CleaningActivateCallback() {
          };
       }
 
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/server/ActivationCallbackTest.java
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/server/ActivationCallbackTest.java
new file mode 100644
index 0000000..62a233d
--- /dev/null
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/server/ActivationCallbackTest.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.activemq.artemis.tests.integration.server;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.activemq.artemis.core.server.ActivateCallback;
+import org.apache.activemq.artemis.core.server.ActiveMQServer;
+import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * A simple test-case used for documentation purposes.
+ */
+public class ActivationCallbackTest extends ActiveMQTestBase {
+
+   protected ActiveMQServer server;
+
+   @Test
+   public void callbackOnShutdown() throws Exception {
+      server = createServer(false, createDefaultNettyConfig());
+      final CountDownLatch latch = new CountDownLatch(1);
+      server.registerActivateCallback(new ActivateCallback() {
+         @Override
+         public void shutdown(ActiveMQServer server) {
+            latch.countDown();
+         }
+      });
+      server.start();
+      Assert.assertEquals(1, latch.getCount());
+      server.stop();
+      Assert.assertTrue(latch.await(30, TimeUnit.SECONDS));
+   }
+}


Mime
View raw message