use of org.apache.activemq.artemis.core.server.ActiveMQComponent in project activemq-artemis by apache.
the class FileBroker method getComponentsByStartOrder.
/*
* this makes sure the components are started in the correct order. Its simple at the mo as e only have core and jms but
* will need impproving if we get more.
* */
private ArrayList<ActiveMQComponent> getComponentsByStartOrder(Map<String, ActiveMQComponent> components) {
ArrayList<ActiveMQComponent> activeMQComponents = new ArrayList<>();
ActiveMQComponent jmsComponent = components.get("jms");
if (jmsComponent != null) {
activeMQComponents.add(jmsComponent);
}
activeMQComponents.add(components.get("core"));
return activeMQComponents;
}
use of org.apache.activemq.artemis.core.server.ActiveMQComponent in project activemq-artemis by apache.
the class FileBroker method start.
@Override
public synchronized void start() throws Exception {
if (started) {
return;
}
// todo if we start to pullout more configs from the main config then we should pull out the configuration objects from factories if available
FileConfiguration configuration = new FileConfiguration();
// Keep this as we still want to parse destinations in the <jms> element
FileJMSConfiguration jmsConfiguration = new FileJMSConfiguration();
FileDeploymentManager fileDeploymentManager = new FileDeploymentManager(configurationUrl);
fileDeploymentManager.addDeployable(configuration).addDeployable(jmsConfiguration);
fileDeploymentManager.readConfiguration();
createDirectories(configuration);
/**
* This is a bit of a hack for backwards config compatibility since we no longer want to start the broker
* using the JMSServerManager which would normally deploy JMS destinations. Here we take the JMS destination
* configurations from the parsed JMS configuration and add them to the core configuration.
*
* It's also important here that we are adding them to the core ADDRESS configurations as those will be
* deployed first and therefore their configuration will take precedence over other legacy queue configurations
* which are deployed later. This is so we can maintain support for configurations like those found in the
* bridge and divert examples where there are JMS and core queues with the same name (which was itself a bit
* of a hack).
*
* This should be removed when support for the old "jms" configuation element is also removed.
*/
{
for (JMSQueueConfiguration jmsQueueConfig : jmsConfiguration.getQueueConfigurations()) {
List<CoreAddressConfiguration> coreAddressConfigurations = configuration.getAddressConfigurations();
coreAddressConfigurations.add(new CoreAddressConfiguration().setName(jmsQueueConfig.getName()).addRoutingType(RoutingType.ANYCAST).addQueueConfiguration(new CoreQueueConfiguration().setAddress(jmsQueueConfig.getName()).setName(jmsQueueConfig.getName()).setFilterString(jmsQueueConfig.getSelector()).setRoutingType(RoutingType.ANYCAST)));
}
for (TopicConfiguration topicConfig : jmsConfiguration.getTopicConfigurations()) {
List<CoreAddressConfiguration> coreAddressConfigurations = configuration.getAddressConfigurations();
coreAddressConfigurations.add(new CoreAddressConfiguration().setName(topicConfig.getName()).addRoutingType(RoutingType.MULTICAST));
}
}
components = fileDeploymentManager.buildService(securityManager, ManagementFactory.getPlatformMBeanServer());
ArrayList<ActiveMQComponent> componentsByStartOrder = getComponentsByStartOrder(components);
ActiveMQBootstrapLogger.LOGGER.serverStarting();
for (ActiveMQComponent component : componentsByStartOrder) {
component.start();
}
started = true;
}
use of org.apache.activemq.artemis.core.server.ActiveMQComponent in project activemq-artemis by apache.
the class ActiveMQServerImpl method stop.
/**
* Stops the server
*
* @param criticalIOError whether we have encountered an IO error with the journal etc
*/
void stop(boolean failoverOnServerShutdown, final boolean criticalIOError, boolean restarting, boolean isShutdown) {
synchronized (this) {
if (state == SERVER_STATE.STOPPED || state == SERVER_STATE.STOPPING) {
return;
}
state = SERVER_STATE.STOPPING;
if (fileStoreMonitor != null) {
fileStoreMonitor.stop();
fileStoreMonitor = null;
}
if (failoverOnServerShutdown) {
activation.sendLiveIsStopping();
}
stopComponent(connectorsService);
// aren't removed in case of failover
if (groupingHandler != null) {
managementService.removeNotificationListener(groupingHandler);
stopComponent(groupingHandler);
}
stopComponent(clusterManager);
if (remotingService != null) {
remotingService.pauseAcceptors();
}
// allows for graceful shutdown
if (remotingService != null && configuration.isGracefulShutdownEnabled()) {
long timeout = configuration.getGracefulShutdownTimeout();
try {
if (timeout == -1) {
remotingService.getConnectionCountLatch().await();
} else {
remotingService.getConnectionCountLatch().await(timeout);
}
} catch (InterruptedException e) {
ActiveMQServerLogger.LOGGER.interruptWhilstStoppingComponent(remotingService.getClass().getName());
}
}
freezeConnections();
}
activation.postConnectionFreeze();
closeAllServerSessions(criticalIOError);
if (storageManager != null)
storageManager.clearContext();
// before we stop any components deactivate any callbacks
callDeActiveCallbacks();
stopComponent(backupManager);
try {
activation.preStorageClose();
} catch (Throwable t) {
ActiveMQServerLogger.LOGGER.errorStoppingComponent(t, activation.getClass().getName());
}
stopComponent(pagingManager);
if (storageManager != null)
try {
storageManager.stop(criticalIOError, failoverOnServerShutdown);
} catch (Throwable t) {
ActiveMQServerLogger.LOGGER.errorStoppingComponent(t, storageManager.getClass().getName());
}
// error shutdown
if (remotingService != null)
try {
remotingService.stop(criticalIOError);
} catch (Throwable t) {
ActiveMQServerLogger.LOGGER.errorStoppingComponent(t, remotingService.getClass().getName());
}
// Stop the management service after the remoting service to ensure all acceptors are deregistered with JMX
if (managementService != null)
try {
managementService.unregisterServer();
} catch (Throwable t) {
ActiveMQServerLogger.LOGGER.errorStoppingComponent(t, managementService.getClass().getName());
}
stopComponent(managementService);
stopComponent(resourceManager);
stopComponent(postOffice);
if (scheduledPool != null && !scheduledPoolSupplied) {
// we just interrupt all running tasks, these are supposed to be pings and the like.
scheduledPool.shutdownNow();
}
stopComponent(memoryManager);
for (SecuritySettingPlugin securitySettingPlugin : configuration.getSecuritySettingPlugins()) {
securitySettingPlugin.stop();
}
if (threadPool != null && !threadPoolSupplied) {
shutdownPool(threadPool);
}
if (ioExecutorPool != null) {
shutdownPool(ioExecutorPool);
}
if (!threadPoolSupplied)
threadPool = null;
if (!scheduledPoolSupplied)
scheduledPool = null;
if (securityStore != null) {
try {
securityStore.stop();
} catch (Throwable t) {
ActiveMQServerLogger.LOGGER.errorStoppingComponent(t, managementService.getClass().getName());
}
}
pagingManager = null;
securityStore = null;
resourceManager = null;
postOffice = null;
queueFactory = null;
resourceManager = null;
messagingServerControl = null;
memoryManager = null;
backupManager = null;
storageManager = null;
sessions.clear();
activateCallbacks.clear();
state = SERVER_STATE.STOPPED;
activationLatch.setCount(1);
// to display in the log message
SimpleString tempNodeID = getNodeID();
if (activation != null) {
try {
activation.close(failoverOnServerShutdown, restarting);
} catch (Throwable t) {
ActiveMQServerLogger.LOGGER.errorStoppingComponent(t, activation.getClass().getName());
}
}
if (activationThread != null) {
try {
activationThread.join(30000);
} catch (InterruptedException e) {
ActiveMQServerLogger.LOGGER.interruptWhilstStoppingComponent(activationThread.getClass().getName());
}
if (activationThread.isAlive()) {
ActiveMQServerLogger.LOGGER.activationDidntFinish(this);
activationThread.interrupt();
}
}
stopComponent(nodeManager);
nodeManager = null;
addressSettingsRepository.clearListeners();
addressSettingsRepository.clearCache();
scaledDownNodeIDs.clear();
for (ActiveMQComponent externalComponent : externalComponents) {
try {
if (externalComponent instanceof ServiceComponent) {
((ServiceComponent) externalComponent).stop(isShutdown);
} else {
externalComponent.stop();
}
} catch (Exception e) {
ActiveMQServerLogger.LOGGER.errorStoppingComponent(e, externalComponent.getClass().getName());
}
}
try {
this.analyzer.stop();
} catch (Exception e) {
logger.warn(e.getMessage(), e);
} finally {
this.analyzer = null;
}
if (identity != null) {
ActiveMQServerLogger.LOGGER.serverStopped("identity=" + identity + ",version=" + getVersion().getFullVersion(), tempNodeID, getUptime());
} else {
ActiveMQServerLogger.LOGGER.serverStopped(getVersion().getFullVersion(), tempNodeID, getUptime());
}
}
use of org.apache.activemq.artemis.core.server.ActiveMQComponent in project activemq-artemis by apache.
the class DiscoveryTest method tearDown.
@Override
@After
public void tearDown() throws Exception {
JChannelManager.getInstance().clear().setLoopbackMessages(false);
/**
* This file path is defined at {@link #TEST_JGROUPS_CONF_FILE}
*/
deleteDirectory(new File("./target/tmp/amqtest.ping.dir"));
for (ActiveMQComponent component : new ActiveMQComponent[] { bg, bg1, bg2, bg3, dg, dg1, dg2, dg3 }) {
stopComponent(component);
}
super.tearDown();
}
use of org.apache.activemq.artemis.core.server.ActiveMQComponent in project activemq-artemis by apache.
the class NettyAcceptorTest method testStartStop.
@Test
public void testStartStop() throws Exception {
BufferHandler handler = new BufferHandler() {
@Override
public void bufferReceived(final Object connectionID, final ActiveMQBuffer buffer) {
}
};
Map<String, Object> params = new HashMap<>();
ServerConnectionLifeCycleListener listener = new ServerConnectionLifeCycleListener() {
@Override
public void connectionException(final Object connectionID, final ActiveMQException me) {
}
@Override
public void connectionDestroyed(final Object connectionID) {
}
@Override
public void connectionCreated(final ActiveMQComponent component, final Connection connection, final ProtocolManager protocol) {
}
@Override
public void connectionReadyForWrites(Object connectionID, boolean ready) {
}
};
pool2 = Executors.newScheduledThreadPool(ActiveMQDefaultConfiguration.getDefaultScheduledThreadPoolMaxSize(), ActiveMQThreadFactory.defaultThreadFactory());
NettyAcceptor acceptor = new NettyAcceptor("netty", null, params, handler, listener, pool2, new HashMap<String, ProtocolManager>());
addActiveMQComponent(acceptor);
acceptor.start();
Assert.assertTrue(acceptor.isStarted());
acceptor.stop();
Assert.assertFalse(acceptor.isStarted());
ActiveMQTestBase.checkFreePort(TransportConstants.DEFAULT_PORT);
acceptor.start();
Assert.assertTrue(acceptor.isStarted());
acceptor.stop();
Assert.assertFalse(acceptor.isStarted());
ActiveMQTestBase.checkFreePort(TransportConstants.DEFAULT_PORT);
pool2.shutdown();
pool2.awaitTermination(1, TimeUnit.SECONDS);
}
Aggregations