Search in sources :

Example 1 with ServiceComponent

use of org.apache.activemq.artemis.core.server.ServiceComponent 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());
    }
}
Also used : ActiveMQComponent(org.apache.activemq.artemis.core.server.ActiveMQComponent) ServiceComponent(org.apache.activemq.artemis.core.server.ServiceComponent) SecuritySettingPlugin(org.apache.activemq.artemis.core.server.SecuritySettingPlugin) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) IOException(java.io.IOException) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) ActiveMQDeleteAddressException(org.apache.activemq.artemis.api.core.ActiveMQDeleteAddressException)

Example 2 with ServiceComponent

use of org.apache.activemq.artemis.core.server.ServiceComponent in project activemq-artemis by apache.

the class ReplicatedFailoverTest method testReplicatedFailbackBackupFromLiveBackToBackup.

@Test
public void testReplicatedFailbackBackupFromLiveBackToBackup() throws Exception {
    InetSocketAddress address = new InetSocketAddress("127.0.0.1", 8787);
    HttpServer httpServer = HttpServer.create(address, 100);
    httpServer.start();
    try {
        httpServer.createContext("/", new HttpHandler() {

            @Override
            public void handle(HttpExchange t) throws IOException {
                String response = "<html><body><b>This is a unit test</b></body></html>";
                t.sendResponseHeaders(200, response.length());
                OutputStream os = t.getResponseBody();
                os.write(response.getBytes());
                os.close();
            }
        });
        WebServerDTO wdto = new WebServerDTO();
        AppDTO appDTO = new AppDTO();
        appDTO.war = "console.war";
        appDTO.url = "console";
        wdto.apps = new ArrayList<AppDTO>();
        wdto.apps.add(appDTO);
        wdto.bind = "http://localhost:0";
        wdto.path = "console";
        WebServerComponent webServerComponent = new WebServerComponent();
        webServerComponent.configure(wdto, ".", ".");
        webServerComponent.start();
        backupServer.getServer().getNetworkHealthCheck().parseURIList("http://localhost:8787");
        Assert.assertTrue(backupServer.getServer().getNetworkHealthCheck().isStarted());
        backupServer.getServer().addExternalComponent(webServerComponent);
        // this is called when backup servers go from live back to backup
        backupServer.getServer().fail(true);
        Assert.assertTrue(backupServer.getServer().getNetworkHealthCheck().isStarted());
        Assert.assertTrue(backupServer.getServer().getExternalComponents().get(0).isStarted());
        ((ServiceComponent) (backupServer.getServer().getExternalComponents().get(0))).stop(true);
    } finally {
        httpServer.stop(0);
    }
}
Also used : HttpHandler(com.sun.net.httpserver.HttpHandler) ServiceComponent(org.apache.activemq.artemis.core.server.ServiceComponent) InetSocketAddress(java.net.InetSocketAddress) OutputStream(java.io.OutputStream) HttpExchange(com.sun.net.httpserver.HttpExchange) IOException(java.io.IOException) WebServerDTO(org.apache.activemq.artemis.dto.WebServerDTO) AppDTO(org.apache.activemq.artemis.dto.AppDTO) HttpServer(com.sun.net.httpserver.HttpServer) WebServerComponent(org.apache.activemq.artemis.component.WebServerComponent) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)2 ServiceComponent (org.apache.activemq.artemis.core.server.ServiceComponent)2 HttpExchange (com.sun.net.httpserver.HttpExchange)1 HttpHandler (com.sun.net.httpserver.HttpHandler)1 HttpServer (com.sun.net.httpserver.HttpServer)1 OutputStream (java.io.OutputStream)1 InetSocketAddress (java.net.InetSocketAddress)1 ActiveMQDeleteAddressException (org.apache.activemq.artemis.api.core.ActiveMQDeleteAddressException)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1 ActiveMQQueueExistsException (org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 WebServerComponent (org.apache.activemq.artemis.component.WebServerComponent)1 ActiveMQComponent (org.apache.activemq.artemis.core.server.ActiveMQComponent)1 SecuritySettingPlugin (org.apache.activemq.artemis.core.server.SecuritySettingPlugin)1 AppDTO (org.apache.activemq.artemis.dto.AppDTO)1 WebServerDTO (org.apache.activemq.artemis.dto.WebServerDTO)1 Test (org.junit.Test)1