ARTEMIS-388 listen for activation failures

Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/94dc2976
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/94dc2976
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/94dc2976

Branch: refs/heads/master
Commit: 94dc2976ef04498aa14b67a8c13088bebf91d5d1
Parents: 1f371ad
Author: jbertram <[email protected]>
Authored: Fri Feb 5 12:11:21 2016 -0600
Committer: Clebert Suconic <[email protected]>
Committed: Tue Feb 9 14:24:07 2016 -0500

----------------------------------------------------------------------
 .../core/server/ActivationFailureListener.java  | 31 ++++++++++++
 .../artemis/core/server/ActiveMQServer.java     | 21 ++++++++
 .../core/server/impl/ActiveMQServerImpl.java    | 20 ++++++++
 .../core/server/impl/LiveOnlyActivation.java    |  1 +
 .../impl/SharedNothingLiveActivation.java       |  1 +
 .../server/impl/SharedStoreLiveActivation.java  |  1 +
 .../server/ActivationFailureListenerTest.java   | 52 ++++++++++++++++++++
 7 files changed, 127 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/94dc2976/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActivationFailureListener.java
----------------------------------------------------------------------
diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActivationFailureListener.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActivationFailureListener.java
new file mode 100644
index 0000000..960394b
--- /dev/null
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActivationFailureListener.java
@@ -0,0 +1,31 @@
+/*
+ * 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.core.server;
+
+/**
+ * This interface represents a way users can be alerted to activation failures 
that don't necessarily constitute a
+ * fatal problem for the broker (e.g. the failure to start an acceptor)
+ */
+public interface ActivationFailureListener {
+
+   /**
+    * This will be invoked by the broker in case of an exception during the 
activation process
+    *
+    * @param exception the exception which caused the activation failure
+    */
+   void activationFailed(Exception exception);
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/94dc2976/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java
----------------------------------------------------------------------
diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java
index d7a298d..e3c1b2a 100644
--- 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java
@@ -105,6 +105,27 @@ public interface ActiveMQServer extends ActiveMQComponent {
 
    void unregisterActivateCallback(ActivateCallback callback);
 
+   /**
+    * Register a listener to detect problems during activation
+    *
+    * @param listener @see 
org.apache.activemq.artemis.core.server.ActivationFailureListener
+    */
+   void registerActivationFailureListener(ActivationFailureListener listener);
+
+   /**
+    * Remove a previously registered failure listener
+    *
+    * @param listener
+    */
+   void unregisterActivationFailureListener(ActivationFailureListener 
listener);
+
+   /**
+    * Alert activation failure listeners of a failure.
+    *
+    * @param e the exception that caused the activation failure
+    */
+   void callActivationFailureListeners(Exception e);
+
    void checkQueueCreationLimit(String username) throws Exception;
 
    ServerSession createSession(String name,

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/94dc2976/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java
----------------------------------------------------------------------
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 8c4b7bd..1934f2f 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
@@ -91,6 +91,7 @@ import org.apache.activemq.artemis.core.security.SecurityAuth;
 import org.apache.activemq.artemis.core.security.SecurityStore;
 import org.apache.activemq.artemis.core.security.impl.SecurityStoreImpl;
 import org.apache.activemq.artemis.core.server.ActivateCallback;
+import org.apache.activemq.artemis.core.server.ActivationFailureListener;
 import org.apache.activemq.artemis.core.server.ActiveMQComponent;
 import org.apache.activemq.artemis.core.server.ActiveMQMessageBundle;
 import org.apache.activemq.artemis.core.server.ActiveMQServer;
@@ -245,6 +246,8 @@ public class ActiveMQServerImpl implements ActiveMQServer {
 
    private final Set<ActivateCallback> activateCallbacks = new 
ConcurrentHashSet<>();
 
+   private final Set<ActivationFailureListener> activationFailureListeners = 
new ConcurrentHashSet<>();
+
    private volatile GroupingHandler groupingHandler;
 
    private NodeManager nodeManager;
@@ -1356,6 +1359,23 @@ public class ActiveMQServerImpl implements 
ActiveMQServer {
    }
 
    @Override
+   public void registerActivationFailureListener(final 
ActivationFailureListener listener) {
+      activationFailureListeners.add(listener);
+   }
+
+   @Override
+   public void unregisterActivationFailureListener(final 
ActivationFailureListener listener) {
+      activationFailureListeners.remove(listener);
+   }
+
+   @Override
+   public void callActivationFailureListeners(final Exception e) {
+      for (ActivationFailureListener listener : activationFailureListeners) {
+         listener.activationFailed(e);
+      }
+   }
+
+   @Override
    public ExecutorFactory getExecutorFactory() {
       return executorFactory;
    }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/94dc2976/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/LiveOnlyActivation.java
----------------------------------------------------------------------
diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/LiveOnlyActivation.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/LiveOnlyActivation.java
index d8224dc..6811369 100644
--- 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/LiveOnlyActivation.java
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/LiveOnlyActivation.java
@@ -71,6 +71,7 @@ public class LiveOnlyActivation extends Activation {
       }
       catch (Exception e) {
          ActiveMQServerLogger.LOGGER.initializationError(e);
+         activeMQServer.callActivationFailureListeners(e);
       }
    }
 

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/94dc2976/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedNothingLiveActivation.java
----------------------------------------------------------------------
diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedNothingLiveActivation.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedNothingLiveActivation.java
index 76730a0..11b83b7 100644
--- 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedNothingLiveActivation.java
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedNothingLiveActivation.java
@@ -107,6 +107,7 @@ public class SharedNothingLiveActivation extends 
LiveActivation {
       }
       catch (Exception e) {
          ActiveMQServerLogger.LOGGER.initializationError(e);
+         activeMQServer.callActivationFailureListeners(e);
       }
    }
 

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/94dc2976/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedStoreLiveActivation.java
----------------------------------------------------------------------
diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedStoreLiveActivation.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedStoreLiveActivation.java
index 868be2e..8cdcb91 100644
--- 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedStoreLiveActivation.java
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedStoreLiveActivation.java
@@ -72,6 +72,7 @@ public final class SharedStoreLiveActivation extends 
LiveActivation {
       }
       catch (Exception e) {
          ActiveMQServerLogger.LOGGER.initializationError(e);
+         activeMQServer.callActivationFailureListeners(e);
       }
    }
 

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/94dc2976/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/server/ActivationFailureListenerTest.java
----------------------------------------------------------------------
diff --git 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/server/ActivationFailureListenerTest.java
 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/server/ActivationFailureListenerTest.java
new file mode 100644
index 0000000..6732b7a
--- /dev/null
+++ 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/server/ActivationFailureListenerTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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.net.InetSocketAddress;
+import java.net.Socket;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.activemq.artemis.core.server.ActivationFailureListener;
+import org.apache.activemq.artemis.core.server.ActiveMQServer;
+import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
+import org.junit.Test;
+
+/**
+ * A simple test-case used for documentation purposes.
+ */
+public class ActivationFailureListenerTest extends ActiveMQTestBase {
+
+   protected ActiveMQServer server;
+
+   @Test
+   public void simpleTest() throws Exception {
+      Socket s = new Socket();
+      s.bind(new InetSocketAddress("127.0.0.1", 61616));
+      server = createServer(false, createDefaultNettyConfig());
+      final CountDownLatch latch = new CountDownLatch(1);
+      server.registerActivationFailureListener(new ActivationFailureListener() 
{
+         @Override
+         public void activationFailed(Exception exception) {
+            latch.countDown();
+         }
+      });
+      server.start();
+      assertTrue(latch.await(3000, TimeUnit.MILLISECONDS));
+   }
+}

Reply via email to