Search in sources :

Example 11 with MonitoringPlugin

use of org.jivesoftware.openfire.plugin.MonitoringPlugin in project Openfire by igniterealtime.

the class ConversationManager method start.

public void start() {
    metadataArchivingEnabled = JiveGlobals.getBooleanProperty("conversation.metadataArchiving", true);
    messageArchivingEnabled = JiveGlobals.getBooleanProperty("conversation.messageArchiving", false);
    if (messageArchivingEnabled && !metadataArchivingEnabled) {
        Log.warn("Metadata archiving must be enabled when message archiving is enabled. Overriding setting.");
        metadataArchivingEnabled = true;
    }
    roomArchivingEnabled = JiveGlobals.getBooleanProperty("conversation.roomArchiving", false);
    roomArchivingStanzasEnabled = JiveGlobals.getBooleanProperty("conversation.roomArchivingStanzas", false);
    roomsArchived = StringUtils.stringToCollection(JiveGlobals.getProperty("conversation.roomsArchived", ""));
    if (roomArchivingEnabled && !metadataArchivingEnabled) {
        Log.warn("Metadata archiving must be enabled when room archiving is enabled. Overriding setting.");
        metadataArchivingEnabled = true;
    }
    idleTime = JiveGlobals.getIntProperty("conversation.idleTime", DEFAULT_IDLE_TIME) * JiveConstants.MINUTE;
    maxTime = JiveGlobals.getIntProperty("conversation.maxTime", DEFAULT_MAX_TIME) * JiveConstants.MINUTE;
    maxAge = JiveGlobals.getIntProperty("conversation.maxAge", DEFAULT_MAX_AGE) * JiveConstants.DAY;
    maxRetrievable = JiveGlobals.getIntProperty("conversation.maxRetrievable", DEFAULT_MAX_RETRIEVABLE) * JiveConstants.DAY;
    // Listen for any changes to the conversation properties.
    propertyListener = new ConversationPropertyListener();
    PropertyEventDispatcher.addListener(propertyListener);
    conversationQueue = new ConcurrentLinkedQueue<Conversation>();
    messageQueue = new ConcurrentLinkedQueue<ArchivedMessage>();
    participantQueue = new ConcurrentLinkedQueue<RoomParticipant>();
    conversationListeners = new CopyOnWriteArraySet<ConversationListener>();
    // Schedule a task to do conversation archiving.
    archiveTask = new TimerTask() {

        @Override
        public void run() {
            new ArchivingTask().run();
        }
    };
    taskEngine.scheduleAtFixedRate(archiveTask, JiveConstants.MINUTE, JiveConstants.MINUTE);
    if (JiveGlobals.getProperty("conversation.maxTimeDebug") != null) {
        Log.info("Monitoring plugin max time value deleted. Must be left over from stalled userCreation plugin run.");
        JiveGlobals.deleteProperty("conversation.maxTimeDebug");
    }
    // Schedule a task to do conversation cleanup.
    cleanupTask = new TimerTask() {

        @Override
        public void run() {
            for (String key : conversations.keySet()) {
                Conversation conversation = conversations.get(key);
                long now = System.currentTimeMillis();
                if ((now - conversation.getLastActivity().getTime() > idleTime) || (now - conversation.getStartDate().getTime() > maxTime)) {
                    removeConversation(key, conversation, new Date(now));
                }
            }
        }
    };
    taskEngine.scheduleAtFixedRate(cleanupTask, JiveConstants.MINUTE * 5, JiveConstants.MINUTE * 5);
    // Schedule a task to do conversation purging.
    maxAgeTask = new TimerTask() {

        @Override
        public void run() {
            if (maxAge > 0) {
                // Delete conversations older than maxAge days
                Connection con = null;
                PreparedStatement pstmt1 = null;
                PreparedStatement pstmt2 = null;
                PreparedStatement pstmt3 = null;
                try {
                    con = DbConnectionManager.getConnection();
                    pstmt1 = con.prepareStatement(DELETE_CONVERSATION_1);
                    pstmt2 = con.prepareStatement(DELETE_CONVERSATION_2);
                    pstmt3 = con.prepareStatement(DELETE_CONVERSATION_3);
                    Date now = new Date();
                    Date maxAgeDate = new Date(now.getTime() - maxAge);
                    ArchiveSearch search = new ArchiveSearch();
                    search.setDateRangeMax(maxAgeDate);
                    MonitoringPlugin plugin = (MonitoringPlugin) XMPPServer.getInstance().getPluginManager().getPlugin(MonitoringConstants.NAME);
                    ArchiveSearcher archiveSearcher = (ArchiveSearcher) plugin.getModule(ArchiveSearcher.class);
                    Collection<Conversation> conversations = archiveSearcher.search(search);
                    int conversationDeleted = 0;
                    for (Conversation conversation : conversations) {
                        Log.debug("Deleting: " + conversation.getConversationID() + " with date: " + conversation.getStartDate() + " older than: " + maxAgeDate);
                        pstmt1.setLong(1, conversation.getConversationID());
                        pstmt1.execute();
                        pstmt2.setLong(1, conversation.getConversationID());
                        pstmt2.execute();
                        pstmt3.setLong(1, conversation.getConversationID());
                        pstmt3.execute();
                        conversationDeleted++;
                    }
                    if (conversationDeleted > 0) {
                        Log.info("Deleted " + conversationDeleted + " conversations with date older than: " + maxAgeDate);
                    }
                } catch (Exception e) {
                    Log.error(e.getMessage(), e);
                } finally {
                    DbConnectionManager.closeConnection(pstmt1, con);
                    DbConnectionManager.closeConnection(pstmt2, con);
                    DbConnectionManager.closeConnection(pstmt3, con);
                }
            }
        }
    };
    taskEngine.scheduleAtFixedRate(maxAgeTask, JiveConstants.MINUTE, JiveConstants.MINUTE);
    // Register a statistic.
    Statistic conversationStat = new Statistic() {

        public String getName() {
            return LocaleUtils.getLocalizedString("stat.conversation.name", MonitoringConstants.NAME);
        }

        public Type getStatType() {
            return Type.count;
        }

        public String getDescription() {
            return LocaleUtils.getLocalizedString("stat.conversation.desc", MonitoringConstants.NAME);
        }

        public String getUnits() {
            return LocaleUtils.getLocalizedString("stat.conversation.units", MonitoringConstants.NAME);
        }

        public double sample() {
            return getConversationCount();
        }

        public boolean isPartialSample() {
            return false;
        }
    };
    StatisticsManager.getInstance().addStatistic(CONVERSATIONS_KEY, conversationStat);
    InternalComponentManager.getInstance().addListener(this);
}
Also used : Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Date(java.util.Date) SQLException(java.sql.SQLException) NotFoundException(org.jivesoftware.util.NotFoundException) MonitoringPlugin(org.jivesoftware.openfire.plugin.MonitoringPlugin) TimerTask(java.util.TimerTask) Statistic(org.jivesoftware.openfire.stats.Statistic) Collection(java.util.Collection)

Example 12 with MonitoringPlugin

use of org.jivesoftware.openfire.plugin.MonitoringPlugin in project Openfire by igniterealtime.

the class ConversationPDFServlet method doGet.

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    long conversationID = ParamUtils.getLongParameter(request, "conversationID", -1);
    if (conversationID == -1) {
        return;
    }
    MonitoringPlugin plugin = (MonitoringPlugin) XMPPServer.getInstance().getPluginManager().getPlugin(MonitoringConstants.NAME);
    ConversationManager conversationManager = (ConversationManager) plugin.getModule(ConversationManager.class);
    Conversation conversation;
    if (conversationID > -1) {
        try {
            conversation = new Conversation(conversationManager, conversationID);
            ByteArrayOutputStream stream = new ConversationUtils().getConversationPDF(conversation);
            // setting some response headers
            response.setHeader("Expires", "0");
            response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
            response.setHeader("Pragma", "public");
            // setting the content type
            response.setContentType("application/pdf");
            // the content length is needed for MSIE!!!
            response.setContentLength(stream.size());
            // write ByteArrayOutputStream to the ServletOutputStream
            ServletOutputStream out = response.getOutputStream();
            stream.writeTo(out);
            out.flush();
        } catch (NotFoundException nfe) {
            Log.error(nfe.getMessage(), nfe);
        }
    }
}
Also used : MonitoringPlugin(org.jivesoftware.openfire.plugin.MonitoringPlugin) ServletOutputStream(javax.servlet.ServletOutputStream) NotFoundException(org.jivesoftware.util.NotFoundException) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 13 with MonitoringPlugin

use of org.jivesoftware.openfire.plugin.MonitoringPlugin in project Openfire by igniterealtime.

the class ConversationUtils method getConversationInfo.

public ConversationInfo getConversationInfo(long conversationID, boolean formatParticipants) {
    // Create ConversationInfo bean
    ConversationInfo info = new ConversationInfo();
    // Get handle on the Monitoring plugin
    MonitoringPlugin plugin = (MonitoringPlugin) XMPPServer.getInstance().getPluginManager().getPlugin(MonitoringConstants.NAME);
    ConversationManager conversationmanager = (ConversationManager) plugin.getModule(ConversationManager.class);
    try {
        Conversation conversation = conversationmanager.getConversation(conversationID);
        info = toConversationInfo(conversation, formatParticipants);
    } catch (NotFoundException e) {
        Log.error(e.getMessage(), e);
    }
    return info;
}
Also used : MonitoringPlugin(org.jivesoftware.openfire.plugin.MonitoringPlugin) NotFoundException(org.jivesoftware.util.NotFoundException)

Example 14 with MonitoringPlugin

use of org.jivesoftware.openfire.plugin.MonitoringPlugin in project Openfire by igniterealtime.

the class GraphServlet method init.

@Override
public void init() throws ServletException {
    // load dependencies
    MonitoringPlugin plugin = (MonitoringPlugin) XMPPServer.getInstance().getPluginManager().getPlugin(MonitoringConstants.NAME);
    this.graphEngine = (GraphEngine) plugin.getModule(GraphEngine.class);
    this.statsViewer = (StatsViewer) plugin.getModule(StatsViewer.class);
}
Also used : MonitoringPlugin(org.jivesoftware.openfire.plugin.MonitoringPlugin)

Example 15 with MonitoringPlugin

use of org.jivesoftware.openfire.plugin.MonitoringPlugin in project Openfire by igniterealtime.

the class StatsAction method getUpdatedStat.

private Map getUpdatedStat(String statkey, long[] timePeriod) {
    MonitoringPlugin plugin = (MonitoringPlugin) XMPPServer.getInstance().getPluginManager().getPlugin(MonitoringConstants.NAME);
    StatsViewer viewer = (StatsViewer) plugin.getModule(StatsViewer.class);
    String[] lowHigh = getLowAndHigh(statkey, timePeriod);
    Map stat = new HashMap();
    stat.put("low", lowHigh[0]);
    stat.put("high", lowHigh[1]);
    stat.put("count", (int) viewer.getCurrentValue(statkey)[0]);
    return stat;
}
Also used : MonitoringPlugin(org.jivesoftware.openfire.plugin.MonitoringPlugin) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

MonitoringPlugin (org.jivesoftware.openfire.plugin.MonitoringPlugin)15 ConversationManager (org.jivesoftware.openfire.archive.ConversationManager)6 NotFoundException (org.jivesoftware.util.NotFoundException)5 Date (java.util.Date)3 HashMap (java.util.HashMap)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Map (java.util.Map)2 Conversation (org.jivesoftware.openfire.archive.Conversation)2 Statistic (org.jivesoftware.openfire.stats.Statistic)2 JID (org.xmpp.packet.JID)2 DocumentException (com.lowagie.text.DocumentException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 NumberFormat (java.text.NumberFormat)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 TimerTask (java.util.TimerTask)1