PageRenderTime 557ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/src/java/org/jivesoftware/openfire/XMPPServer.java

https://bitbucket.org/nurdiansyah/openfire
Java | 1497 lines | 771 code | 122 blank | 604 comment | 78 complexity | 58659594d5282201b88a50eee5fd7c08 MD5 | raw file
  1. /**
  2. * $RCSfile$
  3. * $Revision: 3144 $
  4. * $Date: 2005-12-01 14:20:11 -0300 (Thu, 01 Dec 2005) $
  5. *
  6. * Copyright (C) 2004-2008 Jive Software. All rights reserved.
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. */
  20. package org.jivesoftware.openfire;
  21. import java.io.File;
  22. import java.io.FileNotFoundException;
  23. import java.io.IOException;
  24. import java.io.InputStream;
  25. import java.lang.reflect.Method;
  26. import java.net.InetAddress;
  27. import java.net.UnknownHostException;
  28. import java.security.KeyStore;
  29. import java.sql.Connection;
  30. import java.sql.PreparedStatement;
  31. import java.sql.ResultSet;
  32. import java.sql.SQLException;
  33. import java.util.ArrayList;
  34. import java.util.Collection;
  35. import java.util.Date;
  36. import java.util.LinkedHashMap;
  37. import java.util.List;
  38. import java.util.Map;
  39. import java.util.concurrent.CopyOnWriteArrayList;
  40. import org.dom4j.Document;
  41. import org.dom4j.io.SAXReader;
  42. import org.jivesoftware.database.DbConnectionManager;
  43. import org.jivesoftware.openfire.admin.AdminManager;
  44. import org.jivesoftware.openfire.audit.AuditManager;
  45. import org.jivesoftware.openfire.audit.spi.AuditManagerImpl;
  46. import org.jivesoftware.openfire.clearspace.ClearspaceManager;
  47. import org.jivesoftware.openfire.cluster.NodeID;
  48. import org.jivesoftware.openfire.commands.AdHocCommandHandler;
  49. import org.jivesoftware.openfire.component.InternalComponentManager;
  50. import org.jivesoftware.openfire.container.AdminConsolePlugin;
  51. import org.jivesoftware.openfire.container.Module;
  52. import org.jivesoftware.openfire.container.PluginManager;
  53. import org.jivesoftware.openfire.disco.IQDiscoInfoHandler;
  54. import org.jivesoftware.openfire.disco.IQDiscoItemsHandler;
  55. import org.jivesoftware.openfire.disco.ServerFeaturesProvider;
  56. import org.jivesoftware.openfire.disco.ServerIdentitiesProvider;
  57. import org.jivesoftware.openfire.disco.ServerItemsProvider;
  58. import org.jivesoftware.openfire.disco.UserIdentitiesProvider;
  59. import org.jivesoftware.openfire.disco.UserItemsProvider;
  60. import org.jivesoftware.openfire.filetransfer.DefaultFileTransferManager;
  61. import org.jivesoftware.openfire.filetransfer.FileTransferManager;
  62. import org.jivesoftware.openfire.filetransfer.proxy.FileTransferProxy;
  63. import org.jivesoftware.openfire.handler.IQAuthHandler;
  64. import org.jivesoftware.openfire.handler.IQBindHandler;
  65. import org.jivesoftware.openfire.handler.IQHandler;
  66. import org.jivesoftware.openfire.handler.IQLastActivityHandler;
  67. import org.jivesoftware.openfire.handler.IQOfflineMessagesHandler;
  68. import org.jivesoftware.openfire.handler.IQPingHandler;
  69. import org.jivesoftware.openfire.handler.IQPrivacyHandler;
  70. import org.jivesoftware.openfire.handler.IQPrivateHandler;
  71. import org.jivesoftware.openfire.handler.IQRegisterHandler;
  72. import org.jivesoftware.openfire.handler.IQRosterHandler;
  73. import org.jivesoftware.openfire.handler.IQSessionEstablishmentHandler;
  74. import org.jivesoftware.openfire.handler.IQSharedGroupHandler;
  75. import org.jivesoftware.openfire.handler.IQTimeHandler;
  76. import org.jivesoftware.openfire.handler.IQVersionHandler;
  77. import org.jivesoftware.openfire.handler.IQvCardHandler;
  78. import org.jivesoftware.openfire.handler.PresenceSubscribeHandler;
  79. import org.jivesoftware.openfire.handler.PresenceUpdateHandler;
  80. import org.jivesoftware.openfire.lockout.LockOutManager;
  81. import org.jivesoftware.openfire.mediaproxy.MediaProxyService;
  82. import org.jivesoftware.openfire.muc.MultiUserChatManager;
  83. import org.jivesoftware.openfire.net.MulticastDNSService;
  84. import org.jivesoftware.openfire.net.SSLConfig;
  85. import org.jivesoftware.openfire.net.ServerTrafficCounter;
  86. import org.jivesoftware.openfire.pep.IQPEPHandler;
  87. import org.jivesoftware.openfire.pep.IQPEPOwnerHandler;
  88. import org.jivesoftware.openfire.pubsub.PubSubModule;
  89. import org.jivesoftware.openfire.roster.RosterManager;
  90. import org.jivesoftware.openfire.session.RemoteSessionLocator;
  91. import org.jivesoftware.openfire.spi.ConnectionManagerImpl;
  92. import org.jivesoftware.openfire.spi.PacketDelivererImpl;
  93. import org.jivesoftware.openfire.spi.PacketRouterImpl;
  94. import org.jivesoftware.openfire.spi.PacketTransporterImpl;
  95. import org.jivesoftware.openfire.spi.PresenceManagerImpl;
  96. import org.jivesoftware.openfire.spi.RoutingTableImpl;
  97. import org.jivesoftware.openfire.spi.XMPPServerInfoImpl;
  98. import org.jivesoftware.openfire.stun.STUNService;
  99. import org.jivesoftware.openfire.transport.TransportHandler;
  100. import org.jivesoftware.openfire.update.UpdateManager;
  101. import org.jivesoftware.openfire.user.UserManager;
  102. import org.jivesoftware.openfire.vcard.VCardManager;
  103. import org.jivesoftware.util.CertificateManager;
  104. import org.jivesoftware.util.InitializationException;
  105. import org.jivesoftware.util.JiveGlobals;
  106. import org.jivesoftware.util.LocaleUtils;
  107. import org.jivesoftware.util.TaskEngine;
  108. import org.jivesoftware.util.Version;
  109. import org.jivesoftware.util.cache.CacheFactory;
  110. import org.slf4j.Logger;
  111. import org.slf4j.LoggerFactory;
  112. import org.xmpp.packet.JID;
  113. /**
  114. * The main XMPP server that will load, initialize and start all the server's
  115. * modules. The server is unique in the JVM and could be obtained by using the
  116. * {@link #getInstance()} method.<p>
  117. * <p/>
  118. * The loaded modules will be initialized and may access through the server other
  119. * modules. This means that the only way for a module to locate another module is
  120. * through the server. The server maintains a list of loaded modules.<p>
  121. * <p/>
  122. * After starting up all the modules the server will load any available plugin.
  123. * For more information see: {@link org.jivesoftware.openfire.container.PluginManager}.<p>
  124. * <p/>
  125. * A configuration file keeps the server configuration. This information is required for the
  126. * server to work correctly. The server assumes that the configuration file is named
  127. * <b>openfire.xml</b> and is located in the <b>conf</b> folder. The folder that keeps
  128. * the configuration file must be located under the home folder. The server will try different
  129. * methods to locate the home folder.
  130. * <p/>
  131. * <ol>
  132. * <li><b>system property</b> - The server will use the value defined in the <i>openfireHome</i>
  133. * system property.</li>
  134. * <li><b>working folder</b> - The server will check if there is a <i>conf</i> folder in the
  135. * working directory. This is the case when running in standalone mode.</li>
  136. * <li><b>openfire_init.xml file</b> - Attempt to load the value from openfire_init.xml which
  137. * must be in the classpath</li>
  138. * </ol>
  139. *
  140. * @author Gaston Dombiak
  141. */
  142. public class XMPPServer {
  143. private static final Logger Log = LoggerFactory.getLogger(XMPPServer.class);
  144. private static XMPPServer instance;
  145. private String name;
  146. private String host;
  147. private Version version;
  148. private Date startDate;
  149. private boolean initialized = false;
  150. private boolean started = false;
  151. private NodeID nodeID;
  152. private static final NodeID DEFAULT_NODE_ID = NodeID.getInstance(new byte[0]);
  153. /**
  154. * All modules loaded by this server
  155. */
  156. private Map<Class, Module> modules = new LinkedHashMap<Class, Module>();
  157. /**
  158. * Listeners that will be notified when the server has started or is about to be stopped.
  159. */
  160. private List<XMPPServerListener> listeners = new CopyOnWriteArrayList<XMPPServerListener>();
  161. /**
  162. * Location of the home directory. All configuration files should be
  163. * located here.
  164. */
  165. private File openfireHome;
  166. private ClassLoader loader;
  167. private PluginManager pluginManager;
  168. private InternalComponentManager componentManager;
  169. private RemoteSessionLocator remoteSessionLocator;
  170. /**
  171. * True if in setup mode
  172. */
  173. private boolean setupMode = true;
  174. private static final String STARTER_CLASSNAME =
  175. "org.jivesoftware.openfire.starter.ServerStarter";
  176. private static final String WRAPPER_CLASSNAME =
  177. "org.tanukisoftware.wrapper.WrapperManager";
  178. private boolean shuttingDown;
  179. private XMPPServerInfoImpl xmppServerInfo;
  180. /**
  181. * Returns a singleton instance of XMPPServer.
  182. *
  183. * @return an instance.
  184. */
  185. public static XMPPServer getInstance() {
  186. return instance;
  187. }
  188. /**
  189. * Creates a server and starts it.
  190. */
  191. public XMPPServer() {
  192. // We may only have one instance of the server running on the JVM
  193. if (instance != null) {
  194. throw new IllegalStateException("A server is already running");
  195. }
  196. instance = this;
  197. start();
  198. }
  199. /**
  200. * Returns a snapshot of the server's status.
  201. *
  202. * @return the server information current at the time of the method call.
  203. */
  204. public XMPPServerInfo getServerInfo() {
  205. if (!initialized) {
  206. throw new IllegalStateException("Not initialized yet");
  207. }
  208. return xmppServerInfo;
  209. }
  210. /**
  211. * Returns true if the given address is local to the server (managed by this
  212. * server domain). Return false even if the jid's domain matches a local component's
  213. * service JID.
  214. *
  215. * @param jid the JID to check.
  216. * @return true if the address is a local address to this server.
  217. */
  218. public boolean isLocal(JID jid) {
  219. boolean local = false;
  220. if (jid != null && name != null && name.equals(jid.getDomain())) {
  221. local = true;
  222. }
  223. return local;
  224. }
  225. /**
  226. * Returns true if the given address does not match the local server hostname and does not
  227. * match a component service JID.
  228. *
  229. * @param jid the JID to check.
  230. * @return true if the given address does not match the local server hostname and does not
  231. * match a component service JID.
  232. */
  233. public boolean isRemote(JID jid) {
  234. if (jid != null) {
  235. if (!name.equals(jid.getDomain()) && !componentManager.hasComponent(jid)) {
  236. return true;
  237. }
  238. }
  239. return false;
  240. }
  241. /**
  242. * Returns an ID that uniquely identifies this server in a cluster. When not running in cluster mode
  243. * the returned value is always the same. However, when in cluster mode the value should be set
  244. * when joining the cluster and must be unique even upon restarts of this node.
  245. *
  246. * @return an ID that uniquely identifies this server in a cluster.
  247. */
  248. public NodeID getNodeID() {
  249. return nodeID == null ? DEFAULT_NODE_ID : nodeID;
  250. }
  251. /**
  252. * Sets an ID that uniquely identifies this server in a cluster. When not running in cluster mode
  253. * the returned value is always the same. However, when in cluster mode the value should be set
  254. * when joining the cluster and must be unique even upon restarts of this node.
  255. *
  256. * @param nodeID an ID that uniquely identifies this server in a cluster or null if not in a cluster.
  257. */
  258. public void setNodeID(NodeID nodeID) {
  259. this.nodeID = nodeID;
  260. }
  261. /**
  262. * Returns true if the given address matches a component service JID.
  263. *
  264. * @param jid the JID to check.
  265. * @return true if the given address matches a component service JID.
  266. */
  267. public boolean matchesComponent(JID jid) {
  268. return jid != null && !name.equals(jid.getDomain()) && componentManager.hasComponent(jid);
  269. }
  270. /**
  271. * Creates an XMPPAddress local to this server.
  272. *
  273. * @param username the user name portion of the id or null to indicate none is needed.
  274. * @param resource the resource portion of the id or null to indicate none is needed.
  275. * @return an XMPPAddress for the server.
  276. */
  277. public JID createJID(String username, String resource) {
  278. return new JID(username, name, resource);
  279. }
  280. /**
  281. * Creates an XMPPAddress local to this server. The construction of the new JID
  282. * can be optimized by skipping stringprep operations.
  283. *
  284. * @param username the user name portion of the id or null to indicate none is needed.
  285. * @param resource the resource portion of the id or null to indicate none is needed.
  286. * @param skipStringprep true if stringprep should not be applied.
  287. * @return an XMPPAddress for the server.
  288. */
  289. public JID createJID(String username, String resource, boolean skipStringprep) {
  290. return new JID(username, name, resource, skipStringprep);
  291. }
  292. /**
  293. * Returns a collection with the JIDs of the server's admins. The collection may include
  294. * JIDs of local users and users of remote servers.
  295. *
  296. * @return a collection with the JIDs of the server's admins.
  297. */
  298. public Collection<JID> getAdmins() {
  299. return AdminManager.getInstance().getAdminAccounts();
  300. }
  301. /**
  302. * Adds a new server listener that will be notified when the server has been started
  303. * or is about to be stopped.
  304. *
  305. * @param listener the new server listener to add.
  306. */
  307. public void addServerListener(XMPPServerListener listener) {
  308. listeners.add(listener);
  309. }
  310. /**
  311. * Removes a server listener that was being notified when the server was being started
  312. * or was about to be stopped.
  313. *
  314. * @param listener the server listener to remove.
  315. */
  316. public void removeServerListener(XMPPServerListener listener) {
  317. listeners.remove(listener);
  318. }
  319. private void initialize() throws FileNotFoundException {
  320. locateOpenfire();
  321. name = JiveGlobals.getProperty("xmpp.domain", "127.0.0.1").toLowerCase();
  322. try {
  323. host = InetAddress.getLocalHost().getHostName();
  324. }
  325. catch (UnknownHostException ex) {
  326. Log.warn("Unable to determine local hostname.", ex);
  327. }
  328. version = new Version(3, 7, 0, Version.ReleaseStatus.Release, -1);
  329. if ("true".equals(JiveGlobals.getXMLProperty("setup"))) {
  330. setupMode = false;
  331. }
  332. if (isStandAlone()) {
  333. Runtime.getRuntime().addShutdownHook(new ShutdownHookThread());
  334. }
  335. loader = Thread.currentThread().getContextClassLoader();
  336. try {
  337. CacheFactory.initialize();
  338. } catch (InitializationException e) {
  339. e.printStackTrace();
  340. Log.error(e.getMessage(), e);
  341. }
  342. initialized = true;
  343. }
  344. /**
  345. * Finish the setup process. Because this method is meant to be called from inside
  346. * the Admin console plugin, it spawns its own thread to do the work so that the
  347. * class loader is correct.
  348. */
  349. public void finishSetup() {
  350. if (!setupMode) {
  351. return;
  352. }
  353. // Make sure that setup finished correctly.
  354. if ("true".equals(JiveGlobals.getXMLProperty("setup"))) {
  355. // Set the new server domain assigned during the setup process
  356. name = JiveGlobals.getProperty("xmpp.domain").toLowerCase();
  357. xmppServerInfo.setXMPPDomain(name);
  358. // Update certificates (if required)
  359. try {
  360. // Check if keystore already has certificates for current domain
  361. KeyStore ksKeys = SSLConfig.getKeyStore();
  362. boolean dsaFound = CertificateManager.isDSACertificate(ksKeys, name);
  363. boolean rsaFound = CertificateManager.isRSACertificate(ksKeys, name);
  364. // No certificates were found so create new self-signed certificates
  365. if (!dsaFound) {
  366. CertificateManager.createDSACert(ksKeys, SSLConfig.getKeyPassword(),
  367. name + "_dsa", "cn=" + name, "cn=" + name, "*." + name);
  368. }
  369. if (!rsaFound) {
  370. CertificateManager.createRSACert(ksKeys, SSLConfig.getKeyPassword(),
  371. name + "_rsa", "cn=" + name, "cn=" + name, "*." + name);
  372. }
  373. // Save new certificates into the key store
  374. if (!dsaFound || !rsaFound) {
  375. SSLConfig.saveStores();
  376. }
  377. } catch (Exception e) {
  378. Log.error("Error generating self-signed certificates", e);
  379. }
  380. // Initialize list of admins now (before we restart Jetty)
  381. AdminManager.getInstance().getAdminAccounts();
  382. Thread finishSetup = new Thread() {
  383. @Override
  384. public void run() {
  385. try {
  386. if (isStandAlone()) {
  387. // Always restart the HTTP server manager. This covers the case
  388. // of changing the ports, as well as generating self-signed certificates.
  389. // Wait a short period before shutting down the admin console.
  390. // Otherwise, the page that requested the setup finish won't
  391. // render properly!
  392. Thread.sleep(1000);
  393. ((AdminConsolePlugin) pluginManager.getPlugin("admin")).restart();
  394. // ((AdminConsolePlugin) pluginManager.getPlugin("admin")).shutdown();
  395. // ((AdminConsolePlugin) pluginManager.getPlugin("admin")).startup();
  396. }
  397. verifyDataSource();
  398. // First load all the modules so that modules may access other modules while
  399. // being initialized
  400. loadModules();
  401. // Initize all the modules
  402. initModules();
  403. // Start all the modules
  404. startModules();
  405. }
  406. catch (Exception e) {
  407. e.printStackTrace();
  408. Log.error(e.getMessage(), e);
  409. shutdownServer();
  410. }
  411. }
  412. };
  413. // Use the correct class loader.
  414. finishSetup.setContextClassLoader(loader);
  415. finishSetup.start();
  416. // We can now safely indicate that setup has finished
  417. setupMode = false;
  418. // Update server info
  419. xmppServerInfo = new XMPPServerInfoImpl(name, host, version, startDate, getConnectionManager());
  420. }
  421. }
  422. public void start() {
  423. try {
  424. initialize();
  425. startDate = new Date();
  426. // Store server info
  427. xmppServerInfo = new XMPPServerInfoImpl(name, host, version, startDate, getConnectionManager());
  428. // Create PluginManager now (but don't start it) so that modules may use it
  429. File pluginDir = new File(openfireHome, "plugins");
  430. pluginManager = new PluginManager(pluginDir);
  431. // If the server has already been setup then we can start all the server's modules
  432. if (!setupMode) {
  433. verifyDataSource();
  434. // First load all the modules so that modules may access other modules while
  435. // being initialized
  436. loadModules();
  437. // Initize all the modules
  438. initModules();
  439. // Start all the modules
  440. startModules();
  441. }
  442. // Initialize statistics
  443. ServerTrafficCounter.initStatistics();
  444. // Load plugins (when in setup mode only the admin console will be loaded)
  445. pluginManager.start();
  446. // Log that the server has been started
  447. String startupBanner = LocaleUtils.getLocalizedString("short.title") + " " + version.getVersionString() +
  448. " [" + JiveGlobals.formatDateTime(new Date()) + "]";
  449. Log.info(startupBanner);
  450. System.out.println(startupBanner);
  451. started = true;
  452. // Notify server listeners that the server has been started
  453. for (XMPPServerListener listener : listeners) {
  454. listener.serverStarted();
  455. }
  456. }
  457. catch (Exception e) {
  458. e.printStackTrace();
  459. Log.error(e.getMessage(), e);
  460. System.out.println(LocaleUtils.getLocalizedString("startup.error"));
  461. shutdownServer();
  462. }
  463. }
  464. private void loadModules() {
  465. // Load boot modules
  466. loadModule(RoutingTableImpl.class.getName());
  467. loadModule(AuditManagerImpl.class.getName());
  468. loadModule(RosterManager.class.getName());
  469. loadModule(PrivateStorage.class.getName());
  470. // Load core modules
  471. loadModule(PresenceManagerImpl.class.getName());
  472. loadModule(SessionManager.class.getName());
  473. loadModule(PacketRouterImpl.class.getName());
  474. loadModule(IQRouter.class.getName());
  475. loadModule(MessageRouter.class.getName());
  476. loadModule(PresenceRouter.class.getName());
  477. loadModule(MulticastRouter.class.getName());
  478. loadModule(PacketTransporterImpl.class.getName());
  479. loadModule(PacketDelivererImpl.class.getName());
  480. loadModule(TransportHandler.class.getName());
  481. loadModule(OfflineMessageStrategy.class.getName());
  482. loadModule(OfflineMessageStore.class.getName());
  483. loadModule(VCardManager.class.getName());
  484. // Load standard modules
  485. loadModule(IQBindHandler.class.getName());
  486. loadModule(IQSessionEstablishmentHandler.class.getName());
  487. loadModule(IQAuthHandler.class.getName());
  488. loadModule(IQPingHandler.class.getName());
  489. loadModule(IQPrivateHandler.class.getName());
  490. loadModule(IQRegisterHandler.class.getName());
  491. loadModule(IQRosterHandler.class.getName());
  492. loadModule(IQTimeHandler.class.getName());
  493. loadModule(IQvCardHandler.class.getName());
  494. loadModule(IQVersionHandler.class.getName());
  495. loadModule(IQLastActivityHandler.class.getName());
  496. loadModule(PresenceSubscribeHandler.class.getName());
  497. loadModule(PresenceUpdateHandler.class.getName());
  498. loadModule(IQOfflineMessagesHandler.class.getName());
  499. loadModule(IQPEPHandler.class.getName());
  500. loadModule(IQPEPOwnerHandler.class.getName());
  501. loadModule(MulticastDNSService.class.getName());
  502. loadModule(IQSharedGroupHandler.class.getName());
  503. loadModule(AdHocCommandHandler.class.getName());
  504. loadModule(IQPrivacyHandler.class.getName());
  505. loadModule(DefaultFileTransferManager.class.getName());
  506. loadModule(FileTransferProxy.class.getName());
  507. loadModule(MediaProxyService.class.getName());
  508. loadModule(STUNService.class.getName());
  509. loadModule(PubSubModule.class.getName());
  510. loadModule(IQDiscoInfoHandler.class.getName());
  511. loadModule(IQDiscoItemsHandler.class.getName());
  512. loadModule(UpdateManager.class.getName());
  513. loadModule(FlashCrossDomainHandler.class.getName());
  514. loadModule(InternalComponentManager.class.getName());
  515. loadModule(MultiUserChatManager.class.getName());
  516. loadModule(ClearspaceManager.class.getName());
  517. // Load this module always last since we don't want to start listening for clients
  518. // before the rest of the modules have been started
  519. loadModule(ConnectionManagerImpl.class.getName());
  520. // Keep a reference to the internal component manager
  521. componentManager = getComponentManager();
  522. }
  523. /**
  524. * Loads a module.
  525. *
  526. * @param module the name of the class that implements the Module interface.
  527. */
  528. private void loadModule(String module) {
  529. try {
  530. Class modClass = loader.loadClass(module);
  531. Module mod = (Module) modClass.newInstance();
  532. this.modules.put(modClass, mod);
  533. }
  534. catch (Exception e) {
  535. e.printStackTrace();
  536. Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
  537. }
  538. }
  539. private void initModules() {
  540. for (Module module : modules.values()) {
  541. boolean isInitialized = false;
  542. try {
  543. module.initialize(this);
  544. isInitialized = true;
  545. }
  546. catch (Exception e) {
  547. e.printStackTrace();
  548. // Remove the failed initialized module
  549. this.modules.remove(module.getClass());
  550. if (isInitialized) {
  551. module.stop();
  552. module.destroy();
  553. }
  554. Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
  555. }
  556. }
  557. }
  558. /**
  559. * <p>Following the loading and initialization of all the modules
  560. * this method is called to iterate through the known modules and
  561. * start them.</p>
  562. */
  563. private void startModules() {
  564. for (Module module : modules.values()) {
  565. boolean started = false;
  566. try {
  567. module.start();
  568. }
  569. catch (Exception e) {
  570. if (started && module != null) {
  571. module.stop();
  572. module.destroy();
  573. }
  574. Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
  575. }
  576. }
  577. }
  578. /**
  579. * Restarts the server and all it's modules only if the server is restartable. Otherwise do
  580. * nothing.
  581. */
  582. public void restart() {
  583. if (isStandAlone() && isRestartable()) {
  584. try {
  585. Class wrapperClass = Class.forName(WRAPPER_CLASSNAME);
  586. Method restartMethod = wrapperClass.getMethod("restart", (Class []) null);
  587. restartMethod.invoke(null, (Object []) null);
  588. }
  589. catch (Exception e) {
  590. Log.error("Could not restart container", e);
  591. }
  592. }
  593. }
  594. /**
  595. * Restarts the HTTP server only when running in stand alone mode. The restart
  596. * process will be done in another thread that will wait 1 second before doing
  597. * the actual restart. The delay will give time to the page that requested the
  598. * restart to fully render its content.
  599. */
  600. public void restartHTTPServer() {
  601. Thread restartThread = new Thread() {
  602. @Override
  603. public void run() {
  604. if (isStandAlone()) {
  605. // Restart the HTTP server manager. This covers the case
  606. // of changing the ports, as well as generating self-signed certificates.
  607. // Wait a short period before shutting down the admin console.
  608. // Otherwise, this page won't render properly!
  609. try {
  610. Thread.sleep(1000);
  611. ((AdminConsolePlugin) pluginManager.getPlugin("admin")).shutdown();
  612. ((AdminConsolePlugin) pluginManager.getPlugin("admin")).startup();
  613. } catch (Exception e) {
  614. e.printStackTrace();
  615. }
  616. }
  617. }
  618. };
  619. restartThread.setContextClassLoader(loader);
  620. restartThread.start();
  621. }
  622. /**
  623. * Stops the server only if running in standalone mode. Do nothing if the server is running
  624. * inside of another server.
  625. */
  626. public void stop() {
  627. // Only do a system exit if we're running standalone
  628. if (isStandAlone()) {
  629. // if we're in a wrapper, we have to tell the wrapper to shut us down
  630. if (isRestartable()) {
  631. try {
  632. Class wrapperClass = Class.forName(WRAPPER_CLASSNAME);
  633. Method stopMethod = wrapperClass.getMethod("stop", Integer.TYPE);
  634. stopMethod.invoke(null, 0);
  635. }
  636. catch (Exception e) {
  637. Log.error("Could not stop container", e);
  638. }
  639. }
  640. else {
  641. shutdownServer();
  642. Thread shutdownThread = new ShutdownThread();
  643. shutdownThread.setDaemon(true);
  644. shutdownThread.start();
  645. }
  646. }
  647. else {
  648. // Close listening socket no matter what the condition is in order to be able
  649. // to be restartable inside a container.
  650. shutdownServer();
  651. }
  652. }
  653. public boolean isSetupMode() {
  654. return setupMode;
  655. }
  656. public boolean isRestartable() {
  657. boolean restartable;
  658. try {
  659. restartable = Class.forName(WRAPPER_CLASSNAME) != null;
  660. }
  661. catch (ClassNotFoundException e) {
  662. restartable = false;
  663. }
  664. return restartable;
  665. }
  666. /**
  667. * Returns if the server is running in standalone mode. We consider that it's running in
  668. * standalone if the "org.jivesoftware.openfire.starter.ServerStarter" class is present in the
  669. * system.
  670. *
  671. * @return true if the server is running in standalone mode.
  672. */
  673. public boolean isStandAlone() {
  674. boolean standalone;
  675. try {
  676. standalone = Class.forName(STARTER_CLASSNAME) != null;
  677. }
  678. catch (ClassNotFoundException e) {
  679. standalone = false;
  680. }
  681. return standalone;
  682. }
  683. /**
  684. * Verify that the database is accessible.
  685. */
  686. private void verifyDataSource() {
  687. Connection con = null;
  688. PreparedStatement pstmt = null;
  689. ResultSet rs = null;
  690. try {
  691. con = DbConnectionManager.getConnection();
  692. pstmt = con.prepareStatement("SELECT count(*) FROM ofID");
  693. rs = pstmt.executeQuery();
  694. rs.next();
  695. }
  696. catch (Exception e) {
  697. System.err.println("Database setup or configuration error: " +
  698. "Please verify your database settings and check the " +
  699. "logs/error.log file for detailed error messages.");
  700. Log.error("Database could not be accessed", e);
  701. throw new IllegalArgumentException(e);
  702. }
  703. finally {
  704. DbConnectionManager.closeConnection(rs, pstmt, con);
  705. }
  706. }
  707. /**
  708. * Verifies that the given home guess is a real Openfire home directory.
  709. * We do the verification by checking for the Openfire config file in
  710. * the config dir of jiveHome.
  711. *
  712. * @param homeGuess a guess at the path to the home directory.
  713. * @param jiveConfigName the name of the config file to check.
  714. * @return a file pointing to the home directory or null if the
  715. * home directory guess was wrong.
  716. * @throws java.io.FileNotFoundException if there was a problem with the home
  717. * directory provided
  718. */
  719. private File verifyHome(String homeGuess, String jiveConfigName) throws FileNotFoundException {
  720. File openfireHome = new File(homeGuess);
  721. File configFile = new File(openfireHome, jiveConfigName);
  722. if (!configFile.exists()) {
  723. throw new FileNotFoundException();
  724. }
  725. else {
  726. try {
  727. return new File(openfireHome.getCanonicalPath());
  728. }
  729. catch (Exception ex) {
  730. throw new FileNotFoundException();
  731. }
  732. }
  733. }
  734. /**
  735. * <p>Retrieve the jive home for the container.</p>
  736. *
  737. * @throws FileNotFoundException If jiveHome could not be located
  738. */
  739. private void locateOpenfire() throws FileNotFoundException {
  740. String jiveConfigName = "conf" + File.separator + "openfire.xml";
  741. // First, try to load it openfireHome as a system property.
  742. if (openfireHome == null) {
  743. String homeProperty = System.getProperty("openfireHome");
  744. try {
  745. if (homeProperty != null) {
  746. openfireHome = verifyHome(homeProperty, jiveConfigName);
  747. }
  748. }
  749. catch (FileNotFoundException fe) {
  750. // Ignore.
  751. }
  752. }
  753. // If we still don't have home, let's assume this is standalone
  754. // and just look for home in a standard sub-dir location and verify
  755. // by looking for the config file
  756. if (openfireHome == null) {
  757. try {
  758. openfireHome = verifyHome("..", jiveConfigName).getCanonicalFile();
  759. }
  760. catch (FileNotFoundException fe) {
  761. // Ignore.
  762. }
  763. catch (IOException ie) {
  764. // Ignore.
  765. }
  766. }
  767. // If home is still null, no outside process has set it and
  768. // we have to attempt to load the value from openfire_init.xml,
  769. // which must be in the classpath.
  770. if (openfireHome == null) {
  771. InputStream in = null;
  772. try {
  773. in = getClass().getResourceAsStream("/openfire_init.xml");
  774. if (in != null) {
  775. SAXReader reader = new SAXReader();
  776. Document doc = reader.read(in);
  777. String path = doc.getRootElement().getText();
  778. try {
  779. if (path != null) {
  780. openfireHome = verifyHome(path, jiveConfigName);
  781. }
  782. }
  783. catch (FileNotFoundException fe) {
  784. fe.printStackTrace();
  785. }
  786. }
  787. }
  788. catch (Exception e) {
  789. System.err.println("Error loading openfire_init.xml to find home.");
  790. e.printStackTrace();
  791. }
  792. finally {
  793. try {
  794. if (in != null) {
  795. in.close();
  796. }
  797. }
  798. catch (Exception e) {
  799. System.err.println("Could not close open connection");
  800. e.printStackTrace();
  801. }
  802. }
  803. }
  804. if (openfireHome == null) {
  805. System.err.println("Could not locate home");
  806. throw new FileNotFoundException();
  807. }
  808. else {
  809. // Set the home directory for the config file
  810. JiveGlobals.setHomeDirectory(openfireHome.toString());
  811. // Set the name of the config file
  812. JiveGlobals.setConfigName(jiveConfigName);
  813. }
  814. }
  815. /**
  816. * <p>A thread to ensure the server shuts down no matter what.</p>
  817. * <p>Spawned when stop() is called in standalone mode, we wait a few
  818. * seconds then call system exit().</p>
  819. *
  820. * @author Iain Shigeoka
  821. */
  822. private class ShutdownHookThread extends Thread {
  823. /**
  824. * <p>Logs the server shutdown.</p>
  825. */
  826. @Override
  827. public void run() {
  828. shutdownServer();
  829. Log.info("Server halted");
  830. System.err.println("Server halted");
  831. }
  832. }
  833. /**
  834. * <p>A thread to ensure the server shuts down no matter what.</p>
  835. * <p>Spawned when stop() is called in standalone mode, we wait a few
  836. * seconds then call system exit().</p>
  837. *
  838. * @author Iain Shigeoka
  839. */
  840. private class ShutdownThread extends Thread {
  841. /**
  842. * <p>Shuts down the JVM after a 5 second delay.</p>
  843. */
  844. @Override
  845. public void run() {
  846. try {
  847. Thread.sleep(5000);
  848. // No matter what, we make sure it's dead
  849. System.exit(0);
  850. }
  851. catch (InterruptedException e) {
  852. // Ignore.
  853. }
  854. }
  855. }
  856. /**
  857. * Makes a best effort attempt to shutdown the server
  858. */
  859. private void shutdownServer() {
  860. shuttingDown = true;
  861. // Notify server listeners that the server is about to be stopped
  862. for (XMPPServerListener listener : listeners) {
  863. listener.serverStopping();
  864. }
  865. // Shutdown the task engine.
  866. TaskEngine.getInstance().shutdown();
  867. // If we don't have modules then the server has already been shutdown
  868. if (modules.isEmpty()) {
  869. return;
  870. }
  871. // Get all modules and stop and destroy them
  872. for (Module module : modules.values()) {
  873. module.stop();
  874. module.destroy();
  875. }
  876. // Stop all plugins
  877. if (pluginManager != null) {
  878. pluginManager.shutdown();
  879. }
  880. modules.clear();
  881. // Stop the Db connection manager.
  882. DbConnectionManager.destroyConnectionProvider();
  883. // hack to allow safe stopping
  884. Log.info("Openfire stopped");
  885. }
  886. /**
  887. * Returns true if the server is being shutdown.
  888. *
  889. * @return true if the server is being shutdown.
  890. */
  891. public boolean isShuttingDown() {
  892. return shuttingDown;
  893. }
  894. /**
  895. * Returns the <code>ConnectionManager</code> registered with this server. The
  896. * <code>ConnectionManager</code> was registered with the server as a module while starting up
  897. * the server.
  898. *
  899. * @return the <code>ConnectionManager</code> registered with this server.
  900. */
  901. public ConnectionManager getConnectionManager() {
  902. return (ConnectionManager) modules.get(ConnectionManagerImpl.class);
  903. }
  904. /**
  905. * Returns the <code>RoutingTable</code> registered with this server. The
  906. * <code>RoutingTable</code> was registered with the server as a module while starting up
  907. * the server.
  908. *
  909. * @return the <code>RoutingTable</code> registered with this server.
  910. */
  911. public RoutingTable getRoutingTable() {
  912. return (RoutingTable) modules.get(RoutingTableImpl.class);
  913. }
  914. /**
  915. * Returns the <code>PacketDeliverer</code> registered with this server. The
  916. * <code>PacketDeliverer</code> was registered with the server as a module while starting up
  917. * the server.
  918. *
  919. * @return the <code>PacketDeliverer</code> registered with this server.
  920. */
  921. public PacketDeliverer getPacketDeliverer() {
  922. return (PacketDeliverer) modules.get(PacketDelivererImpl.class);
  923. }
  924. /**
  925. * Returns the <code>RosterManager</code> registered with this server. The
  926. * <code>RosterManager</code> was registered with the server as a module while starting up
  927. * the server.
  928. *
  929. * @return the <code>RosterManager</code> registered with this server.
  930. */
  931. public RosterManager getRosterManager() {
  932. return (RosterManager) modules.get(RosterManager.class);
  933. }
  934. /**
  935. * Returns the <code>PresenceManager</code> registered with this server. The
  936. * <code>PresenceManager</code> was registered with the server as a module while starting up
  937. * the server.
  938. *
  939. * @return the <code>PresenceManager</code> registered with this server.
  940. */
  941. public PresenceManager getPresenceManager() {
  942. return (PresenceManager) modules.get(PresenceManagerImpl.class);
  943. }
  944. /**
  945. * Returns the <code>OfflineMessageStore</code> registered with this server. The
  946. * <code>OfflineMessageStore</code> was registered with the server as a module while starting up
  947. * the server.
  948. *
  949. * @return the <code>OfflineMessageStore</code> registered with this server.
  950. */
  951. public OfflineMessageStore getOfflineMessageStore() {
  952. return (OfflineMessageStore) modules.get(OfflineMessageStore.class);
  953. }
  954. /**
  955. * Returns the <code>OfflineMessageStrategy</code> registered with this server. The
  956. * <code>OfflineMessageStrategy</code> was registered with the server as a module while starting
  957. * up the server.
  958. *
  959. * @return the <code>OfflineMessageStrategy</code> registered with this server.
  960. */
  961. public OfflineMessageStrategy getOfflineMessageStrategy() {
  962. return (OfflineMessageStrategy) modules.get(OfflineMessageStrategy.class);
  963. }
  964. /**
  965. * Returns the <code>PacketRouter</code> registered with this server. The
  966. * <code>PacketRouter</code> was registered with the server as a module while starting up
  967. * the server.
  968. *
  969. * @return the <code>PacketRouter</code> registered with this server.
  970. */
  971. public PacketRouter getPacketRouter() {
  972. return (PacketRouter) modules.get(PacketRouterImpl.class);
  973. }
  974. /**
  975. * Returns the <code>IQRegisterHandler</code> registered with this server. The
  976. * <code>IQRegisterHandler</code> was registered with the server as a module while starting up
  977. * the server.
  978. *
  979. * @return the <code>IQRegisterHandler</code> registered with this server.
  980. */
  981. public IQRegisterHandler getIQRegisterHandler() {
  982. return (IQRegisterHandler) modules.get(IQRegisterHandler.class);
  983. }
  984. /**
  985. * Returns the <code>IQAuthHandler</code> registered with this server. The
  986. * <code>IQAuthHandler</code> was registered with the server as a module while starting up
  987. * the server.
  988. *
  989. * @return the <code>IQAuthHandler</code> registered with this server.
  990. */
  991. public IQAuthHandler getIQAuthHandler() {
  992. return (IQAuthHandler) modules.get(IQAuthHandler.class);
  993. }
  994. /**
  995. * Returns the <code>IQPEPHandler</code> registered with this server. The
  996. * <code>IQPEPHandler</code> was registered with the server as a module while starting up
  997. * the server.
  998. *
  999. * @return the <code>IQPEPHandler</code> registered with this server.
  1000. */
  1001. public IQPEPHandler getIQPEPHandler() {
  1002. return (IQPEPHandler) modules.get(IQPEPHandler.class);
  1003. }
  1004. /**
  1005. * Returns the <code>PluginManager</code> instance registered with this server.
  1006. *
  1007. * @return the PluginManager instance.
  1008. */
  1009. public PluginManager getPluginManager() {
  1010. return pluginManager;
  1011. }
  1012. /**
  1013. * Returns the <code>PubSubModule</code> registered with this server. The
  1014. * <code>PubSubModule</code> was registered with the server as a module while starting up
  1015. * the server.
  1016. *
  1017. * @return the <code>PubSubModule</code> registered with this server.
  1018. */
  1019. public PubSubModule getPubSubModule() {
  1020. return (PubSubModule) modules.get(PubSubModule.class);
  1021. }
  1022. /**
  1023. * Returns a list with all the modules registered with the server that inherit from IQHandler.
  1024. *
  1025. * @return a list with all the modules registered with the server that inherit from IQHandler.
  1026. */
  1027. public List<IQHandler> getIQHandlers() {
  1028. List<IQHandler> answer = new ArrayList<IQHandler>();
  1029. for (Module module : modules.values()) {
  1030. if (module instanceof IQHandler) {
  1031. answer.add((IQHandler) module);
  1032. }
  1033. }
  1034. return answer;
  1035. }
  1036. /**
  1037. * Returns the <code>SessionManager</code> registered with this server. The
  1038. * <code>SessionManager</code> was registered with the server as a module while starting up
  1039. * the server.
  1040. *
  1041. * @return the <code>SessionManager</code> registered with this server.
  1042. */
  1043. public SessionManager getSessionManager() {
  1044. return (SessionManager) modules.get(SessionManager.class);
  1045. }
  1046. /**
  1047. * Returns the <code>TransportHandler</code> registered with this server. The
  1048. * <code>TransportHandler</code> was registered with the server as a module while starting up
  1049. * the server.
  1050. *
  1051. * @return the <code>TransportHandler</code> registered with this server.
  1052. */
  1053. public TransportHandler getTransportHandler() {
  1054. return (TransportHandler) modules.get(TransportHandler.class);
  1055. }
  1056. /**
  1057. * Returns the <code>PresenceUpdateHandler</code> registered with this server. The
  1058. * <code>PresenceUpdateHandler</code> was registered with the server as a module while starting
  1059. * up the server.
  1060. *
  1061. * @return the <code>PresenceUpdateHandler</code> registered with this server.
  1062. */
  1063. public PresenceUpdateHandler getPresenceUpdateHandler() {
  1064. return (PresenceUpdateHandler) modules.get(PresenceUpdateHandler.class);
  1065. }
  1066. /**
  1067. * Returns the <code>PresenceSubscribeHandler</code> registered with this server. The
  1068. * <code>PresenceSubscribeHandler</code> was registered with the server as a module while
  1069. * starting up the server.
  1070. *
  1071. * @return the <code>PresenceSubscribeHandler</code> registered with this server.
  1072. */
  1073. public PresenceSubscribeHandler getPresenceSubscribeHandler() {
  1074. return (PresenceSubscribeHandler) modules.get(PresenceSubscribeHandler.class);
  1075. }
  1076. /**
  1077. * Returns the <code>IQRouter</code> registered with this server. The
  1078. * <code>IQRouter</code> was registered with the server as a module while starting up
  1079. * the server.
  1080. *
  1081. * @return the <code>IQRouter</code> registered with this server.
  1082. */
  1083. public IQRouter getIQRouter() {
  1084. return (IQRouter) modules.get(IQRouter.class);
  1085. }
  1086. /**
  1087. * Returns the <code>MessageRouter</code> registered with this server. The
  1088. * <code>MessageRouter</code> was registered with the server as a module while starting up
  1089. * the server.
  1090. *
  1091. * @return the <code>MessageRouter</code> registered with this server.
  1092. */
  1093. public MessageRouter getMessageRouter() {
  1094. return (MessageRouter) modules.get(MessageRouter.class);
  1095. }
  1096. /**
  1097. * Returns the <code>PresenceRouter</code> registered with this server. The
  1098. * <code>PresenceRouter</code> was registered with the server as a module while starting up
  1099. * the server.
  1100. *
  1101. * @return the <code>PresenceRouter</code> registered with this server.
  1102. */
  1103. public PresenceRouter getPresenceRouter() {
  1104. return (PresenceRouter) modules.get(PresenceRouter.class);
  1105. }
  1106. /**
  1107. * Returns the <code>MulticastRouter</code> registered with this server. The
  1108. * <code>MulticastRouter</code> was registered with the server as a module while starting up
  1109. * the server.
  1110. *
  1111. * @return the <code>MulticastRouter</code> registered with this server.
  1112. */
  1113. public MulticastRouter getMulticastRouter() {
  1114. return (MulticastRouter) modules.get(MulticastRouter.class);
  1115. }
  1116. /**
  1117. * Returns the <code>UserManager</code> registered with this server. The
  1118. * <code>UserManager</code> was registered with the server as a module while starting up
  1119. * the server.
  1120. *
  1121. * @return the <code>UserManager</code> registered with this server.
  1122. */
  1123. public UserManager getUserManager() {
  1124. return UserManager.getInstance();
  1125. }
  1126. /**
  1127. * Returns the <code>LockOutManager</code> registered with this server. The
  1128. * <code>LockOutManager</code> was registered with the server as a module while starting up
  1129. * the server.
  1130. *
  1131. * @return the <code>LockOutManager</code> registered with this server.
  1132. */
  1133. public LockOutManager getLockOutManager() {
  1134. return LockOutManager.getInstance();
  1135. }
  1136. /**
  1137. * Returns the <code>UpdateManager</code> registered with this server. The
  1138. * <code>UpdateManager</code> was registered with the server as a module while starting up
  1139. * the server.
  1140. *
  1141. * @return the <code>UpdateManager</code> registered with this server.
  1142. */
  1143. public UpdateManager getUpdateManager() {
  1144. return (UpdateManager) modules.get(UpdateManager.class);
  1145. }
  1146. /**
  1147. * Returns the <code>AuditManager</code> registered with this server. The
  1148. * <code>AuditManager</code> was registered with the server as a module while starting up
  1149. * the server.
  1150. *
  1151. * @return the <code>AuditManager</code> registered with this server.
  1152. */
  1153. public AuditManager getAuditManager() {
  1154. return (AuditManager) modules.get(AuditManagerImpl.class);
  1155. }
  1156. /**
  1157. * Returns a list with all the modules that provide "discoverable" features.
  1158. *
  1159. * @return a list with all the modules that provide "discoverable" features.
  1160. */
  1161. public List<ServerFeaturesProvider> getServerFeaturesProviders() {
  1162. List<ServerFeaturesProvider> answer = new ArrayList<ServerFeaturesProvider>();
  1163. for (Module module : modules.values()) {
  1164. if (module instanceof ServerFeaturesProvider) {
  1165. answer.add((ServerFeaturesProvider) module);
  1166. }
  1167. }
  1168. return answer;
  1169. }
  1170. /**
  1171. * Returns a list with all the modules that provide "discoverable" identities.
  1172. *
  1173. * @return a list with all the modules that provide "discoverable" identities.
  1174. */
  1175. public List<ServerIdentitiesProvider> getServerIdentitiesProviders() {
  1176. List<ServerIdentitiesProvider> answer = new ArrayList<ServerIdentitiesProvider>();
  1177. for (Module module : modules.values()) {
  1178. if (module instanceof ServerIdentitiesProvider) {
  1179. answer.add((ServerIdentitiesProvider) module);
  1180. }
  1181. }
  1182. return answer;
  1183. }
  1184. /**
  1185. * Returns a list with all the modules that provide "discoverable" items associated with
  1186. * the server.
  1187. *
  1188. * @return a list with all the modules that provide "discoverable" items associated with
  1189. * the server.
  1190. */
  1191. public List<ServerItemsProvider> getServerItemsProviders() {
  1192. List<ServerItemsProvider> answer = new ArrayList<ServerItemsProvider>();
  1193. for (Module module : modules.values()) {
  1194. if (module instanceof ServerItemsProvider) {
  1195. answer.add((ServerItemsProvider) module);
  1196. }
  1197. }
  1198. return answer;
  1199. }
  1200. /**
  1201. * Returns a list with all the modules that provide "discoverable" user identities.
  1202. *
  1203. * @return a list with all the modules that provide "discoverable" user identities.
  1204. */
  1205. public List<UserIdentitiesProvider> getUserIdentitiesProviders() {
  1206. List<UserIdentitiesProvider> answer = new ArrayList<UserIdentitiesProvider>();
  1207. for (Module module : modules.values()) {
  1208. if (module instanceof UserIdentitiesProvider) {
  1209. answer.add((UserIdentitiesProvider) module);
  1210. }
  1211. }
  1212. return answer;
  1213. }
  1214. /**
  1215. * Returns a list with all the modules that provide "discoverable" items associated with
  1216. * users.
  1217. *
  1218. * @return a list with all the modules that provide "discoverable" items associated with
  1219. * users.
  1220. */
  1221. public List<UserItemsProvider> getUserItemsProviders() {
  1222. List<UserItemsProvider> answer = new ArrayList<UserItemsProvider>();
  1223. for (Module module : modules.values()) {
  1224. if (module instanceof UserItemsProvider) {
  1225. answer.add((UserItemsProvider) module);
  1226. }
  1227. }
  1228. return answer;
  1229. }
  1230. /**
  1231. * Returns the <code>IQDiscoInfoHandler</code> registered with this server. The
  1232. * <code>IQDiscoInfoHandler</code> was registered with the server as a module while starting up
  1233. * the server.
  1234. *
  1235. * @return the <code>IQDiscoInfoHandler</code> registered with this server.
  1236. */
  1237. public IQDiscoInfoHandler getIQDiscoInfoHandler() {
  1238. return (IQDiscoInfoHandler) modules.get(IQDiscoInfoHandler.class);
  1239. }
  1240. /**
  1241. * Returns the <code>IQDiscoItemsHandler</code> registered with this server. The
  1242. * <code>IQDiscoItemsHandler</code> was registered with the server as a module while starting up
  1243. * the server.
  1244. *
  1245. * @return the <code>IQDiscoItemsHandler</code> registered with this server.
  1246. */
  1247. public IQDiscoItemsHandler getIQDiscoItemsHandler() {
  1248. return (IQDiscoItemsHandler) modules.get(IQDiscoItemsHandler.class);
  1249. }
  1250. /**
  1251. * Returns the <code>PrivateStorage</code> registered with this server. The
  1252. * <code>PrivateStorage</code> was registered with the server as a module while starting up
  1253. * the server.
  1254. *
  1255. * @return the <code>PrivateStorage</code> registered with this server.
  1256. */
  1257. public PrivateStorage getPrivateStorage() {
  1258. return (PrivateStorage) modules.get(PrivateStorage.class);
  1259. }
  1260. /**
  1261. * Returns the <code>MultiUserChatManager</code> registered with this server. The
  1262. * <code>MultiUserChatManager</code> was registered with the server as a module while starting up
  1263. * the server.
  1264. *
  1265. * @return the <code>MultiUserChatManager</code> registered with this server.
  1266. */
  1267. public MultiUserChatManager getMultiUserChatManager() {
  1268. return (MultiUserChatManager) modules.get(MultiUserChatManager.class);
  1269. }
  1270. /**
  1271. * Returns the <code>AdHocCommandHandler</code> registered with this server. The
  1272. * <code>AdHocCommandHandler</code> was registered with the server as a module while starting up
  1273. * the server.
  1274. *
  1275. * @return the <code>AdHocCommandHandler</code> registered with this server.
  1276. */
  1277. public AdHocCommandHandler getAdHocCommandHandler() {
  1278. return (AdHocCommandHandler) modules.get(AdHocCommandHandler.class);
  1279. }
  1280. /**
  1281. * Returns the <code>FileTransferProxy</code> registered with this server. The
  1282. * <code>FileTransferProxy</code> was registered with the server as a module while starting up
  1283. * the server.
  1284. *
  1285. * @return the <code>FileTransferProxy</code> registered with this server.
  1286. */
  1287. public FileTransferProxy getFileTransferProxy() {
  1288. return (FileTransferProxy) modules.get(FileTransferProxy.class);
  1289. }
  1290. /**
  1291. * Returns the <code>FileTransferManager</code> registered with this server. The
  1292. * <code>FileTransferManager</code> was registered with the server as a module while starting up
  1293. * the server.
  1294. *
  1295. * @return the <code>FileTransferProxy</code> registered with this server.
  1296. */
  1297. public FileTransferManager getFileTransferManager() {
  1298. return (FileTransferManager) modules.get(DefaultFileTransferManager.class);
  1299. }
  1300. /**
  1301. * Returns the <code>MediaProxyService</code> registered with this server. The
  1302. * <code>MediaProxyService</code> was registered with the server as a module while starting up
  1303. * the server.
  1304. *
  1305. * @return the <code>MediaProxyService</code> registered with this server.
  1306. */
  1307. public MediaProxyService getMediaProxyService() {
  1308. return (MediaProxyService) modules.get(MediaProxyService.class);
  1309. }
  1310. /**
  1311. * Returns the <code>STUNService</code> registered with this server. The
  1312. * <code>MediaProxyService</code> was registered with the server as a module while starting up
  1313. * the server.
  1314. *
  1315. * @return the <code>STUNService</code> registered with this server.
  1316. */
  1317. public STUNService getSTUNService() {
  1318. return (STUNService) modules.get(STUNService.class);
  1319. }
  1320. /**
  1321. * Returns the <code>FlashCrossDomainHandler</code> registered with this server. The
  1322. * <code>FlashCrossDomainHandler</code> was registered with the server as a module while starting up
  1323. * the server.
  1324. *
  1325. * @return the <code>FlashCrossDomainHandler</code> registered with this server.
  1326. */
  1327. public FlashCrossDomainHandler getFlashCrossDomainHandler() {
  1328. return (FlashCrossDomainHandler) modules.get(FlashCrossDomainHandler.class);
  1329. }
  1330. /**
  1331. * Returns the <code>VCardManager</code> registered with this server. The
  1332. * <code>VCardManager</code> was registered with the server as a module while starting up
  1333. * the server.
  1334. * @return the <code>VCardManager</code> registered with this server.
  1335. */
  1336. public VCardManager getVCardManager() {
  1337. return VCardManager.getInstance();
  1338. }
  1339. /**
  1340. * Returns the <code>InternalComponentManager</code> registered with this server. The
  1341. * <code>InternalComponentManager</code> was registered with the server as a module while starting up
  1342. * the server.
  1343. *
  1344. * @return the <code>InternalComponentManager</code> registered with this server.
  1345. */
  1346. private InternalComponentManager getComponentManager() {
  1347. return (InternalComponentManager) modules.get(InternalComponentManager.class);
  1348. }
  1349. /**
  1350. * Returns the locator to use to find sessions hosted in other cluster nodes. When not running
  1351. * in a cluster a <tt>null</tt> value is returned.
  1352. *
  1353. * @return the locator to use to find sessions hosted in other cluster nodes.
  1354. */
  1355. public RemoteSessionLocator getRemoteSessionLocator() {
  1356. return remoteSessionLocator;
  1357. }
  1358. /**
  1359. * Sets the locator to use to find sessions hosted in other cluster nodes. When not running
  1360. * in a cluster set a <tt>null</tt> value.
  1361. *
  1362. * @param remoteSessionLocator the locator to use to find sessions hosted in other cluster nodes.
  1363. */
  1364. public void setRemoteSessionLocator(RemoteSessionLocator remoteSessionLocator) {
  1365. this.remoteSessionLocator = remoteSessionLocator;
  1366. }
  1367. /**
  1368. * Returns whether or not the server has been started.
  1369. *
  1370. * @return whether or not the server has been started.
  1371. */
  1372. public boolean isStarted() {
  1373. return started;
  1374. }
  1375. }