Search in sources :

Example 1 with Module

use of org.jivesoftware.openfire.container.Module in project Openfire by igniterealtime.

the class XMPPServer method shutdownServer.

/**
 * Makes a best effort attempt to shutdown the server
 */
private void shutdownServer() {
    shuttingDown = true;
    if (terminatorTimer != null) {
        terminatorTimer.cancel();
    }
    ClusterManager.shutdown();
    // Notify server listeners that the server is about to be stopped
    for (XMPPServerListener listener : listeners) {
        try {
            listener.serverStopping();
        } catch (Exception ex) {
            logger.error("Exception during listener shutdown", ex);
        }
    }
    // If we don't have modules then the server has already been shutdown
    if (modules.isEmpty()) {
        return;
    }
    // Stop all plugins
    logger.info("Shutting down plugins ...");
    if (pluginManager != null) {
        try {
            pluginManager.shutdown();
        } catch (Exception ex) {
            logger.error("Exception during plugin shutdown", ex);
        }
    }
    logger.info("Shutting down " + modules.size() + " modules ...");
    final SimpleTimeLimiter timeLimiter = SimpleTimeLimiter.create(Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setDaemon(true).setNameFormat("shutdown-thread-%d").build()));
    // OF-1996" Get all modules and stop and destroy them. Do this in the reverse order in which the were created.
    // This ensures that the 'most important' / core modules are shut down last, giving other modules the
    // opportunity to make use of their functionality during their shutdown (eg: MUC wants to send messages during
    // shutdown).
    final List<Class> reverseInsertionOrder = new ArrayList<>(modules.keySet());
    Collections.reverse(reverseInsertionOrder);
    for (final Class moduleClass : reverseInsertionOrder) {
        final Module module = modules.get(moduleClass);
        try {
            // OF-1607: Apply a configurable timeout to the duration of stop/destroy invocation.
            timeLimiter.runWithTimeout(() -> {
                stopAndDestroyModule(module);
            }, JiveGlobals.getLongProperty("shutdown.modules.timeout-millis", Long.MAX_VALUE), TimeUnit.MILLISECONDS);
        } catch (Exception e) {
            logger.warn("An exception occurred while stopping / destroying module '{}'.", module.getName(), e);
            System.err.println(e);
        }
    }
    modules.clear();
    // Stop the Db connection manager.
    try {
        DbConnectionManager.destroyConnectionProvider();
    } catch (Exception ex) {
        logger.error("Exception during DB shutdown", ex);
    }
    // Shutdown the task engine.
    TaskEngine.getInstance().shutdown();
    // hack to allow safe stopping
    logger.info("Openfire stopped");
    // Shut down the logging framework (causing the last few log entries to be flushed)
    LogManager.shutdown();
}
Also used : CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) PubSubModule(org.jivesoftware.openfire.pubsub.PubSubModule) Module(org.jivesoftware.openfire.container.Module) SimpleTimeLimiter(com.google.common.util.concurrent.SimpleTimeLimiter) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with Module

use of org.jivesoftware.openfire.container.Module in project Openfire by igniterealtime.

the class XMPPServer method startModules.

/**
 * <p>Following the loading and initialization of all the modules
 * this method is called to iterate through the known modules and
 * start them.</p>
 */
private void startModules() {
    for (Module module : modules.values()) {
        try {
            logger.debug("Starting module: " + module.getName());
            module.start();
        } catch (Exception e) {
            logger.error("An exception occurred while starting module '{}'.", module.getName(), e);
        }
    }
}
Also used : PubSubModule(org.jivesoftware.openfire.pubsub.PubSubModule) Module(org.jivesoftware.openfire.container.Module) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) FileNotFoundException(java.io.FileNotFoundException)

Example 3 with Module

use of org.jivesoftware.openfire.container.Module in project Openfire by igniterealtime.

the class XMPPServer method loadModule.

/**
 * Loads a module.
 *
 * @param module the name of the class that implements the Module interface.
 */
private void loadModule(String module) {
    try {
        Class<Module> modClass = (Class<Module>) loader.loadClass(module);
        Module mod = modClass.newInstance();
        this.modules.put(modClass, mod);
    } catch (Exception e) {
        e.printStackTrace();
        logger.error(LocaleUtils.getLocalizedString("admin.error"), e);
    }
}
Also used : PubSubModule(org.jivesoftware.openfire.pubsub.PubSubModule) Module(org.jivesoftware.openfire.container.Module) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 UnknownHostException (java.net.UnknownHostException)3 Module (org.jivesoftware.openfire.container.Module)3 PubSubModule (org.jivesoftware.openfire.pubsub.PubSubModule)3 SimpleTimeLimiter (com.google.common.util.concurrent.SimpleTimeLimiter)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1