This closes #381 listener on activation failures
This commit is contained in:
commit
37addeaf76
|
@ -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);
|
||||
}
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
@ -1355,6 +1358,23 @@ public class ActiveMQServerImpl implements ActiveMQServer {
|
|||
activateCallbacks.remove(callback);
|
||||
}
|
||||
|
||||
@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;
|
||||
|
|
|
@ -71,6 +71,7 @@ public class LiveOnlyActivation extends Activation {
|
|||
}
|
||||
catch (Exception e) {
|
||||
ActiveMQServerLogger.LOGGER.initializationError(e);
|
||||
activeMQServer.callActivationFailureListeners(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -107,6 +107,7 @@ public class SharedNothingLiveActivation extends LiveActivation {
|
|||
}
|
||||
catch (Exception e) {
|
||||
ActiveMQServerLogger.LOGGER.initializationError(e);
|
||||
activeMQServer.callActivationFailureListeners(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -72,6 +72,7 @@ public final class SharedStoreLiveActivation extends LiveActivation {
|
|||
}
|
||||
catch (Exception e) {
|
||||
ActiveMQServerLogger.LOGGER.initializationError(e);
|
||||
activeMQServer.callActivationFailureListeners(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue