KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jivesoftware > messenger > XMPPServer


1 /**
2  * $RCSfile: XMPPServer.java,v $
3  * $Revision: 1.39 $
4  * $Date: 2005/08/01 20:19:06 $
5  *
6  * Copyright (C) 2004 Jive Software. All rights reserved.
7  *
8  * This software is published under the terms of the GNU Public License (GPL),
9  * a copy of which is included in this distribution.
10  */

11
12 package org.jivesoftware.messenger;
13
14 import org.xmpp.packet.JID;
15 import org.jivesoftware.messenger.roster.RosterManager;
16 import org.jivesoftware.messenger.user.UserManager;
17 import org.jivesoftware.messenger.handler.*;
18 import org.jivesoftware.messenger.transport.TransportHandler;
19 import org.jivesoftware.messenger.audit.AuditManager;
20 import org.jivesoftware.messenger.audit.spi.AuditManagerImpl;
21 import org.jivesoftware.messenger.disco.ServerFeaturesProvider;
22 import org.jivesoftware.messenger.disco.ServerItemsProvider;
23 import org.jivesoftware.messenger.disco.IQDiscoInfoHandler;
24 import org.jivesoftware.messenger.disco.IQDiscoItemsHandler;
25 import org.jivesoftware.messenger.muc.MultiUserChatServer;
26 import org.jivesoftware.messenger.muc.spi.MultiUserChatServerImpl;
27 import org.jivesoftware.messenger.spi.*;
28 import org.jivesoftware.messenger.container.Module;
29 import org.jivesoftware.messenger.container.PluginManager;
30 import org.jivesoftware.messenger.net.MulticastDNSService;
31 import org.jivesoftware.messenger.component.InternalComponentManager;
32 import org.jivesoftware.util.Version;
33 import org.jivesoftware.util.LocaleUtils;
34 import org.jivesoftware.util.Log;
35 import org.jivesoftware.util.JiveGlobals;
36 import org.jivesoftware.database.DbConnectionManager;
37 import org.dom4j.io.SAXReader;
38 import org.dom4j.Document;
39
40 import java.util.*;
41 import java.io.File JavaDoc;
42 import java.io.FileNotFoundException JavaDoc;
43 import java.io.IOException JavaDoc;
44 import java.io.InputStream JavaDoc;
45 import java.lang.reflect.Method JavaDoc;
46 import java.sql.PreparedStatement JavaDoc;
47 import java.sql.ResultSet JavaDoc;
48 import java.sql.SQLException JavaDoc;
49
50 /**
51  * The main XMPP server that will load, initialize and start all the server's
52  * modules. The server is unique in the JVM and could be obtained by using the
53  * {@link #getInstance()} method.<p>
54  *
55  * The loaded modules will be initialized and may access through the server other
56  * modules. This means that the only way for a module to locate another module is
57  * through the server. The server maintains a list of loaded modules.<p>
58  *
59  * After starting up all the modules the server will load any available plugin.
60  * For more information see: {@link org.jivesoftware.messenger.container.PluginManager}.
61  * </p>
62  *
63  * @author Gaston Dombiak
64  */

65 public class XMPPServer {
66
67     private static XMPPServer instance;
68
69     private String JavaDoc name;
70     private Version version;
71     private Date startDate;
72     private Date stopDate;
73     private boolean initialized = false;
74
75     /**
76      * All modules loaded by this server
77      */

78     private Map<Class JavaDoc,Module> modules = new HashMap<Class JavaDoc,Module>();
79
80     /**
81      * Location of the home directory. All configuration files should be
82      * located here.
83      */

84     private File JavaDoc messengerHome;
85     private ClassLoader JavaDoc loader;
86
87     private PluginManager pluginManager;
88     private InternalComponentManager componentManager;
89
90     /**
91      * True if in setup mode
92      */

93     private boolean setupMode = true;
94
95     private static final String JavaDoc STARTER_CLASSNAME =
96             "org.jivesoftware.messenger.starter.ServerStarter";
97     private static final String JavaDoc WRAPPER_CLASSNAME =
98             "org.tanukisoftware.wrapper.WrapperManager";
99
100     /**
101      * Returns a singleton instance of XMPPServer.
102      *
103      * @return an instance.
104      */

105     public static XMPPServer getInstance() {
106         return instance;
107     }
108
109     /**
110      * Creates a server and starts it.
111      */

112     public XMPPServer() {
113         // We may only have one instance of the server running on the JVM
114
if (instance != null) {
115             throw new IllegalStateException JavaDoc("A server is already running");
116         }
117         instance = this;
118         start();
119     }
120
121     /**
122      * Returns a snapshot of the server's status.
123      *
124      * @return the server information current at the time of the method call.
125      */

126     public XMPPServerInfo getServerInfo() {
127         if (!initialized) {
128             throw new IllegalStateException JavaDoc("Not initialized yet");
129         }
130         return new XMPPServerInfoImpl(name, version, startDate, stopDate, getConnectionManager());
131     }
132
133     /**
134      * Returns true if the given address is local to the server (managed by this
135      * server domain). Return false even if the jid's domain matches a local component's
136      * service JID.
137      *
138      * @param jid the JID to check.
139      * @return true if the address is a local address to this server.
140      */

141     public boolean isLocal(JID jid) {
142         boolean local = false;
143         if (jid != null && name != null && name.equalsIgnoreCase(jid.getDomain())) {
144             local = true;
145         }
146         return local;
147     }
148
149     /**
150      * Returns true if the given address does not match the local server hostname and does not
151      * match a component service JID.
152      *
153      * @param jid the JID to check.
154      * @return true if the given address does not match the local server hostname and does not
155      * match a component service JID.
156      */

157     public boolean isRemote(JID jid) {
158         if (jid != null) {
159             String JavaDoc domain = jid.getDomain();
160             if (!name.equals(domain) && componentManager.getComponent(domain) == null) {
161                 return true;
162             }
163         }
164         return false;
165     }
166
167     /**
168      * Creates an XMPPAddress local to this server.
169      *
170      * @param username the user name portion of the id or null to indicate none is needed.
171      * @param resource the resource portion of the id or null to indicate none is needed.
172      * @return an XMPPAddress for the server.
173      */

174     public JID createJID(String JavaDoc username, String JavaDoc resource) {
175         return new JID(username, name, resource);
176     }
177
178     private void initialize() throws FileNotFoundException JavaDoc {
179         // Set the name of the config file
180
JiveGlobals.setConfigName("jive-messenger.xml");
181
182         locateMessenger();
183
184         name = JiveGlobals.getProperty("xmpp.domain");
185         if (name == null) {
186             name = "127.0.0.1";
187         }
188
189         version = new Version(2, 2, 0, Version.ReleaseStatus.Release, -1);
190         if ("true".equals(JiveGlobals.getXMLProperty("setup"))) {
191             setupMode = false;
192         }
193
194         if (isStandAlone()) {
195             Runtime.getRuntime().addShutdownHook(new ShutdownHookThread());
196         }
197
198         loader = Thread.currentThread().getContextClassLoader();
199         componentManager = InternalComponentManager.getInstance();
200
201         initialized = true;
202     }
203
204     public void start() {
205         try {
206             initialize();
207
208             // If the server has already been setup then we can start all the server's modules
209
if (!setupMode) {
210                 verifyDataSource();
211                 // First load all the modules so that modules may access other modules while
212
// being initialized
213
loadModules();
214                 // Initize all the modules
215
initModules();
216                 // Start all the modules
217
startModules();
218             }
219             // Load plugins. First, initialize component manager.
220
InternalComponentManager.getInstance().start();
221             File JavaDoc pluginDir = new File JavaDoc(messengerHome, "plugins");
222             pluginManager = new PluginManager(pluginDir);
223             pluginManager.start();
224
225             // Log that the server has been started
226

227             List params = new ArrayList();
228             params.add(version.getVersionString());
229             params.add(JiveGlobals.formatDateTime(new Date()));
230             String JavaDoc startupBanner = LocaleUtils.getLocalizedString("startup.name", params);
231             Log.info(startupBanner);
232             System.out.println(startupBanner);
233
234             startDate = new Date();
235             stopDate = null;
236         }
237         catch (Exception JavaDoc e) {
238             e.printStackTrace();
239             Log.error(e);
240             System.out.println(LocaleUtils.getLocalizedString("startup.error"));
241             shutdownServer();
242         }
243     }
244
245     private void loadModules() {
246         // Load boot modules
247
loadModule(RoutingTableImpl.class.getName());
248         loadModule(AuditManagerImpl.class.getName());
249         loadModule(RosterManager.class.getName());
250         loadModule(PrivateStorage.class.getName());
251         // Load core modules
252
loadModule(PresenceManagerImpl.class.getName());
253         loadModule(SessionManager.class.getName());
254         loadModule(PacketRouter.class.getName());
255         loadModule(IQRouter.class.getName());
256         loadModule(MessageRouter.class.getName());
257         loadModule(PresenceRouter.class.getName());
258         loadModule(PacketTransporterImpl.class.getName());
259         loadModule(PacketDelivererImpl.class.getName());
260         loadModule(TransportHandler.class.getName());
261         loadModule(OfflineMessageStrategy.class.getName());
262         loadModule(OfflineMessageStore.class.getName());
263         // Load standard modules
264
loadModule(IQAuthHandler.class.getName());
265         loadModule(IQPrivateHandler.class.getName());
266         loadModule(IQRegisterHandler.class.getName());
267         loadModule(IQRosterHandler.class.getName());
268         loadModule(IQTimeHandler.class.getName());
269         loadModule(IQvCardHandler.class.getName());
270         loadModule(IQVersionHandler.class.getName());
271         loadModule(IQLastActivityHandler.class.getName());
272         loadModule(PresenceSubscribeHandler.class.getName());
273         loadModule(PresenceUpdateHandler.class.getName());
274         loadModule(IQDiscoInfoHandler.class.getName());
275         loadModule(IQDiscoItemsHandler.class.getName());
276         loadModule(IQOfflineMessagesHandler.class.getName());
277         loadModule(MultiUserChatServerImpl.class.getName());
278         loadModule(MulticastDNSService.class.getName());
279         // Load this module always last since we don't want to start listening for clients
280
// before the rest of the modules have been started
281
loadModule(ConnectionManagerImpl.class.getName());
282     }
283
284     /**
285      * Loads a module.
286      *
287      * @param module the name of the class that implements the Module interface.
288      */

289     private void loadModule(String JavaDoc module) {
290         Module mod = null;
291         try {
292             Class JavaDoc modClass = loader.loadClass(module);
293             mod = (Module)modClass.newInstance();
294             this.modules.put(modClass, mod);
295         }
296         catch (Exception JavaDoc e) {
297             e.printStackTrace();
298             Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
299         }
300     }
301
302     private void initModules() {
303         for (Module module : modules.values()) {
304             boolean isInitialized = false;
305             try {
306                 module.initialize(this);
307                 isInitialized = true;
308             }
309             catch (Exception JavaDoc e) {
310                 e.printStackTrace();
311                 // Remove the failed initialized module
312
this.modules.remove(module.getClass());
313                 if (isInitialized) {
314                     module.stop();
315                     module.destroy();
316                 }
317                 Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
318             }
319         }
320     }
321
322     /**
323      * <p>Following the loading and initialization of all the modules
324      * this method is called to iterate through the known modules and
325      * start them.</p>
326      */

327     private void startModules() {
328         for (Module module : modules.values()) {
329             boolean started = false;
330             try {
331                 module.start();
332             }
333             catch (Exception JavaDoc e) {
334                 if (started && module != null) {
335                     module.stop();
336                     module.destroy();
337                 }
338                 Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
339             }
340         }
341     }
342
343     /**
344      * Restarts the server and all it's modules only if the server is restartable. Otherwise do
345      * nothing.
346      */

347     public void restart() {
348         if (isStandAlone() && isRestartable()) {
349             try {
350                 Class JavaDoc wrapperClass = Class.forName(WRAPPER_CLASSNAME);
351                 Method JavaDoc restartMethod = wrapperClass.getMethod("restart", (Class JavaDoc [])null);
352                 restartMethod.invoke(null, (Object JavaDoc [])null);
353             }
354             catch (Exception JavaDoc e) {
355                 Log.error("Could not restart container", e);
356             }
357         }
358     }
359
360     /**
361      * Stops the server only if running in standalone mode. Do nothing if the server is running
362      * inside of another server.
363      */

364     public void stop() {
365         // Only do a system exit if we're running standalone
366
if (isStandAlone()) {
367             // if we're in a wrapper, we have to tell the wrapper to shut us down
368
if (isRestartable()) {
369                 try {
370                     Class JavaDoc wrapperClass = Class.forName(WRAPPER_CLASSNAME);
371                     Method JavaDoc stopMethod = wrapperClass.getMethod("stop", new Class JavaDoc[]{Integer.TYPE});
372                     stopMethod.invoke(null, new Object JavaDoc[]{0});
373                 }
374                 catch (Exception JavaDoc e) {
375                     Log.error("Could not stop container", e);
376                 }
377             }
378             else {
379                 shutdownServer();
380                 stopDate = new Date();
381                 Thread JavaDoc shutdownThread = new ShutdownThread();
382                 shutdownThread.setDaemon(true);
383                 shutdownThread.start();
384             }
385         }
386     }
387
388     public boolean isSetupMode() {
389         return setupMode;
390     }
391
392     public boolean isRestartable() {
393         boolean restartable = false;
394         try {
395             restartable = Class.forName(WRAPPER_CLASSNAME) != null;
396         }
397         catch (ClassNotFoundException JavaDoc e) {
398             restartable = false;
399         }
400         return restartable;
401     }
402
403     /**
404      * Returns if the server is running in standalone mode. We consider that it's running in
405      * standalone if the "org.jivesoftware.messenger.starter.ServerStarter" class is present in the
406      * system.
407      *
408      * @return true if the server is running in standalone mode.
409      */

410     public boolean isStandAlone() {
411         boolean standalone = false;
412         try {
413             standalone = Class.forName(STARTER_CLASSNAME) != null;
414         }
415         catch (ClassNotFoundException JavaDoc e) {
416             standalone = false;
417         }
418         return standalone;
419     }
420
421     /**
422      * Verify that the database is accessible.
423      */

424     private void verifyDataSource() {
425         java.sql.Connection JavaDoc conn = null;
426         try {
427             conn = DbConnectionManager.getConnection();
428             PreparedStatement JavaDoc stmt = conn.prepareStatement("SELECT count(*) FROM jiveID");
429             ResultSet JavaDoc rs = stmt.executeQuery();
430             rs.next();
431             rs.close();
432             stmt.close();
433         }
434         catch (Exception JavaDoc e) {
435             System.err.println("Database setup or configuration error: " +
436                     "Please verify your database settings and check the " +
437                     "logs/error.log file for detailed error messages.");
438             Log.error("Database could not be accessed", e);
439             throw new IllegalArgumentException JavaDoc(e);
440         }
441         finally {
442             if (conn != null) {
443                 try { conn.close(); }
444                 catch (SQLException JavaDoc e) { Log.error(e); }
445             }
446         }
447     }
448
449     /**
450      * Verifies that the given home guess is a real Messenger home directory.
451      * We do the verification by checking for the Messenger config file in
452      * the config dir of jiveHome.
453      *
454      * @param homeGuess a guess at the path to the home directory.
455      * @param jiveConfigName the name of the config file to check.
456      * @return a file pointing to the home directory or null if the
457      * home directory guess was wrong.
458      * @throws java.io.FileNotFoundException if there was a problem with the home
459      * directory provided
460      */

461     private File JavaDoc verifyHome(String JavaDoc homeGuess, String JavaDoc jiveConfigName) throws FileNotFoundException JavaDoc {
462         File JavaDoc realHome = null;
463         File JavaDoc guess = new File JavaDoc(homeGuess);
464         File JavaDoc configFileGuess = new File JavaDoc(guess, jiveConfigName);
465         if (configFileGuess.exists()) {
466             realHome = guess;
467         }
468         File JavaDoc messengerHome = new File JavaDoc(guess, jiveConfigName);
469         if (!messengerHome.exists()) {
470             throw new FileNotFoundException JavaDoc();
471         }
472
473         try{
474             return new File JavaDoc(realHome.getCanonicalPath());
475         }
476         catch(Exception JavaDoc ex){
477            throw new FileNotFoundException JavaDoc();
478         }
479     }
480
481     /**
482      * <p>Retrieve the jive home for the container.</p>
483      *
484      * @throws FileNotFoundException If jiveHome could not be located
485      */

486     private void locateMessenger() throws FileNotFoundException JavaDoc {
487         String JavaDoc jiveConfigName = "conf" + File.separator + "jive-messenger.xml";
488         // First, try to load it messengerHome as a system property.
489
if (messengerHome == null) {
490             String JavaDoc homeProperty = System.getProperty("messengerHome");
491             try {
492                 if (homeProperty != null) {
493                     messengerHome = verifyHome(homeProperty, jiveConfigName);
494                 }
495             }
496             catch (FileNotFoundException JavaDoc fe) {
497
498             }
499         }
500
501         // If we still don't have home, let's assume this is standalone
502
// and just look for home in a standard sub-dir location and verify
503
// by looking for the config file
504
if (messengerHome == null) {
505             try {
506                 messengerHome = verifyHome("..", jiveConfigName).getCanonicalFile();
507             }
508             catch (FileNotFoundException JavaDoc fe) {
509             }
510             catch (IOException JavaDoc ie) {
511             }
512         }
513
514         // If home is still null, no outside process has set it and
515
// we have to attempt to load the value from messenger_init.xml,
516
// which must be in the classpath.
517
if (messengerHome == null) {
518             InputStream JavaDoc in = null;
519             try {
520                 in = getClass().getResourceAsStream("/messenger_init.xml");
521                 if (in != null) {
522                     SAXReader reader = new SAXReader();
523                     Document doc = reader.read(in);
524                     String JavaDoc path = doc.getRootElement().getText();
525                     try {
526                         if (path != null) {
527                             messengerHome = verifyHome(path, jiveConfigName);
528                         }
529                     }
530                     catch (FileNotFoundException JavaDoc fe) {
531                         fe.printStackTrace();
532                     }
533                 }
534             }
535             catch (Exception JavaDoc e) {
536                 System.err.println("Error loading messenger_init.xml to find home.");
537                 e.printStackTrace();
538             }
539             finally {
540                 try { if (in != null) { in.close(); } }
541                 catch (Exception JavaDoc e) {
542                     System.err.println("Could not close open connection");
543                     e.printStackTrace();
544                 }
545             }
546         }
547
548         if (messengerHome == null) {
549             System.err.println("Could not locate home");
550             throw new FileNotFoundException JavaDoc();
551         }
552         else {
553             JiveGlobals.home = messengerHome.toString();
554         }
555     }
556
557     /**
558      * <p>A thread to ensure the server shuts down no matter what.</p>
559      * <p>Spawned when stop() is called in standalone mode, we wait a few
560      * seconds then call system exit().</p>
561      *
562      * @author Iain Shigeoka
563      */

564     private class ShutdownHookThread extends Thread JavaDoc {
565         /**
566          * <p>Logs the server shutdown.</p>
567          */

568         public void run() {
569             shutdownServer();
570             Log.info("Server halted");
571             System.err.println("Server halted");
572         }
573     }
574
575     /**
576      * <p>A thread to ensure the server shuts down no matter what.</p>
577      * <p>Spawned when stop() is called in standalone mode, we wait a few
578      * seconds then call system exit().</p>
579      *
580      * @author Iain Shigeoka
581      */

582     private class ShutdownThread extends Thread JavaDoc {
583         /**
584          * <p>Shuts down the JVM after a 5 second delay.</p>
585          */

586         public void run() {
587             try {
588                 Thread.sleep(5000);
589                 // No matter what, we make sure it's dead
590
System.exit(0);
591             }
592             catch (InterruptedException JavaDoc e) {
593             }
594
595         }
596     }
597
598     /**
599      * Makes a best effort attempt to shutdown the server
600      */

601     private void shutdownServer() {
602         // If we don't have modules then the server has already been shutdown
603
if (modules.isEmpty()) {
604             return;
605         }
606         // Get all modules and stop and destroy them
607
for (Module module : modules.values()) {
608             module.stop();
609             module.destroy();
610         }
611         modules.clear();
612         // Stop all plugins
613
if (pluginManager != null) {
614             pluginManager.shutdown();
615         }
616         // Stop the Db connection manager.
617
DbConnectionManager.getConnectionProvider().destroy();
618         // TODO: hack to allow safe stopping
619
Log.info("Jive Messenger stopped");
620     }
621
622     /**
623      * Returns the <code>ConnectionManager</code> registered with this server. The
624      * <code>ConnectionManager</code> was registered with the server as a module while starting up
625      * the server.
626      *
627      * @return the <code>ConnectionManager</code> registered with this server.
628      */

629     public ConnectionManager getConnectionManager() {
630         return (ConnectionManager) modules.get(ConnectionManagerImpl.class);
631     }
632
633     /**
634      * Returns the <code>RoutingTable</code> registered with this server. The
635      * <code>RoutingTable</code> was registered with the server as a module while starting up
636      * the server.
637      *
638      * @return the <code>RoutingTable</code> registered with this server.
639      */

640     public RoutingTable getRoutingTable() {
641         return (RoutingTable) modules.get(RoutingTableImpl.class);
642     }
643
644     /**
645      * Returns the <code>PacketDeliverer</code> registered with this server. The
646      * <code>PacketDeliverer</code> was registered with the server as a module while starting up
647      * the server.
648      *
649      * @return the <code>PacketDeliverer</code> registered with this server.
650      */

651     public PacketDeliverer getPacketDeliverer() {
652         return (PacketDeliverer) modules.get(PacketDelivererImpl.class);
653     }
654
655     /**
656      * Returns the <code>RosterManager</code> registered with this server. The
657      * <code>RosterManager</code> was registered with the server as a module while starting up
658      * the server.
659      *
660      * @return the <code>RosterManager</code> registered with this server.
661      */

662     public RosterManager getRosterManager() {
663         return (RosterManager) modules.get(RosterManager.class);
664     }
665
666     /**
667      * Returns the <code>PresenceManager</code> registered with this server. The
668      * <code>PresenceManager</code> was registered with the server as a module while starting up
669      * the server.
670      *
671      * @return the <code>PresenceManager</code> registered with this server.
672      */

673     public PresenceManager getPresenceManager() {
674         return (PresenceManager) modules.get(PresenceManagerImpl.class);
675     }
676
677     /**
678      * Returns the <code>OfflineMessageStore</code> registered with this server. The
679      * <code>OfflineMessageStore</code> was registered with the server as a module while starting up
680      * the server.
681      *
682      * @return the <code>OfflineMessageStore</code> registered with this server.
683      */

684     public OfflineMessageStore getOfflineMessageStore() {
685         return (OfflineMessageStore) modules.get(OfflineMessageStore.class);
686     }
687
688     /**
689      * Returns the <code>OfflineMessageStrategy</code> registered with this server. The
690      * <code>OfflineMessageStrategy</code> was registered with the server as a module while starting
691      * up the server.
692      *
693      * @return the <code>OfflineMessageStrategy</code> registered with this server.
694      */

695     public OfflineMessageStrategy getOfflineMessageStrategy() {
696         return (OfflineMessageStrategy)modules.get(OfflineMessageStrategy.class);
697     }
698
699     /**
700      * Returns the <code>PacketRouter</code> registered with this server. The
701      * <code>PacketRouter</code> was registered with the server as a module while starting up
702      * the server.
703      *
704      * @return the <code>PacketRouter</code> registered with this server.
705      */

706     public PacketRouter getPacketRouter() {
707         return (PacketRouter)modules.get(PacketRouter.class);
708     }
709
710     /**
711      * Returns the <code>IQRegisterHandler</code> registered with this server. The
712      * <code>IQRegisterHandler</code> was registered with the server as a module while starting up
713      * the server.
714      *
715      * @return the <code>IQRegisterHandler</code> registered with this server.
716      */

717     public IQRegisterHandler getIQRegisterHandler() {
718         return (IQRegisterHandler)modules.get(IQRegisterHandler.class);
719     }
720
721     /**
722      * Returns the <code>PluginManager</code> instance registered with this server.
723      *
724      * @return the PluginManager instance.
725      */

726     public PluginManager getPluginManager() {
727         return pluginManager;
728     }
729
730     /**
731      * Returns a list with all the modules registered with the server that inherit from IQHandler.
732      *
733      * @return a list with all the modules registered with the server that inherit from IQHandler.
734      */

735     public List<IQHandler> getIQHandlers() {
736         List<IQHandler> answer = new ArrayList<IQHandler>();
737         for (Module module : modules.values()) {
738             if (module instanceof IQHandler) {
739                 answer.add((IQHandler)module);
740             }
741         }
742         return answer;
743     }
744
745     /**
746      * Returns the <code>SessionManager</code> registered with this server. The
747      * <code>SessionManager</code> was registered with the server as a module while starting up
748      * the server.
749      *
750      * @return the <code>SessionManager</code> registered with this server.
751      */

752     public SessionManager getSessionManager() {
753         return (SessionManager) modules.get(SessionManager.class);
754     }
755
756     /**
757      * Returns the <code>TransportHandler</code> registered with this server. The
758      * <code>TransportHandler</code> was registered with the server as a module while starting up
759      * the server.
760      *
761      * @return the <code>TransportHandler</code> registered with this server.
762      */

763     public TransportHandler getTransportHandler() {
764         return (TransportHandler) modules.get(TransportHandler.class);
765     }
766
767     /**
768      * Returns the <code>PresenceUpdateHandler</code> registered with this server. The
769      * <code>PresenceUpdateHandler</code> was registered with the server as a module while starting
770      * up the server.
771      *
772      * @return the <code>PresenceUpdateHandler</code> registered with this server.
773      */

774     public PresenceUpdateHandler getPresenceUpdateHandler() {
775         return (PresenceUpdateHandler) modules.get(PresenceUpdateHandler.class);
776     }
777
778     /**
779      * Returns the <code>PresenceSubscribeHandler</code> registered with this server. The
780      * <code>PresenceSubscribeHandler</code> was registered with the server as a module while
781      * starting up the server.
782      *
783      * @return the <code>PresenceSubscribeHandler</code> registered with this server.
784      */

785     public PresenceSubscribeHandler getPresenceSubscribeHandler() {
786         return (PresenceSubscribeHandler) modules.get(PresenceSubscribeHandler.class);
787     }
788
789     /**
790      * Returns the <code>IQRouter</code> registered with this server. The
791      * <code>IQRouter</code> was registered with the server as a module while starting up
792      * the server.
793      *
794      * @return the <code>IQRouter</code> registered with this server.
795      */

796     public IQRouter getIQRouter() {
797         return (IQRouter) modules.get(IQRouter.class);
798     }
799
800     /**
801      * Returns the <code>MessageRouter</code> registered with this server. The
802      * <code>MessageRouter</code> was registered with the server as a module while starting up
803      * the server.
804      *
805      * @return the <code>MessageRouter</code> registered with this server.
806      */

807     public MessageRouter getMessageRouter() {
808         return (MessageRouter) modules.get(MessageRouter.class);
809     }
810
811     /**
812      * Returns the <code>PresenceRouter</code> registered with this server. The
813      * <code>PresenceRouter</code> was registered with the server as a module while starting up
814      * the server.
815      *
816      * @return the <code>PresenceRouter</code> registered with this server.
817      */

818     public PresenceRouter getPresenceRouter() {
819         return (PresenceRouter) modules.get(PresenceRouter.class);
820     }
821
822     /**
823      * Returns the <code>UserManager</code> registered with this server. The
824      * <code>UserManager</code> was registered with the server as a module while starting up
825      * the server.
826      *
827      * @return the <code>UserManager</code> registered with this server.
828      */

829     public UserManager getUserManager() {
830         return UserManager.getInstance();
831     }
832
833     /**
834      * Returns the <code>AuditManager</code> registered with this server. The
835      * <code>AuditManager</code> was registered with the server as a module while starting up
836      * the server.
837      *
838      * @return the <code>AuditManager</code> registered with this server.
839      */

840     public AuditManager getAuditManager() {
841         return (AuditManager) modules.get(AuditManagerImpl.class);
842     }
843
844     /**
845      * Returns a list with all the modules that provide "discoverable" features.
846      *
847      * @return a list with all the modules that provide "discoverable" features.
848      */

849     public List<ServerFeaturesProvider> getServerFeaturesProviders() {
850         List<ServerFeaturesProvider> answer = new ArrayList<ServerFeaturesProvider>();
851         for (Module module : modules.values()) {
852             if (module instanceof ServerFeaturesProvider) {
853                 answer.add((ServerFeaturesProvider) module);
854             }
855         }
856         return answer;
857     }
858
859     /**
860      * Returns a list with all the modules that provide "discoverable" items associated with
861      * the server.
862      *
863      * @return a list with all the modules that provide "discoverable" items associated with
864      * the server.
865      */

866     public List<ServerItemsProvider> getServerItemsProviders() {
867         List<ServerItemsProvider> answer = new ArrayList<ServerItemsProvider>();
868         for (Module module : modules.values()) {
869             if (module instanceof ServerItemsProvider) {
870                 answer.add((ServerItemsProvider) module);
871             }
872         }
873         return answer;
874     }
875
876     /**
877      * Returns the <code>IQDiscoInfoHandler</code> registered with this server. The
878      * <code>IQDiscoInfoHandler</code> was registered with the server as a module while starting up
879      * the server.
880      *
881      * @return the <code>IQDiscoInfoHandler</code> registered with this server.
882      */

883     public IQDiscoInfoHandler getIQDiscoInfoHandler() {
884         return (IQDiscoInfoHandler) modules.get(IQDiscoInfoHandler.class);
885     }
886
887     /**
888      * Returns the <code>IQDiscoItemsHandler</code> registered with this server. The
889      * <code>IQDiscoItemsHandler</code> was registered with the server as a module while starting up
890      * the server.
891      *
892      * @return the <code>IQDiscoItemsHandler</code> registered with this server.
893      */

894     public IQDiscoItemsHandler getIQDiscoItemsHandler() {
895         return (IQDiscoItemsHandler) modules.get(IQDiscoItemsHandler.class);
896     }
897
898     /**
899      * Returns the <code>PrivateStorage</code> registered with this server. The
900      * <code>PrivateStorage</code> was registered with the server as a module while starting up
901      * the server.
902      *
903      * @return the <code>PrivateStorage</code> registered with this server.
904      */

905     public PrivateStorage getPrivateStorage() {
906         return (PrivateStorage) modules.get(PrivateStorage.class);
907     }
908
909     /**
910      * Returns the <code>MultiUserChatServer</code> registered with this server. The
911      * <code>MultiUserChatServer</code> was registered with the server as a module while starting up
912      * the server.
913      *
914      * @return the <code>MultiUserChatServer</code> registered with this server.
915      */

916     public MultiUserChatServer getMultiUserChatServer() {
917         return (MultiUserChatServer) modules.get(MultiUserChatServerImpl.class);
918     }
919 }
920
Popular Tags