/** * * @param trackQueue queue */ protected TemplateTracker(Queue<Track> trackQueue) { super(trackQueue, TrackerUtil.TEMPLATE_TRACKER_TABLE); templatesExecutionCache = new TemplatesExecutionMap(); LOG.info("Creating new " + getClass().getName() + " tracker"); }
/** * Return a map containing the logarithm of accesses for each template. The map is obtained * merging the map of logarithm of accesses for single users and the map of logarithm of * accesses for the single sessions * @param userName the user name * @param sessionId the http session identifier * @param templateManager the template manager used to retrieve the global templates * @return map of logarithm of accesses */ public Map<String, Double> getLogarithmMap(String userName, String sessionId, TemplateManager templateManager) { Map<String, Double> logarithmMap; if (userName == null && sessionId == null) { logarithmMap = templatesExecutionCache.getLogarithmMap(null, templateManager); } else { Map<String, Double> executionsByUser = new HashMap<String, Double>(); Map<String, Double> executionsBySessionId = new HashMap<String, Double>(); executionsByUser = templatesExecutionCache.getLogarithmMap(userName, templateManager); executionsBySessionId = templatesExecutionCache.getLogarithmMap(sessionId, templateManager); logarithmMap = mergeMap(executionsByUser, executionsBySessionId); } return logarithmMap; }
/** * Load the tracks retrieved from the database into TemplateExecutionMap object. */ private static void loadTemplatesExecutionCache(Connection con) { PreparedStatement stm = null; ResultSet rs = null; try { String sql = "SELECT tt.templatename, tt.username, tt.sessionidentifier" + " FROM templatetrack tt" + " LEFT JOIN tag t ON tt.templatename = t.objectidentifier" + " WHERE t.type = ? AND t.tagname = ?"; stm = con.prepareStatement(sql); stm.setString(1, TagTypes.TEMPLATE); stm.setString(2, TagNames.IM_PUBLIC); rs = stm.executeQuery(); TemplateTrack tt; while (rs.next()) { tt = new TemplateTrack(rs.getString(1), rs.getString(2), rs.getString(3)); templatesExecutionCache.addExecution(tt); } } catch (SQLException sqle) { LOG.error("Error during loading template tracks into the cache", sqle); } }
/** * Load the tracks retrieved from the database into TemplateExecutionMap object. */ private static void loadTemplatesExecutionCache(Connection con) { PreparedStatement stm = null; ResultSet rs = null; try { String sql = "SELECT tt.templatename, tt.username, tt.sessionidentifier" + " FROM templatetrack tt" + " LEFT JOIN tag t ON tt.templatename = t.objectidentifier" + " WHERE t.type = ? AND t.tagname = ?"; stm = con.prepareStatement(sql); stm.setString(1, TagTypes.TEMPLATE); stm.setString(2, TagNames.IM_PUBLIC); rs = stm.executeQuery(); TemplateTrack tt; while (rs.next()) { tt = new TemplateTrack(rs.getString(1), rs.getString(2), rs.getString(3)); templatesExecutionCache.addExecution(tt); } } catch (SQLException sqle) { LOG.error("Error during loading template tracks into the cache", sqle); } }
/** * Store into the database the template execution by the user or if the user is not logged * during a specific http session. Update the cache. * @param templateName the template name * @param profile the user profile * @param sessionIdentifier the session id */ protected void trackTemplate(String templateName, Profile profile, String sessionIdentifier) { String userName = (profile.getUsername() != null) ? profile.getUsername() : ""; TemplateTrack templateTrack = new TemplateTrack(templateName, userName, sessionIdentifier, new Timestamp(System.currentTimeMillis())); if (templateTracker != null) { templateTracker.storeTrack(templateTrack); templatesExecutionCache.addExecution(templateTrack); } else { LOG.warn("Template not tracked. Check if the TemplateTracker has been configured"); } }
/** * Return a map containing the logarithm of accesses for each template. The map is obtained * merging the map of logarithm of accesses for single users and the map of logarithm of * accesses for the single sessions * @param userName the user name * @param sessionId the http session identifier * @param templateManager the template manager used to retrieve the global templates * @return map of logarithm of accesses */ public Map<String, Double> getLogarithmMap(String userName, String sessionId, TemplateManager templateManager) { Map<String, Double> logarithmMap; if (userName == null && sessionId == null) { logarithmMap = templatesExecutionCache.getLogarithmMap(null, templateManager); } else { Map<String, Double> executionsByUser = new HashMap<String, Double>(); Map<String, Double> executionsBySessionId = new HashMap<String, Double>(); executionsByUser = templatesExecutionCache.getLogarithmMap(userName, templateManager); executionsBySessionId = templatesExecutionCache.getLogarithmMap(sessionId, templateManager); logarithmMap = mergeMap(executionsByUser, executionsBySessionId); } return logarithmMap; }
/** * * @param trackQueue queue */ protected TemplateTracker(Queue<Track> trackQueue) { super(trackQueue, TrackerUtil.TEMPLATE_TRACKER_TABLE); templatesExecutionCache = new TemplatesExecutionMap(); LOG.info("Creating new " + getClass().getName() + " tracker"); }
/** * Store into the database the template execution by the user or if the user is not logged * during a specific http session. Update the cache. * @param templateName the template name * @param profile the user profile * @param sessionIdentifier the session id */ protected void trackTemplate(String templateName, Profile profile, String sessionIdentifier) { String userName = (profile.getUsername() != null) ? profile.getUsername() : ""; TemplateTrack templateTrack = new TemplateTrack(templateName, userName, sessionIdentifier, new Timestamp(System.currentTimeMillis())); if (templateTracker != null) { templateTracker.storeTrack(templateTrack); templatesExecutionCache.addExecution(templateTrack); } else { LOG.warn("Template not tracked. Check if the TemplateTracker has been configured"); } }
Map<String, Double> templateMergedRank = templatesExecutionCache.getLogarithmMap(null, templateManager);
Map<String, Double> templateMergedRank = templatesExecutionCache.getLogarithmMap(null, templateManager);