/openfire_src/src/plugins/monitoring/src/java/org/jivesoftware/openfire/plugin/MonitoringPlugin.java

https://github.com/treejames/openfire-1 · Java · 208 lines · 133 code · 35 blank · 40 comment · 6 complexity · ef2d056e1c26f6868e7e1d37ffa16f2c MD5 · raw file

  1. /**
  2. * $Revision: 3034 $
  3. * $Date: 2005-11-04 21:02:33 -0300 (Fri, 04 Nov 2005) $
  4. *
  5. * Copyright (C) 2008 Jive Software. All rights reserved.
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. */
  19. package org.jivesoftware.openfire.plugin;
  20. import java.io.File;
  21. import java.io.FileFilter;
  22. import org.jivesoftware.openfire.XMPPServer;
  23. import org.jivesoftware.openfire.archive.ArchiveIndexer;
  24. import org.jivesoftware.openfire.archive.ArchiveInterceptor;
  25. import org.jivesoftware.openfire.archive.ArchiveSearcher;
  26. import org.jivesoftware.openfire.archive.ConversationManager;
  27. import org.jivesoftware.openfire.archive.GroupConversationInterceptor;
  28. import org.jivesoftware.openfire.archive.MonitoringConstants;
  29. import org.jivesoftware.openfire.container.Plugin;
  30. import org.jivesoftware.openfire.container.PluginManager;
  31. import org.jivesoftware.openfire.reporting.graph.GraphEngine;
  32. import org.jivesoftware.openfire.reporting.stats.DefaultStatsViewer;
  33. import org.jivesoftware.openfire.reporting.stats.MockStatsViewer;
  34. import org.jivesoftware.openfire.reporting.stats.StatisticsModule;
  35. import org.jivesoftware.openfire.reporting.stats.StatsEngine;
  36. import org.jivesoftware.openfire.reporting.stats.StatsViewer;
  37. import org.jivesoftware.openfire.reporting.util.TaskEngine;
  38. import org.jivesoftware.util.JiveGlobals;
  39. import org.jivesoftware.util.JiveProperties;
  40. import org.picocontainer.MutablePicoContainer;
  41. import org.picocontainer.defaults.DefaultPicoContainer;
  42. import com.reucon.openfire.plugin.archive.ArchiveManager;
  43. import com.reucon.openfire.plugin.archive.ArchiveProperties;
  44. import com.reucon.openfire.plugin.archive.IndexManager;
  45. import com.reucon.openfire.plugin.archive.PersistenceManager;
  46. import com.reucon.openfire.plugin.archive.impl.ArchiveManagerImpl;
  47. import com.reucon.openfire.plugin.archive.impl.JdbcPersistenceManager;
  48. import com.reucon.openfire.plugin.archive.xep0136.Xep0136Support;
  49. /**
  50. * Openfire Monitoring plugin.
  51. *
  52. * @author Matt Tucker
  53. */
  54. public class MonitoringPlugin implements Plugin {
  55. private static final int DEFAULT_CONVERSATION_TIMEOUT = 30; // minutes
  56. private MutablePicoContainer picoContainer;
  57. private boolean shuttingDown = false;
  58. private int conversationTimeout;
  59. private static MonitoringPlugin instance;
  60. private boolean enabled = true;
  61. private PersistenceManager persistenceManager;
  62. private ArchiveManager archiveManager;
  63. private IndexManager indexManager;
  64. private Xep0136Support xep0136Support;
  65. public MonitoringPlugin() {
  66. instance = this;
  67. // Enable AWT headless mode so that stats will work in headless
  68. // environments.
  69. System.setProperty("java.awt.headless", "true");
  70. picoContainer = new DefaultPicoContainer();
  71. picoContainer.registerComponentInstance(TaskEngine.getInstance());
  72. picoContainer.registerComponentInstance(JiveProperties.getInstance());
  73. // Stats and Graphing classes
  74. picoContainer.registerComponentImplementation(StatsEngine.class);
  75. picoContainer.registerComponentImplementation(GraphEngine.class);
  76. picoContainer.registerComponentImplementation(StatisticsModule.class);
  77. picoContainer.registerComponentImplementation(StatsViewer.class,
  78. getStatsViewerImplementation());
  79. // Archive classes
  80. picoContainer
  81. .registerComponentImplementation(ConversationManager.class);
  82. picoContainer.registerComponentImplementation(ArchiveInterceptor.class);
  83. picoContainer
  84. .registerComponentImplementation(GroupConversationInterceptor.class);
  85. picoContainer.registerComponentImplementation(ArchiveSearcher.class);
  86. picoContainer.registerComponentImplementation(ArchiveIndexer.class);
  87. }
  88. private Class<? extends StatsViewer> getStatsViewerImplementation() {
  89. if (JiveGlobals.getBooleanProperty("stats.mock.viewer", false)) {
  90. return MockStatsViewer.class;
  91. } else {
  92. return DefaultStatsViewer.class;
  93. }
  94. }
  95. public static MonitoringPlugin getInstance() {
  96. return instance;
  97. }
  98. /* enabled property */
  99. public boolean isEnabled() {
  100. return this.enabled;
  101. }
  102. public ArchiveManager getArchiveManager() {
  103. return archiveManager;
  104. }
  105. public IndexManager getIndexManager() {
  106. return indexManager;
  107. }
  108. public PersistenceManager getPersistenceManager() {
  109. return persistenceManager;
  110. }
  111. /**
  112. * Returns the instance of a module registered with the Monitoring plugin.
  113. *
  114. * @param clazz
  115. * the module class.
  116. * @return the instance of the module.
  117. */
  118. public Object getModule(Class<?> clazz) {
  119. return picoContainer.getComponentInstanceOfType(clazz);
  120. }
  121. public void initializePlugin(PluginManager manager, File pluginDirectory) {
  122. /* Configuration */
  123. conversationTimeout = JiveGlobals.getIntProperty(
  124. ArchiveProperties.CONVERSATION_TIMEOUT,
  125. DEFAULT_CONVERSATION_TIMEOUT);
  126. enabled = JiveGlobals.getBooleanProperty(ArchiveProperties.ENABLED,
  127. false);
  128. persistenceManager = new JdbcPersistenceManager();
  129. archiveManager = new ArchiveManagerImpl(persistenceManager,
  130. indexManager, conversationTimeout);
  131. xep0136Support = new Xep0136Support(XMPPServer.getInstance());
  132. xep0136Support.start();
  133. System.out.println("Starting Monitoring Plugin");
  134. // Check if we Enterprise is installed and stop loading this plugin if
  135. // found
  136. File pluginDir = new File(JiveGlobals.getHomeDirectory(), "plugins");
  137. File[] jars = pluginDir.listFiles(new FileFilter() {
  138. public boolean accept(File pathname) {
  139. String fileName = pathname.getName().toLowerCase();
  140. return (fileName.equalsIgnoreCase("enterprise.jar"));
  141. }
  142. });
  143. if (jars.length > 0) {
  144. // Do not load this plugin since Enterprise is still installed
  145. System.out
  146. .println("Enterprise plugin found. Stopping Monitoring Plugin");
  147. throw new IllegalStateException(
  148. "This plugin cannot run next to the Enterprise plugin");
  149. }
  150. shuttingDown = false;
  151. // Make sure that the monitoring folder exists under the home directory
  152. File dir = new File(JiveGlobals.getHomeDirectory() + File.separator
  153. + MonitoringConstants.NAME);
  154. if (!dir.exists()) {
  155. dir.mkdirs();
  156. }
  157. picoContainer.start();
  158. xep0136Support = new Xep0136Support(XMPPServer.getInstance());
  159. xep0136Support.start();
  160. }
  161. public void destroyPlugin() {
  162. shuttingDown = true;
  163. if (picoContainer != null) {
  164. picoContainer.stop();
  165. picoContainer.dispose();
  166. picoContainer = null;
  167. }
  168. instance = null;
  169. }
  170. public boolean isShuttingDown() {
  171. return shuttingDown;
  172. }
  173. }