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);
}
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);
}
}
}
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;
}
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);
}
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;
}
Aggregations