XMPPServer.java 54.2 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
            } catch (IOException ie) {
755 756 757 758 759
                // Ignore.
            }
        }

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

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

796 797 798 799 800 801 802
    /**
     * 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 {
803
    	private BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
804
    	@Override
805 806 807 808 809 810 811 812
    	public void run() {
        	try { 
        		if (stdin.ready()) {
            		if (EXIT.equalsIgnoreCase(stdin.readLine())) {
            			System.exit(0); // invokes shutdown hook(s)
            		}
        		}
        	} catch (IOException ioe) {
813
        		logger.error("Error reading console input", ioe);
814 815 816 817
        	}
    	}
    }
    
818 819 820 821 822 823 824 825
    /**
     * <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 {
826

827 828 829
        /**
         * <p>Logs the server shutdown.</p>
         */
830 831
        @Override
		public void run() {
832
            shutdownServer();
833
            logger.info("Server halted");
834 835 836 837 838 839 840 841 842 843 844 845
            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 {
846

847 848 849
        /**
         * <p>Shuts down the JVM after a 5 second delay.</p>
         */
850 851
        @Override
		public void run() {
852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867
            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() {
868
        shuttingDown = true;
869
        ClusterManager.shutdown();
870 871
        // Notify server listeners that the server is about to be stopped
        for (XMPPServerListener listener : listeners) {
872 873 874
        	try {
        		listener.serverStopping();
        	} catch (Exception ex) {
875
        		logger.error("Exception during listener shutdown", ex);
876
        	}
877
        }
878 879 880 881
        // If we don't have modules then the server has already been shutdown
        if (modules.isEmpty()) {
            return;
        }
882
    	logger.info("Shutting down " + modules.size() + " modules ...");
883 884
        // Get all modules and stop and destroy them
        for (Module module : modules.values()) {
885 886 887 888
        	try {
	            module.stop();
	            module.destroy();
        	} catch (Exception ex) {
889
        		logger.error("Exception during module shutdown", ex);
890
        	}
891 892
        }
        // Stop all plugins
893
    	logger.info("Shutting down plugins ...");
894
        if (pluginManager != null) {
895 896 897
        	try {
        		pluginManager.shutdown();
        	} catch (Exception ex) {
898
        		logger.error("Exception during plugin shutdown", ex);
899
        	}
900
        }
901
        modules.clear();
902
        // Stop the Db connection manager.
903 904 905
        try {	
        	DbConnectionManager.destroyConnectionProvider();
        } catch (Exception ex) {
906
    		logger.error("Exception during DB shutdown", ex);
907
        }
908 909 910 911

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

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

925 926 927 928 929 930 931 932
    /**
     * 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() {
933
        return (ConnectionManager) modules.get(ConnectionManager.class.getName());
934 935 936 937 938 939 940 941 942 943
    }

    /**
     * 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() {
944
        return (RoutingTable) modules.get(RoutingTable.class.getName());
945 946 947 948 949 950 951 952 953 954
    }

    /**
     * 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() {
955
        return (PacketDeliverer) modules.get(PacketDeliverer.class.getName());
956 957 958 959 960 961 962 963 964 965
    }

    /**
     * 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() {
966
        return (RosterManager) modules.get(RosterManager.class.getName());
967 968 969 970 971 972 973 974 975 976
    }

    /**
     * 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() {
977
        return (PresenceManager) modules.get(PresenceManager.class.getName());
978 979 980 981 982 983 984 985 986 987
    }

    /**
     * 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() {
988
        return (OfflineMessageStore) modules.get(OfflineMessageStore.class.getName());
989 990 991 992 993 994 995 996 997 998
    }

    /**
     * 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() {
999
        return (OfflineMessageStrategy) modules.get(OfflineMessageStrategy.class.getName());
1000 1001 1002 1003 1004 1005 1006 1007 1008 1009
    }

    /**
     * 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() {
1010
        return (PacketRouter) modules.get(PacketRouter.class.getName());
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020
    }

    /**
     * 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() {
1021
        return (IQRegisterHandler) modules.get(IQRegisterHandler.class.getName());
1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
    }

    /**
     * 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() {
1032
        return (IQAuthHandler) modules.get(IQAuthHandler.class.getName());
1033
    }
1034 1035 1036 1037 1038 1039 1040 1041 1042
    
    /**
     * 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() {
1043
        return (IQPEPHandler) modules.get(IQPEPHandler.class.getName());
1044
    }
1045 1046 1047 1048 1049 1050 1051 1052 1053

    /**
     * Returns the <code>PluginManager</code> instance registered with this server.
     *
     * @return the PluginManager instance.
     */
    public PluginManager getPluginManager() {
        return pluginManager;
    }
1054 1055 1056 1057 1058 1059 1060 1061 1062

    /**
     * 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() {
1063
        return (PubSubModule) modules.get(PubSubModule.class.getName());
1064
    }
1065 1066 1067 1068 1069 1070 1071

    /**
     * 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() {
1072
        List<IQHandler> answer = new ArrayList<>();
1073 1074
        for (Module module : modules.values()) {
            if (module instanceof IQHandler) {
1075
                answer.add((IQHandler) module);
1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088
            }
        }
        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() {
1089
        return (SessionManager) modules.get(SessionManager.class.getName());
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099
    }

    /**
     * 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() {
1100
        return (TransportHandler) modules.get(TransportHandler.class.getName());
1101 1102 1103 1104 1105 1106 1107 1108 1109 1110
    }

    /**
     * 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() {
1111
        return (PresenceUpdateHandler) modules.get(PresenceUpdateHandler.class.getName());
1112 1113 1114 1115 1116 1117 1118 1119 1120 1121
    }

    /**
     * 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() {
1122
        return (PresenceSubscribeHandler) modules.get(PresenceSubscribeHandler.class.getName());
1123 1124 1125 1126 1127 1128 1129 1130 1131 1132
    }

    /**
     * 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() {
1133
        return (IQRouter) modules.get(IQRouter.class.getName());
1134 1135 1136 1137 1138 1139 1140 1141 1142 1143
    }

    /**
     * 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() {
1144
        return (MessageRouter) modules.get(MessageRouter.class.getName());
1145 1146 1147 1148 1149 1150 1151 1152 1153 1154
    }

    /**
     * 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() {
1155
        return (PresenceRouter) modules.get(PresenceRouter.class.getName());
1156 1157
    }

1158 1159 1160 1161 1162 1163 1164 1165
    /**
     * 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() {
1166
        return (MulticastRouter) modules.get(MulticastRouter.class.getName());
1167 1168
    }

1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179
    /**
     * 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();
    }

1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190
    /**
     * 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();
    }

1191 1192 1193 1194 1195 1196 1197 1198
    /**
     * 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() {
1199
        return (UpdateManager) modules.get(UpdateManager.class.getName());
1200 1201
    }

1202 1203 1204 1205 1206 1207 1208 1209
    /**
     * 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() {
1210
        return (AuditManager) modules.get(AuditManager.class.getName());
1211 1212 1213 1214 1215 1216 1217 1218
    }

    /**
     * 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() {
1219
        List<ServerFeaturesProvider> answer = new ArrayList<>();
1220 1221 1222 1223 1224 1225 1226
        for (Module module : modules.values()) {
            if (module instanceof ServerFeaturesProvider) {
                answer.add((ServerFeaturesProvider) module);
            }
        }
        return answer;
    }
1227 1228 1229 1230 1231 1232 1233
 
    /**
     * 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() {
1234
        List<ServerIdentitiesProvider> answer = new ArrayList<>();
1235 1236 1237 1238 1239 1240 1241
        for (Module module : modules.values()) {
            if (module instanceof ServerIdentitiesProvider) {
                answer.add((ServerIdentitiesProvider) module);
            }
        }
        return answer;
    }
1242 1243 1244 1245 1246 1247 1248 1249 1250

    /**
     * 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() {
1251
        List<ServerItemsProvider> answer = new ArrayList<>();
1252 1253 1254 1255 1256 1257 1258
        for (Module module : modules.values()) {
            if (module instanceof ServerItemsProvider) {
                answer.add((ServerItemsProvider) module);
            }
        }
        return answer;
    }
1259 1260 1261 1262 1263 1264 1265
    
    /**
     * 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() {
1266
        List<UserIdentitiesProvider> answer = new ArrayList<>();
1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282
        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() {
1283
        List<UserItemsProvider> answer = new ArrayList<>();
1284 1285 1286 1287 1288 1289 1290
        for (Module module : modules.values()) {
            if (module instanceof UserItemsProvider) {
                answer.add((UserItemsProvider) module);
            }
        }
        return answer;
    }
1291 1292 1293 1294 1295 1296 1297 1298 1299

    /**
     * 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() {
1300
        return (IQDiscoInfoHandler) modules.get(IQDiscoInfoHandler.class.getName());
1301 1302 1303 1304 1305 1306 1307 1308 1309 1310
    }

    /**
     * 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() {
1311
        return (IQDiscoItemsHandler) modules.get(IQDiscoItemsHandler.class.getName());
1312 1313 1314 1315 1316 1317 1318 1319 1320 1321
    }

    /**
     * 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() {
1322
        return (PrivateStorage) modules.get(PrivateStorage.class.getName());
1323 1324 1325
    }

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

    /**
     * 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() {
1344
        return (AdHocCommandHandler) modules.get(AdHocCommandHandler.class.getName());
1345
    }
1346 1347 1348 1349 1350 1351 1352 1353 1354

    /**
     * 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() {
1355
        return (FileTransferProxy) modules.get(FileTransferProxy.class.getName());
1356
    }
1357 1358 1359 1360 1361 1362 1363 1364 1365

    /**
     * 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() {
1366
        return (FileTransferManager) modules.get(DefaultFileTransferManager.class.getName());
1367
    }
1368

1369 1370 1371 1372 1373
    /**
     * 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.
     *
1374
     * @return the <code>MediaProxyService</code> registered with this server.
1375 1376
     */
    public MediaProxyService getMediaProxyService() {
1377
        return (MediaProxyService) modules.get(MediaProxyService.class.getName());
1378 1379
    }

1380 1381 1382 1383 1384 1385 1386 1387
    /**
     * 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() {
1388
        return (FlashCrossDomainHandler) modules.get(FlashCrossDomainHandler.class.getName());
1389 1390
    }

1391 1392 1393 1394 1395 1396 1397 1398 1399 1400
    /**
     * 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();
    }

1401 1402 1403 1404 1405 1406 1407 1408
    /**
     * 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() {
1409
        return (InternalComponentManager) modules.get(InternalComponentManager.class.getName());
1410 1411
    }

1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430
    /**
     * 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;
    }
1431 1432 1433 1434 1435 1436 1437 1438 1439

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