XMPPServer.java 54.4 KB
Newer Older
1 2
/**
 *
3
 * Copyright (C) 2004-2008 Jive Software. All rights reserved.
4
 *
5 6 7 8 9 10 11 12 13 14 15
 * Licensed 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.
16 17
 */

18
package org.jivesoftware.openfire;
19 20

import org.dom4j.Document;
21 22
import org.dom4j.Element;
import org.dom4j.Node;
23 24
import org.dom4j.io.SAXReader;
import org.jivesoftware.database.DbConnectionManager;
25
import org.jivesoftware.openfire.admin.AdminManager;
26 27
import org.jivesoftware.openfire.audit.AuditManager;
import org.jivesoftware.openfire.audit.spi.AuditManagerImpl;
28
import org.jivesoftware.openfire.auth.ScramUtils;
29
import org.jivesoftware.openfire.cluster.ClusterManager;
30
import org.jivesoftware.openfire.cluster.NodeID;
31 32 33 34 35
import org.jivesoftware.openfire.commands.AdHocCommandHandler;
import org.jivesoftware.openfire.component.InternalComponentManager;
import org.jivesoftware.openfire.container.AdminConsolePlugin;
import org.jivesoftware.openfire.container.Module;
import org.jivesoftware.openfire.container.PluginManager;
36
import org.jivesoftware.openfire.disco.*;
37 38 39
import org.jivesoftware.openfire.filetransfer.DefaultFileTransferManager;
import org.jivesoftware.openfire.filetransfer.FileTransferManager;
import org.jivesoftware.openfire.filetransfer.proxy.FileTransferProxy;
40 41 42
import org.jivesoftware.openfire.handler.*;
import org.jivesoftware.openfire.keystore.IdentityStoreConfig;
import org.jivesoftware.openfire.keystore.Purpose;
43
import org.jivesoftware.openfire.lockout.LockOutManager;
44
import org.jivesoftware.openfire.mediaproxy.MediaProxyService;
45
import org.jivesoftware.openfire.muc.MultiUserChatManager;
46 47
import org.jivesoftware.openfire.net.SSLConfig;
import org.jivesoftware.openfire.net.ServerTrafficCounter;
48
import org.jivesoftware.openfire.pep.IQPEPHandler;
49 50
import org.jivesoftware.openfire.pubsub.PubSubModule;
import org.jivesoftware.openfire.roster.RosterManager;
51
import org.jivesoftware.openfire.session.RemoteSessionLocator;
52
import org.jivesoftware.openfire.spi.XMPPServerInfoImpl;
53 54 55 56
import org.jivesoftware.openfire.transport.TransportHandler;
import org.jivesoftware.openfire.update.UpdateManager;
import org.jivesoftware.openfire.user.UserManager;
import org.jivesoftware.openfire.vcard.VCardManager;
57
import org.jivesoftware.util.*;
58
import org.jivesoftware.util.cache.CacheFactory;
59 60
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
61 62
import org.xmpp.packet.JID;

63 64 65 66 67 68 69 70 71 72
import java.io.*;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;

73 74 75
/**
 * The main XMPP server that will load, initialize and start all the server's
 * modules. The server is unique in the JVM and could be obtained by using the
76 77
 * {@link #getInstance()} method.
 * <p>
78 79
 * The loaded modules will be initialized and may access through the server other
 * modules. This means that the only way for a module to locate another module is
80 81 82
 * through the server. The server maintains a list of loaded modules.
 * </p>
 * <p>
83
 * After starting up all the modules the server will load any available plugin.
84 85 86
 * For more information see: {@link org.jivesoftware.openfire.container.PluginManager}.
 * </p>
 * <p>A configuration file keeps the server configuration. This information is required for the
87
 * server to work correctly. The server assumes that the configuration file is named
88
 * <b>openfire.xml</b> and is located in the <b>conf</b> folder. The folder that keeps
89
 * the configuration file must be located under the home folder. The server will try different
90
 * methods to locate the home folder.</p>
91
 * <ol>
92
 * <li><b>system property</b> - The server will use the value defined in the <i>openfireHome</i>
93 94 95
 * system property.</li>
 * <li><b>working folder</b> -  The server will check if there is a <i>conf</i> folder in the
 * working directory. This is the case when running in standalone mode.</li>
96
 * <li><b>openfire_init.xml file</b> - Attempt to load the value from openfire_init.xml which
97
 * must be in the classpath</li>
98 99 100 101 102 103
 * </ol>
 *
 * @author Gaston Dombiak
 */
public class XMPPServer {

104
	private static final Logger logger = LoggerFactory.getLogger(XMPPServer.class);
105

106 107 108
    private static XMPPServer instance;

    private String name;
109
    private String host;
110 111 112
    private Version version;
    private Date startDate;
    private boolean initialized = false;
113
    private boolean started = false;
114
    private NodeID nodeID;
115
    private static final NodeID DEFAULT_NODE_ID = NodeID.getInstance(new byte[0]);
116

117 118
    public static final String EXIT = "exit";

119 120 121
    /**
     * All modules loaded by this server
     */
122
    private Map<String, Module> modules = new LinkedHashMap<>();
123

124 125 126
    /**
     * Listeners that will be notified when the server has started or is about to be stopped.
     */
127
    private List<XMPPServerListener> listeners = new CopyOnWriteArrayList<>();
128

129 130 131 132
    /**
     * Location of the home directory. All configuration files should be
     * located here.
     */
133
    private File openfireHome;
134 135 136 137
    private ClassLoader loader;

    private PluginManager pluginManager;
    private InternalComponentManager componentManager;
138
    private RemoteSessionLocator remoteSessionLocator;
139 140 141 142 143 144 145

    /**
     * True if in setup mode
     */
    private boolean setupMode = true;

    private static final String STARTER_CLASSNAME =
146
            "org.jivesoftware.openfire.starter.ServerStarter";
147 148
    private static final String WRAPPER_CLASSNAME =
            "org.tanukisoftware.wrapper.WrapperManager";
149
    private boolean shuttingDown;
Gaston Dombiak's avatar
Gaston Dombiak committed
150
    private XMPPServerInfoImpl xmppServerInfo;
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181

    /**
     * Returns a singleton instance of XMPPServer.
     *
     * @return an instance.
     */
    public static XMPPServer getInstance() {
        return instance;
    }

    /**
     * Creates a server and starts it.
     */
    public XMPPServer() {
        // We may only have one instance of the server running on the JVM
        if (instance != null) {
            throw new IllegalStateException("A server is already running");
        }
        instance = this;
        start();
    }

    /**
     * Returns a snapshot of the server's status.
     *
     * @return the server information current at the time of the method call.
     */
    public XMPPServerInfo getServerInfo() {
        if (!initialized) {
            throw new IllegalStateException("Not initialized yet");
        }
Gaston Dombiak's avatar
Gaston Dombiak committed
182
        return xmppServerInfo;
183 184 185 186 187 188 189 190 191 192 193 194
    }

    /**
     * Returns true if the given address is local to the server (managed by this
     * server domain). Return false even if the jid's domain matches a local component's
     * service JID.
     *
     * @param jid the JID to check.
     * @return true if the address is a local address to this server.
     */
    public boolean isLocal(JID jid) {
        boolean local = false;
195
        if (jid != null && name != null && name.equals(jid.getDomain())) {
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
            local = true;
        }
        return local;
    }

    /**
     * Returns true if the given address does not match the local server hostname and does not
     * match a component service JID.
     *
     * @param jid the JID to check.
     * @return true if the given address does not match the local server hostname and does not
     *         match a component service JID.
     */
    public boolean isRemote(JID jid) {
        if (jid != null) {
211
            if (!name.equals(jid.getDomain()) && !componentManager.hasComponent(jid)) {
212 213 214 215 216 217
                return true;
            }
        }
        return false;
    }

Gaston Dombiak's avatar
Gaston Dombiak committed
218 219 220 221 222 223 224
    /**
     * Returns an ID that uniquely identifies this server in a cluster. When not running in cluster mode
     * the returned value is always the same. However, when in cluster mode the value should be set
     * when joining the cluster and must be unique even upon restarts of this node.
     *
     * @return an ID that uniquely identifies this server in a cluster.
     */
225
    public NodeID getNodeID() {
226
        return nodeID == null ? DEFAULT_NODE_ID : nodeID;
Gaston Dombiak's avatar
Gaston Dombiak committed
227 228 229 230 231 232 233 234 235
    }

    /**
     * Sets an ID that uniquely identifies this server in a cluster. When not running in cluster mode
     * the returned value is always the same. However, when in cluster mode the value should be set
     * when joining the cluster and must be unique even upon restarts of this node.
     *
     * @param nodeID an ID that uniquely identifies this server in a cluster or null if not in a cluster.
     */
236
    public void setNodeID(NodeID nodeID) {
Gaston Dombiak's avatar
Gaston Dombiak committed
237 238 239
        this.nodeID = nodeID;
    }

240 241 242 243 244 245 246
    /**
     * Returns true if the given address matches a component service JID.
     *
     * @param jid the JID to check.
     * @return true if the given address matches a component service JID.
     */
    public boolean matchesComponent(JID jid) {
247
        return jid != null && !name.equals(jid.getDomain()) && componentManager.hasComponent(jid);
248 249 250 251 252 253 254 255 256 257 258 259 260
    }

    /**
     * Creates an XMPPAddress local to this server.
     *
     * @param username the user name portion of the id or null to indicate none is needed.
     * @param resource the resource portion of the id or null to indicate none is needed.
     * @return an XMPPAddress for the server.
     */
    public JID createJID(String username, String resource) {
        return new JID(username, name, resource);
    }

261 262 263 264 265 266 267 268 269 270 271 272 273
    /**
     * Creates an XMPPAddress local to this server. The construction of the new JID
     * can be optimized by skipping stringprep operations.
     *
     * @param username the user name portion of the id or null to indicate none is needed.
     * @param resource the resource portion of the id or null to indicate none is needed.
     * @param skipStringprep true if stringprep should not be applied.
     * @return an XMPPAddress for the server.
     */
    public JID createJID(String username, String resource, boolean skipStringprep) {
        return new JID(username, name, resource, skipStringprep);
    }

274 275 276 277 278 279 280
    /**
     * Returns a collection with the JIDs of the server's admins. The collection may include
     * JIDs of local users and users of remote servers.
     *
     * @return a collection with the JIDs of the server's admins.
     */
    public Collection<JID> getAdmins() {
281
        return AdminManager.getInstance().getAdminAccounts();
282 283
    }

284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
    /**
     * Adds a new server listener that will be notified when the server has been started
     * or is about to be stopped.
     *
     * @param listener the new server listener to add.
     */
    public void addServerListener(XMPPServerListener listener) {
        listeners.add(listener);
    }

    /**
     * Removes a server listener that was being notified when the server was being started
     * or was about to be stopped.
     *
     * @param listener the server listener to remove.
     */
    public void removeServerListener(XMPPServerListener listener) {
        listeners.remove(listener);
    }

304
    private void initialize() throws FileNotFoundException {
305
        locateOpenfire();
306

307 308
        startDate = new Date();

309 310 311 312
        try {
            host = InetAddress.getLocalHost().getHostName();
        }
        catch (UnknownHostException ex) {
313
            logger.warn("Unable to determine local hostname.", ex);
314 315 316
        }
        if (host == null) {
            host = "127.0.0.1";        	
317 318
        }

319
        version = new Version(3, 11, 0, Version.ReleaseStatus.Alpha, -1);
320 321 322 323 324
        if ("true".equals(JiveGlobals.getXMLProperty("setup"))) {
            setupMode = false;
        }

        if (isStandAlone()) {
325
        	logger.info("Registering shutdown hook (standalone mode)");
326
            Runtime.getRuntime().addShutdownHook(new ShutdownHookThread());
327
            TaskEngine.getInstance().schedule(new Terminator(), 1000, 1000);
328 329 330 331
        }

        loader = Thread.currentThread().getContextClassLoader();

332 333 334 335
        try {
            CacheFactory.initialize();
        } catch (InitializationException e) {
            e.printStackTrace();
336
            logger.error(e.getMessage(), e);
337 338
        }

339 340 341
        JiveGlobals.migrateProperty("xmpp.domain");
        name = JiveGlobals.getProperty("xmpp.domain", host).toLowerCase();

342 343
        JiveGlobals.migrateProperty(Log.LOG_DEBUG_ENABLED);
        Log.setDebugEnabled(JiveGlobals.getBooleanProperty(Log.LOG_DEBUG_ENABLED, false));
344
        
345 346 347
        // Update server info
        xmppServerInfo = new XMPPServerInfoImpl(name, host, version, startDate);

348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
        initialized = true;
    }

    /**
     * Finish the setup process. Because this method is meant to be called from inside
     * the Admin console plugin, it spawns its own thread to do the work so that the
     * class loader is correct.
     */
    public void finishSetup() {
        if (!setupMode) {
            return;
        }
        // Make sure that setup finished correctly.
        if ("true".equals(JiveGlobals.getXMLProperty("setup"))) {
            // Set the new server domain assigned during the setup process
363
            name = JiveGlobals.getProperty("xmpp.domain").toLowerCase();
Jay Kline's avatar
Jay Kline committed
364
            xmppServerInfo.setXMPPDomain(name);
365

366 367
            // Iterate through all the provided XML properties and set the ones that haven't
            // already been touched by setup prior to this method being called.
368
            for (String propName : JiveGlobals.getXMLPropertyNames()) {
369 370 371 372
                if (JiveGlobals.getProperty(propName) == null) {
                    JiveGlobals.setProperty(propName, JiveGlobals.getXMLProperty(propName));
                }
            }
373 374
            // Set default SASL SCRAM-SHA-1 iteration count
            JiveGlobals.setProperty("sasl.scram-sha-1.iteration-count", Integer.toString(ScramUtils.DEFAULT_ITERATION_COUNT));
375

376 377 378
            // Update certificates (if required)
            try {
                // Check if keystore already has certificates for current domain
379 380
                final IdentityStoreConfig storeConfig = (IdentityStoreConfig) SSLConfig.getInstance().getStoreConfig( Purpose.SOCKETBASED_IDENTITYSTORE );
                storeConfig.ensureDomainCertificates( "DSA", "RSA" );
381
            } catch (Exception e) {
382
                logger.error("Error generating self-signed certificates", e);
383 384
            }

385 386 387
            // Initialize list of admins now (before we restart Jetty)
            AdminManager.getInstance().getAdminAccounts();

388
            Thread finishSetup = new Thread() {
389 390
                @Override
				public void run() {
391 392
                    try {
                        if (isStandAlone()) {
393 394 395 396 397 398 399
                            // Always restart the HTTP server manager. This covers the case
                            // of changing the ports, as well as generating self-signed certificates.
                        
                            // Wait a short period before shutting down the admin console.
                            // Otherwise, the page that requested the setup finish won't
                            // render properly!
                            Thread.sleep(1000);
Matt Tucker's avatar
Matt Tucker committed
400 401 402
                            ((AdminConsolePlugin) pluginManager.getPlugin("admin")).restart();
//                            ((AdminConsolePlugin) pluginManager.getPlugin("admin")).shutdown();
//                            ((AdminConsolePlugin) pluginManager.getPlugin("admin")).startup();
403 404 405 406 407 408 409 410 411 412 413 414 415
                        }

                        verifyDataSource();
                        // First load all the modules so that modules may access other modules while
                        // being initialized
                        loadModules();
                        // Initize all the modules
                        initModules();
                        // Start all the modules
                        startModules();
                    }
                    catch (Exception e) {
                        e.printStackTrace();
416
                        logger.error(e.getMessage(), e);
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
                        shutdownServer();
                    }
                }
            };
            // Use the correct class loader.
            finishSetup.setContextClassLoader(loader);
            finishSetup.start();
            // We can now safely indicate that setup has finished
            setupMode = false;
        }
    }

    public void start() {
        try {
            initialize();

433
            // Create PluginManager now (but don't start it) so that modules may use it
434
            File pluginDir = new File(openfireHome, "plugins");
435 436
            pluginManager = new PluginManager(pluginDir);

437 438 439 440 441 442 443 444 445 446 447
            // If the server has already been setup then we can start all the server's modules
            if (!setupMode) {
                verifyDataSource();
                // First load all the modules so that modules may access other modules while
                // being initialized
                loadModules();
                // Initize all the modules
                initModules();
                // Start all the modules
                startModules();
            }
448 449 450
            // Initialize statistics
            ServerTrafficCounter.initStatistics();

451 452 453 454
            // Load plugins (when in setup mode only the admin console will be loaded)
            pluginManager.start();

            // Log that the server has been started
Gaston Dombiak's avatar
Gaston Dombiak committed
455 456
            String startupBanner = LocaleUtils.getLocalizedString("short.title") + " " + version.getVersionString() +
                    " [" + JiveGlobals.formatDateTime(new Date()) + "]";
457
            logger.info(startupBanner);
458 459
            System.out.println(startupBanner);

460 461
            started = true;
            
462 463 464 465
            // Notify server listeners that the server has been started
            for (XMPPServerListener listener : listeners) {
                listener.serverStarted();
            }
466 467 468
        }
        catch (Exception e) {
            e.printStackTrace();
469
            logger.error(e.getMessage(), e);
470 471 472 473 474
            System.out.println(LocaleUtils.getLocalizedString("startup.error"));
            shutdownServer();
        }
    }

475 476
    @SuppressWarnings("unchecked")
	private void loadModules() {
477 478 479 480 481 482

        File modulesXml = new File(JiveGlobals.getHomeDirectory(), "conf/modules.xml");
        logger.info("Loading modules from " + modulesXml.getAbsolutePath());
        SAXReader xmlReader = new SAXReader();
        xmlReader.setEncoding("UTF-8");
    	try (FileReader in = new FileReader(modulesXml)) {
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498
            Document document = xmlReader.read(in);
            Element root = document.getRootElement();
            Iterator<Node> itr = root.nodeIterator();
            while (itr.hasNext()) {
            	Node n = itr.next();
            	if (n.getNodeType() == Element.ELEMENT_NODE && "module".equals(n.getName())) {
                	Element module = (Element)n;
                	logger.debug("Loading module " + module.attributeValue("implementation") + " to interface " + module.attributeValue("interface"));
                	loadModule(module.attributeValue("interface"), module.attributeValue("implementation"));
            	}
            }
    	} catch (Exception e) {
    		e.printStackTrace();
    		logger.error(LocaleUtils.getLocalizedString("admin.error"), e);
    	}
        
499 500
        // Keep a reference to the internal component manager
        componentManager = getComponentManager();
501 502 503 504 505
    }

    /**
     * Loads a module.
     *
506
     * @param moduleName the name of the class that implements the Module interface.
507
     */
508 509
    @SuppressWarnings("unchecked")
	private void loadModule(String moduleName, String moduleImpl) {
510
        try {
511 512 513
            Class<Module> modClass = (Class<Module>) loader.loadClass(moduleImpl);
            Module mod = modClass.newInstance();
            this.modules.put(moduleName, mod);
514 515 516
        }
        catch (Exception e) {
            e.printStackTrace();
517
            logger.error(LocaleUtils.getLocalizedString("admin.error"), e);
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535
        }
    }

    private void initModules() {
        for (Module module : modules.values()) {
            boolean isInitialized = false;
            try {
                module.initialize(this);
                isInitialized = true;
            }
            catch (Exception e) {
                e.printStackTrace();
                // Remove the failed initialized module
                this.modules.remove(module.getClass());
                if (isInitialized) {
                    module.stop();
                    module.destroy();
                }
536
                logger.error(LocaleUtils.getLocalizedString("admin.error"), e);
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556
            }
        }
    }

    /**
     * <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()) {
            boolean started = false;
            try {
                module.start();
            }
            catch (Exception e) {
                if (started && module != null) {
                    module.stop();
                    module.destroy();
                }
557
                logger.error(LocaleUtils.getLocalizedString("admin.error"), e);
558 559 560 561 562 563 564 565 566 567 568
            }
        }
    }

    /**
     * Restarts the server and all it's modules only if the server is restartable. Otherwise do
     * nothing.
     */
    public void restart() {
        if (isStandAlone() && isRestartable()) {
            try {
569
                Class<?> wrapperClass = Class.forName(WRAPPER_CLASSNAME);
570 571
                Method restartMethod = wrapperClass.getMethod("restart", (Class []) null);
                restartMethod.invoke(null, (Object []) null);
572 573
            }
            catch (Exception e) {
574
                logger.error("Could not restart container", e);
575 576 577 578
            }
        }
    }

579
    /**
580 581 582 583
     * Restarts the HTTP server only when running in stand alone mode. The restart
     * process will be done in another thread that will wait 1 second before doing
     * the actual restart. The delay will give time to the page that requested the
     * restart to fully render its content.
584 585 586
     */
    public void restartHTTPServer() {
        Thread restartThread = new Thread() {
587 588
            @Override
			public void run() {
589 590 591 592 593 594 595 596
                if (isStandAlone()) {
                    // Restart the HTTP server manager. This covers the case
                    // of changing the ports, as well as generating self-signed certificates.

                    // Wait a short period before shutting down the admin console.
                    // Otherwise, this page won't render properly!
                    try {
                        Thread.sleep(1000);
597 598
                        ((AdminConsolePlugin) pluginManager.getPlugin("admin")).shutdown();
                        ((AdminConsolePlugin) pluginManager.getPlugin("admin")).startup();
599 600 601 602 603 604 605 606 607 608
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        restartThread.setContextClassLoader(loader);
        restartThread.start();
    }

609 610 611 612 613
    /**
     * Stops the server only if running in standalone mode. Do nothing if the server is running
     * inside of another server.
     */
    public void stop() {
614
    	logger.info("Initiating shutdown ...");
615 616 617 618 619
        // Only do a system exit if we're running standalone
        if (isStandAlone()) {
            // if we're in a wrapper, we have to tell the wrapper to shut us down
            if (isRestartable()) {
                try {
620
                    Class<?> wrapperClass = Class.forName(WRAPPER_CLASSNAME);
621 622
                    Method stopMethod = wrapperClass.getMethod("stop", Integer.TYPE);
                    stopMethod.invoke(null, 0);
623 624
                }
                catch (Exception e) {
625
                    logger.error("Could not stop container", e);
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646
                }
            }
            else {
                shutdownServer();
                Thread shutdownThread = new ShutdownThread();
                shutdownThread.setDaemon(true);
                shutdownThread.start();
            }
        }
        else {
            // Close listening socket no matter what the condition is in order to be able
            // to be restartable inside a container.
            shutdownServer();
        }
    }

    public boolean isSetupMode() {
        return setupMode;
    }

    public boolean isRestartable() {
647
        boolean restartable;
648 649 650 651 652 653 654 655 656 657 658
        try {
            restartable = Class.forName(WRAPPER_CLASSNAME) != null;
        }
        catch (ClassNotFoundException e) {
            restartable = false;
        }
        return restartable;
    }

    /**
     * Returns if the server is running in standalone mode. We consider that it's running in
659
     * standalone if the "org.jivesoftware.openfire.starter.ServerStarter" class is present in the
660 661 662 663 664
     * system.
     *
     * @return true if the server is running in standalone mode.
     */
    public boolean isStandAlone() {
665
        boolean standalone;
666 667 668 669 670 671 672 673 674 675 676 677 678
        try {
            standalone = Class.forName(STARTER_CLASSNAME) != null;
        }
        catch (ClassNotFoundException e) {
            standalone = false;
        }
        return standalone;
    }

    /**
     * Verify that the database is accessible.
     */
    private void verifyDataSource() {
679 680 681
        Connection con = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
682
        try {
683 684 685
            con = DbConnectionManager.getConnection();
            pstmt = con.prepareStatement("SELECT count(*) FROM ofID");
            rs = pstmt.executeQuery();
686 687 688 689 690 691
            rs.next();
        }
        catch (Exception e) {
            System.err.println("Database setup or configuration error: " +
                    "Please verify your database settings and check the " +
                    "logs/error.log file for detailed error messages.");
692
            logger.error("Database could not be accessed", e);
693 694 695
            throw new IllegalArgumentException(e);
        }
        finally {
696
            DbConnectionManager.closeConnection(rs, pstmt, con);
697 698 699 700
        }
    }

    /**
701 702
     * Verifies that the given home guess is a real Openfire home directory.
     * We do the verification by checking for the Openfire config file in
703 704
     * the config dir of jiveHome.
     *
705
     * @param homeGuess a guess at the path to the home directory.
706 707 708 709
     * @param jiveConfigName the name of the config file to check.
     * @return a file pointing to the home directory or null if the
     *         home directory guess was wrong.
     * @throws java.io.FileNotFoundException if there was a problem with the home
710
     *                                       directory provided
711 712
     */
    private File verifyHome(String homeGuess, String jiveConfigName) throws FileNotFoundException {
713 714
        File openfireHome = new File(homeGuess);
        File configFile = new File(openfireHome, jiveConfigName);
715
        if (!configFile.exists()) {
716 717
            throw new FileNotFoundException();
        }
718 719
        else {
            try {
720
                return new File(openfireHome.getCanonicalPath());
721 722 723 724
            }
            catch (Exception ex) {
                throw new FileNotFoundException();
            }
725 726 727 728 729 730 731 732
        }
    }

    /**
     * <p>Retrieve the jive home for the container.</p>
     *
     * @throws FileNotFoundException If jiveHome could not be located
     */
733 734 735 736 737
    private void locateOpenfire() throws FileNotFoundException {
        String jiveConfigName = "conf" + File.separator + "openfire.xml";
        // First, try to load it openfireHome as a system property.
        if (openfireHome == null) {
            String homeProperty = System.getProperty("openfireHome");
738 739
            try {
                if (homeProperty != null) {
740
                    openfireHome = verifyHome(homeProperty, jiveConfigName);
741 742 743 744 745 746 747 748 749 750
                }
            }
            catch (FileNotFoundException fe) {
                // Ignore.
            }
        }

        // If we still don't have home, let's assume this is standalone
        // and just look for home in a standard sub-dir location and verify
        // by looking for the config file
751
        if (openfireHome == null) {
752
            try {
753
                openfireHome = verifyHome("..", jiveConfigName).getCanonicalFile();
754 755 756 757 758 759 760 761 762 763
            }
            catch (FileNotFoundException fe) {
                // Ignore.
            }
            catch (IOException ie) {
                // Ignore.
            }
        }

        // If home is still null, no outside process has set it and
764
        // we have to attempt to load the value from openfire_init.xml,
765
        // which must be in the classpath.
766
        if (openfireHome == null) {
767
            try (InputStream in = getClass().getResourceAsStream("/openfire_init.xml")) {
768 769 770 771 772 773
                if (in != null) {
                    SAXReader reader = new SAXReader();
                    Document doc = reader.read(in);
                    String path = doc.getRootElement().getText();
                    try {
                        if (path != null) {
774
                            openfireHome = verifyHome(path, jiveConfigName);
775 776 777 778 779 780 781 782
                        }
                    }
                    catch (FileNotFoundException fe) {
                        fe.printStackTrace();
                    }
                }
            }
            catch (Exception e) {
783
                System.err.println("Error loading openfire_init.xml to find home.");
784 785 786 787
                e.printStackTrace();
            }
        }

788
        if (openfireHome == null) {
789 790 791 792 793
            System.err.println("Could not locate home");
            throw new FileNotFoundException();
        }
        else {
            // Set the home directory for the config file
794
            JiveGlobals.setHomeDirectory(openfireHome.toString());
795 796 797 798 799
            // Set the name of the config file
            JiveGlobals.setConfigName(jiveConfigName);
        }
    }

800 801 802 803 804 805 806
    /**
     * This timer task is used to monitor the System input stream
     * for a "terminate" command from the launcher (or the console). 
     * This allows for a graceful shutdown when Openfire is started 
     * via the launcher, especially in Windows.
     */
    private class Terminator extends TimerTask {
807
    	private BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
808
    	@Override
809 810 811 812 813 814 815 816
    	public void run() {
        	try { 
        		if (stdin.ready()) {
            		if (EXIT.equalsIgnoreCase(stdin.readLine())) {
            			System.exit(0); // invokes shutdown hook(s)
            		}
        		}
        	} catch (IOException ioe) {
817
        		logger.error("Error reading console input", ioe);
818 819 820 821
        	}
    	}
    }
    
822 823 824 825 826 827 828 829
    /**
     * <p>A thread to ensure the server shuts down no matter what.</p>
     * <p>Spawned when stop() is called in standalone mode, we wait a few
     * seconds then call system exit().</p>
     *
     * @author Iain Shigeoka
     */
    private class ShutdownHookThread extends Thread {
830

831 832 833
        /**
         * <p>Logs the server shutdown.</p>
         */
834 835
        @Override
		public void run() {
836
            shutdownServer();
837
            logger.info("Server halted");
838 839 840 841 842 843 844 845 846 847 848 849
            System.err.println("Server halted");
        }
    }

    /**
     * <p>A thread to ensure the server shuts down no matter what.</p>
     * <p>Spawned when stop() is called in standalone mode, we wait a few
     * seconds then call system exit().</p>
     *
     * @author Iain Shigeoka
     */
    private class ShutdownThread extends Thread {
850

851 852 853
        /**
         * <p>Shuts down the JVM after a 5 second delay.</p>
         */
854 855
        @Override
		public void run() {
856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871
            try {
                Thread.sleep(5000);
                // No matter what, we make sure it's dead
                System.exit(0);
            }
            catch (InterruptedException e) {
                // Ignore.
            }

        }
    }

    /**
     * Makes a best effort attempt to shutdown the server
     */
    private void shutdownServer() {
872
        shuttingDown = true;
873
        ClusterManager.shutdown();
874 875
        // Notify server listeners that the server is about to be stopped
        for (XMPPServerListener listener : listeners) {
876 877 878
        	try {
        		listener.serverStopping();
        	} catch (Exception ex) {
879
        		logger.error("Exception during listener shutdown", ex);
880
        	}
881
        }
882 883 884 885
        // If we don't have modules then the server has already been shutdown
        if (modules.isEmpty()) {
            return;
        }
886
    	logger.info("Shutting down " + modules.size() + " modules ...");
887 888
        // Get all modules and stop and destroy them
        for (Module module : modules.values()) {
889 890 891 892
        	try {
	            module.stop();
	            module.destroy();
        	} catch (Exception ex) {
893
        		logger.error("Exception during module shutdown", ex);
894
        	}
895 896
        }
        // Stop all plugins
897
    	logger.info("Shutting down plugins ...");
898
        if (pluginManager != null) {
899 900 901
        	try {
        		pluginManager.shutdown();
        	} catch (Exception ex) {
902
        		logger.error("Exception during plugin shutdown", ex);
903
        	}
904
        }
905
        modules.clear();
906
        // Stop the Db connection manager.
907 908 909
        try {	
        	DbConnectionManager.destroyConnectionProvider();
        } catch (Exception ex) {
910
    		logger.error("Exception during DB shutdown", ex);
911
        }
912 913 914 915

        // Shutdown the task engine.
        TaskEngine.getInstance().shutdown();

916
        // hack to allow safe stopping
917
        logger.info("Openfire stopped");
918
    }
919
    
920 921 922 923 924 925 926 927 928
    /**
     * Returns true if the server is being shutdown.
     *
     * @return true if the server is being shutdown.
     */
    public boolean isShuttingDown() {
        return shuttingDown;
    }

929 930 931 932 933 934 935 936
    /**
     * Returns the <code>ConnectionManager</code> registered with this server. The
     * <code>ConnectionManager</code> was registered with the server as a module while starting up
     * the server.
     *
     * @return the <code>ConnectionManager</code> registered with this server.
     */
    public ConnectionManager getConnectionManager() {
937
        return (ConnectionManager) modules.get(ConnectionManager.class.getName());
938 939 940 941 942 943 944 945 946 947
    }

    /**
     * Returns the <code>RoutingTable</code> registered with this server. The
     * <code>RoutingTable</code> was registered with the server as a module while starting up
     * the server.
     *
     * @return the <code>RoutingTable</code> registered with this server.
     */
    public RoutingTable getRoutingTable() {
948
        return (RoutingTable) modules.get(RoutingTable.class.getName());
949 950 951 952 953 954 955 956 957 958
    }

    /**
     * Returns the <code>PacketDeliverer</code> registered with this server. The
     * <code>PacketDeliverer</code> was registered with the server as a module while starting up
     * the server.
     *
     * @return the <code>PacketDeliverer</code> registered with this server.
     */
    public PacketDeliverer getPacketDeliverer() {
959
        return (PacketDeliverer) modules.get(PacketDeliverer.class.getName());
960 961 962 963 964 965 966 967 968 969
    }

    /**
     * Returns the <code>RosterManager</code> registered with this server. The
     * <code>RosterManager</code> was registered with the server as a module while starting up
     * the server.
     *
     * @return the <code>RosterManager</code> registered with this server.
     */
    public RosterManager getRosterManager() {
970
        return (RosterManager) modules.get(RosterManager.class.getName());
971 972 973 974 975 976 977 978 979 980
    }

    /**
     * Returns the <code>PresenceManager</code> registered with this server. The
     * <code>PresenceManager</code> was registered with the server as a module while starting up
     * the server.
     *
     * @return the <code>PresenceManager</code> registered with this server.
     */
    public PresenceManager getPresenceManager() {
981
        return (PresenceManager) modules.get(PresenceManager.class.getName());
982 983 984 985 986 987 988 989 990 991
    }

    /**
     * Returns the <code>OfflineMessageStore</code> registered with this server. The
     * <code>OfflineMessageStore</code> was registered with the server as a module while starting up
     * the server.
     *
     * @return the <code>OfflineMessageStore</code> registered with this server.
     */
    public OfflineMessageStore getOfflineMessageStore() {
992
        return (OfflineMessageStore) modules.get(OfflineMessageStore.class.getName());
993 994 995 996 997 998 999 1000 1001 1002
    }

    /**
     * Returns the <code>OfflineMessageStrategy</code> registered with this server. The
     * <code>OfflineMessageStrategy</code> was registered with the server as a module while starting
     * up the server.
     *
     * @return the <code>OfflineMessageStrategy</code> registered with this server.
     */
    public OfflineMessageStrategy getOfflineMessageStrategy() {
1003
        return (OfflineMessageStrategy) modules.get(OfflineMessageStrategy.class.getName());
1004 1005 1006 1007 1008 1009 1010 1011 1012 1013
    }

    /**
     * Returns the <code>PacketRouter</code> registered with this server. The
     * <code>PacketRouter</code> was registered with the server as a module while starting up
     * the server.
     *
     * @return the <code>PacketRouter</code> registered with this server.
     */
    public PacketRouter getPacketRouter() {
1014
        return (PacketRouter) modules.get(PacketRouter.class.getName());
1015 1016 1017 1018 1019 1020 1021 1022 1023 1024
    }

    /**
     * Returns the <code>IQRegisterHandler</code> registered with this server. The
     * <code>IQRegisterHandler</code> was registered with the server as a module while starting up
     * the server.
     *
     * @return the <code>IQRegisterHandler</code> registered with this server.
     */
    public IQRegisterHandler getIQRegisterHandler() {
1025
        return (IQRegisterHandler) modules.get(IQRegisterHandler.class.getName());
1026 1027 1028 1029 1030 1031 1032 1033 1034 1035
    }

    /**
     * Returns the <code>IQAuthHandler</code> registered with this server. The
     * <code>IQAuthHandler</code> was registered with the server as a module while starting up
     * the server.
     *
     * @return the <code>IQAuthHandler</code> registered with this server.
     */
    public IQAuthHandler getIQAuthHandler() {
1036
        return (IQAuthHandler) modules.get(IQAuthHandler.class.getName());
1037
    }
1038 1039 1040 1041 1042 1043 1044 1045 1046
    
    /**
     * Returns the <code>IQPEPHandler</code> registered with this server. The
     * <code>IQPEPHandler</code> was registered with the server as a module while starting up
     * the server.
     *
     * @return the <code>IQPEPHandler</code> registered with this server.
     */
    public IQPEPHandler getIQPEPHandler() {
1047
        return (IQPEPHandler) modules.get(IQPEPHandler.class.getName());
1048
    }
1049 1050 1051 1052 1053 1054 1055 1056 1057

    /**
     * Returns the <code>PluginManager</code> instance registered with this server.
     *
     * @return the PluginManager instance.
     */
    public PluginManager getPluginManager() {
        return pluginManager;
    }
1058 1059 1060 1061 1062 1063 1064 1065 1066

    /**
     * Returns the <code>PubSubModule</code> registered with this server. The
     * <code>PubSubModule</code> was registered with the server as a module while starting up
     * the server.
     *
     * @return the <code>PubSubModule</code> registered with this server.
     */
    public PubSubModule getPubSubModule() {
1067
        return (PubSubModule) modules.get(PubSubModule.class.getName());
1068
    }
1069 1070 1071 1072 1073 1074 1075

    /**
     * Returns a list with all the modules registered with the server that inherit from IQHandler.
     *
     * @return a list with all the modules registered with the server that inherit from IQHandler.
     */
    public List<IQHandler> getIQHandlers() {
1076
        List<IQHandler> answer = new ArrayList<>();
1077 1078
        for (Module module : modules.values()) {
            if (module instanceof IQHandler) {
1079
                answer.add((IQHandler) module);
1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092
            }
        }
        return answer;
    }

    /**
     * Returns the <code>SessionManager</code> registered with this server. The
     * <code>SessionManager</code> was registered with the server as a module while starting up
     * the server.
     *
     * @return the <code>SessionManager</code> registered with this server.
     */
    public SessionManager getSessionManager() {
1093
        return (SessionManager) modules.get(SessionManager.class.getName());
1094 1095 1096 1097 1098 1099 1100 1101 1102 1103
    }

    /**
     * Returns the <code>TransportHandler</code> registered with this server. The
     * <code>TransportHandler</code> was registered with the server as a module while starting up
     * the server.
     *
     * @return the <code>TransportHandler</code> registered with this server.
     */
    public TransportHandler getTransportHandler() {
1104
        return (TransportHandler) modules.get(TransportHandler.class.getName());
1105 1106 1107 1108 1109 1110 1111 1112 1113 1114
    }

    /**
     * Returns the <code>PresenceUpdateHandler</code> registered with this server. The
     * <code>PresenceUpdateHandler</code> was registered with the server as a module while starting
     * up the server.
     *
     * @return the <code>PresenceUpdateHandler</code> registered with this server.
     */
    public PresenceUpdateHandler getPresenceUpdateHandler() {
1115
        return (PresenceUpdateHandler) modules.get(PresenceUpdateHandler.class.getName());
1116 1117 1118 1119 1120 1121 1122 1123 1124 1125
    }

    /**
     * Returns the <code>PresenceSubscribeHandler</code> registered with this server. The
     * <code>PresenceSubscribeHandler</code> was registered with the server as a module while
     * starting up the server.
     *
     * @return the <code>PresenceSubscribeHandler</code> registered with this server.
     */
    public PresenceSubscribeHandler getPresenceSubscribeHandler() {
1126
        return (PresenceSubscribeHandler) modules.get(PresenceSubscribeHandler.class.getName());
1127 1128 1129 1130 1131 1132 1133 1134 1135 1136
    }

    /**
     * Returns the <code>IQRouter</code> registered with this server. The
     * <code>IQRouter</code> was registered with the server as a module while starting up
     * the server.
     *
     * @return the <code>IQRouter</code> registered with this server.
     */
    public IQRouter getIQRouter() {
1137
        return (IQRouter) modules.get(IQRouter.class.getName());
1138 1139 1140 1141 1142 1143 1144 1145 1146 1147
    }

    /**
     * Returns the <code>MessageRouter</code> registered with this server. The
     * <code>MessageRouter</code> was registered with the server as a module while starting up
     * the server.
     *
     * @return the <code>MessageRouter</code> registered with this server.
     */
    public MessageRouter getMessageRouter() {
1148
        return (MessageRouter) modules.get(MessageRouter.class.getName());
1149 1150 1151 1152 1153 1154 1155 1156 1157 1158
    }

    /**
     * Returns the <code>PresenceRouter</code> registered with this server. The
     * <code>PresenceRouter</code> was registered with the server as a module while starting up
     * the server.
     *
     * @return the <code>PresenceRouter</code> registered with this server.
     */
    public PresenceRouter getPresenceRouter() {
1159
        return (PresenceRouter) modules.get(PresenceRouter.class.getName());
1160 1161
    }

1162 1163 1164 1165 1166 1167 1168 1169
    /**
     * Returns the <code>MulticastRouter</code> registered with this server. The
     * <code>MulticastRouter</code> was registered with the server as a module while starting up
     * the server.
     *
     * @return the <code>MulticastRouter</code> registered with this server.
     */
    public MulticastRouter getMulticastRouter() {
1170
        return (MulticastRouter) modules.get(MulticastRouter.class.getName());
1171 1172
    }

1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183
    /**
     * Returns the <code>UserManager</code> registered with this server. The
     * <code>UserManager</code> was registered with the server as a module while starting up
     * the server.
     *
     * @return the <code>UserManager</code> registered with this server.
     */
    public UserManager getUserManager() {
        return UserManager.getInstance();
    }

1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194
    /**
     * Returns the <code>LockOutManager</code> registered with this server.  The
     * <code>LockOutManager</code> was registered with the server as a module while starting up
     * the server.
     *
     * @return the <code>LockOutManager</code> registered with this server.
     */
    public LockOutManager getLockOutManager() {
        return LockOutManager.getInstance();
    }

1195 1196 1197 1198 1199 1200 1201 1202
    /**
     * Returns the <code>UpdateManager</code> registered with this server. The
     * <code>UpdateManager</code> was registered with the server as a module while starting up
     * the server.
     *
     * @return the <code>UpdateManager</code> registered with this server.
     */
    public UpdateManager getUpdateManager() {
1203
        return (UpdateManager) modules.get(UpdateManager.class.getName());
1204 1205
    }

1206 1207 1208 1209 1210 1211 1212 1213
    /**
     * Returns the <code>AuditManager</code> registered with this server. The
     * <code>AuditManager</code> was registered with the server as a module while starting up
     * the server.
     *
     * @return the <code>AuditManager</code> registered with this server.
     */
    public AuditManager getAuditManager() {
1214
        return (AuditManager) modules.get(AuditManager.class.getName());
1215 1216 1217 1218 1219 1220 1221 1222
    }

    /**
     * Returns a list with all the modules that provide "discoverable" features.
     *
     * @return a list with all the modules that provide "discoverable" features.
     */
    public List<ServerFeaturesProvider> getServerFeaturesProviders() {
1223
        List<ServerFeaturesProvider> answer = new ArrayList<>();
1224 1225 1226 1227 1228 1229 1230
        for (Module module : modules.values()) {
            if (module instanceof ServerFeaturesProvider) {
                answer.add((ServerFeaturesProvider) module);
            }
        }
        return answer;
    }
1231 1232 1233 1234 1235 1236 1237
 
    /**
     * Returns a list with all the modules that provide "discoverable" identities.
     *
     * @return a list with all the modules that provide "discoverable" identities.
     */
    public List<ServerIdentitiesProvider> getServerIdentitiesProviders() {
1238
        List<ServerIdentitiesProvider> answer = new ArrayList<>();
1239 1240 1241 1242 1243 1244 1245
        for (Module module : modules.values()) {
            if (module instanceof ServerIdentitiesProvider) {
                answer.add((ServerIdentitiesProvider) module);
            }
        }
        return answer;
    }
1246 1247 1248 1249 1250 1251 1252 1253 1254

    /**
     * Returns a list with all the modules that provide "discoverable" items associated with
     * the server.
     *
     * @return a list with all the modules that provide "discoverable" items associated with
     *         the server.
     */
    public List<ServerItemsProvider> getServerItemsProviders() {
1255
        List<ServerItemsProvider> answer = new ArrayList<>();
1256 1257 1258 1259 1260 1261 1262
        for (Module module : modules.values()) {
            if (module instanceof ServerItemsProvider) {
                answer.add((ServerItemsProvider) module);
            }
        }
        return answer;
    }
1263 1264 1265 1266 1267 1268 1269
    
    /**
     * Returns a list with all the modules that provide "discoverable" user identities.
     *
     * @return a list with all the modules that provide "discoverable" user identities.
     */
    public List<UserIdentitiesProvider> getUserIdentitiesProviders() {
1270
        List<UserIdentitiesProvider> answer = new ArrayList<>();
1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286
        for (Module module : modules.values()) {
            if (module instanceof UserIdentitiesProvider) {
                answer.add((UserIdentitiesProvider) module);
            }
        }
        return answer;
    }

    /**
     * Returns a list with all the modules that provide "discoverable" items associated with
     * users.
     *
     * @return a list with all the modules that provide "discoverable" items associated with
     *         users.
     */
    public List<UserItemsProvider> getUserItemsProviders() {
1287
        List<UserItemsProvider> answer = new ArrayList<>();
1288 1289 1290 1291 1292 1293 1294
        for (Module module : modules.values()) {
            if (module instanceof UserItemsProvider) {
                answer.add((UserItemsProvider) module);
            }
        }
        return answer;
    }
1295 1296 1297 1298 1299 1300 1301 1302 1303

    /**
     * Returns the <code>IQDiscoInfoHandler</code> registered with this server. The
     * <code>IQDiscoInfoHandler</code> was registered with the server as a module while starting up
     * the server.
     *
     * @return the <code>IQDiscoInfoHandler</code> registered with this server.
     */
    public IQDiscoInfoHandler getIQDiscoInfoHandler() {
1304
        return (IQDiscoInfoHandler) modules.get(IQDiscoInfoHandler.class.getName());
1305 1306 1307 1308 1309 1310 1311 1312 1313 1314
    }

    /**
     * Returns the <code>IQDiscoItemsHandler</code> registered with this server. The
     * <code>IQDiscoItemsHandler</code> was registered with the server as a module while starting up
     * the server.
     *
     * @return the <code>IQDiscoItemsHandler</code> registered with this server.
     */
    public IQDiscoItemsHandler getIQDiscoItemsHandler() {
1315
        return (IQDiscoItemsHandler) modules.get(IQDiscoItemsHandler.class.getName());
1316 1317 1318 1319 1320 1321 1322 1323 1324 1325
    }

    /**
     * Returns the <code>PrivateStorage</code> registered with this server. The
     * <code>PrivateStorage</code> was registered with the server as a module while starting up
     * the server.
     *
     * @return the <code>PrivateStorage</code> registered with this server.
     */
    public PrivateStorage getPrivateStorage() {
1326
        return (PrivateStorage) modules.get(PrivateStorage.class.getName());
1327 1328 1329
    }

    /**
1330 1331
     * Returns the <code>MultiUserChatManager</code> registered with this server. The
     * <code>MultiUserChatManager</code> was registered with the server as a module while starting up
1332 1333
     * the server.
     *
1334
     * @return the <code>MultiUserChatManager</code> registered with this server.
1335
     */
1336
    public MultiUserChatManager getMultiUserChatManager() {
1337
        return (MultiUserChatManager) modules.get(MultiUserChatManager.class.getName());
1338 1339 1340 1341 1342 1343 1344 1345 1346 1347
    }

    /**
     * Returns the <code>AdHocCommandHandler</code> registered with this server. The
     * <code>AdHocCommandHandler</code> was registered with the server as a module while starting up
     * the server.
     *
     * @return the <code>AdHocCommandHandler</code> registered with this server.
     */
    public AdHocCommandHandler getAdHocCommandHandler() {
1348
        return (AdHocCommandHandler) modules.get(AdHocCommandHandler.class.getName());
1349
    }
1350 1351 1352 1353 1354 1355 1356 1357 1358

    /**
     * Returns the <code>FileTransferProxy</code> registered with this server. The
     * <code>FileTransferProxy</code> was registered with the server as a module while starting up
     * the server.
     *
     * @return the <code>FileTransferProxy</code> registered with this server.
     */
    public FileTransferProxy getFileTransferProxy() {
1359
        return (FileTransferProxy) modules.get(FileTransferProxy.class.getName());
1360
    }
1361 1362 1363 1364 1365 1366 1367 1368 1369

    /**
     * Returns the <code>FileTransferManager</code> registered with this server. The
     * <code>FileTransferManager</code> was registered with the server as a module while starting up
     * the server.
     *
     * @return the <code>FileTransferProxy</code> registered with this server.
     */
    public FileTransferManager getFileTransferManager() {
1370
        return (FileTransferManager) modules.get(DefaultFileTransferManager.class.getName());
1371
    }
1372

1373 1374 1375 1376 1377
    /**
     * Returns the <code>MediaProxyService</code> registered with this server. The
     * <code>MediaProxyService</code> was registered with the server as a module while starting up
     * the server.
     *
1378
     * @return the <code>MediaProxyService</code> registered with this server.
1379 1380
     */
    public MediaProxyService getMediaProxyService() {
1381
        return (MediaProxyService) modules.get(MediaProxyService.class.getName());
1382 1383
    }

1384 1385 1386 1387 1388 1389 1390 1391
    /**
     * Returns the <code>FlashCrossDomainHandler</code> registered with this server. The
     * <code>FlashCrossDomainHandler</code> was registered with the server as a module while starting up
     * the server.
     *
     * @return the <code>FlashCrossDomainHandler</code> registered with this server.
     */
    public FlashCrossDomainHandler getFlashCrossDomainHandler() {
1392
        return (FlashCrossDomainHandler) modules.get(FlashCrossDomainHandler.class.getName());
1393 1394
    }

1395 1396 1397 1398 1399 1400 1401 1402 1403 1404
    /**
     * Returns the <code>VCardManager</code> registered with this server. The
     * <code>VCardManager</code> was registered with the server as a module while starting up
     * the server.
     * @return the <code>VCardManager</code> registered with this server.
     */
    public VCardManager getVCardManager() {
        return VCardManager.getInstance();
    }

1405 1406 1407 1408 1409 1410 1411 1412
    /**
     * Returns the <code>InternalComponentManager</code> registered with this server. The
     * <code>InternalComponentManager</code> was registered with the server as a module while starting up
     * the server.
     *
     * @return the <code>InternalComponentManager</code> registered with this server.
     */
    private InternalComponentManager getComponentManager() {
1413
        return (InternalComponentManager) modules.get(InternalComponentManager.class.getName());
1414 1415
    }

1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434
    /**
     * Returns the locator to use to find sessions hosted in other cluster nodes. When not running
     * in a cluster a <tt>null</tt> value is returned.
     *
     * @return the locator to use to find sessions hosted in other cluster nodes.
     */
    public RemoteSessionLocator getRemoteSessionLocator() {
        return remoteSessionLocator;
    }

    /**
     * Sets the locator to use to find sessions hosted in other cluster nodes. When not running
     * in a cluster set a <tt>null</tt> value.
     *
     * @param remoteSessionLocator the locator to use to find sessions hosted in other cluster nodes.
     */
    public void setRemoteSessionLocator(RemoteSessionLocator remoteSessionLocator) {
        this.remoteSessionLocator = remoteSessionLocator;
    }
1435 1436 1437 1438 1439 1440 1441 1442 1443

    /**
     * Returns whether or not the server has been started.
     * 
     * @return whether or not the server has been started.
     */
    public boolean isStarted() {
        return started;
    }
1444
}