Class TemplateTracker

  • All Implemented Interfaces:
    Tracker

    public class TemplateTracker
    extends AbstractTracker
    Class for tracking the templates execution by the users. When a user executes a template, a new track is saved into the database and saved into the memory too.
    Author:
    dbutano
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected TemplateTracker​(java.util.Queue<Track> trackQueue)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.util.Map<java.lang.String,​java.lang.Integer> getAccessCounter​(java.sql.Connection con)
      Return the number of executions for each public template
      static TemplateTracker getInstance​(java.sql.Connection con, java.util.Queue<Track> trackQueue)
      Return an instance of the TemplateTracker
      java.util.Map<java.lang.String,​java.lang.Double> getLogarithmMap​(java.lang.String userName, java.lang.String sessionId, TemplateManager templateManager)
      Return a map containing the logarithm of accesses for each template.
      java.lang.String getName()
      Return the tracker's name
      protected java.util.Map<java.lang.String,​java.lang.Integer> getRank​(TemplateManager templateManager)
      Return the rank for each public template.It represents a relationship between the templates executions; a template with rank 1 has been executed more than a template with rank 2.
      protected java.lang.Integer getRank​(TemplateManager templateManager, java.lang.String templateName)
      get rank for a specific template
      java.lang.String getStatementCreatingTable()
      Generate the sql statement to create the table used by the tracker
      protected void trackTemplate​(java.lang.String templateName, Profile profile, java.lang.String sessionIdentifier)
      Store into the database the template execution by the user or if the user is not logged during a specific http session.
      protected void updateTemplateName​(java.lang.String oldTemplateName, java.lang.String newTemplateName, java.sql.Connection con)
      Update the template name value into the database
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TemplateTracker

        protected TemplateTracker​(java.util.Queue<Track> trackQueue)
        Parameters:
        trackQueue - queue
    • Method Detail

      • getInstance

        public static TemplateTracker getInstance​(java.sql.Connection con,
                                                  java.util.Queue<Track> trackQueue)
        Return an instance of the TemplateTracker
        Parameters:
        con - connection to the database
        trackQueue - queue
        Returns:
        TemplateTracker the template tracker
      • trackTemplate

        protected void trackTemplate​(java.lang.String templateName,
                                     Profile profile,
                                     java.lang.String sessionIdentifier)
        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.
        Parameters:
        templateName - the template name
        profile - the user profile
        sessionIdentifier - the session id
      • getAccessCounter

        protected java.util.Map<java.lang.String,​java.lang.Integer> getAccessCounter​(java.sql.Connection con)
        Return the number of executions for each public template
        Parameters:
        con - db connection
        Returns:
        map with key the template name and executions number
      • getRank

        protected java.util.Map<java.lang.String,​java.lang.Integer> getRank​(TemplateManager templateManager)
        Return the rank for each public template.It represents a relationship between the templates executions; a template with rank 1 has been executed more than a template with rank 2. The rank is calculated by summing the logarithm of the templates executions launched by the single users, if the user is logged in, or otherwise, by summing the logarithm of the templates executions during the same http session. The function is called only by the super user
        Parameters:
        templateManager - the template manager used to retrieve the global templates
        Returns:
        map with key the template name and rank
      • getRank

        protected java.lang.Integer getRank​(TemplateManager templateManager,
                                            java.lang.String templateName)
        get rank for a specific template
        Parameters:
        templateManager - manager of templates
        templateName - template to test
        Returns:
        rank as an integer
      • getLogarithmMap

        public java.util.Map<java.lang.String,​java.lang.Double> getLogarithmMap​(java.lang.String userName,
                                                                                      java.lang.String sessionId,
                                                                                      TemplateManager templateManager)
        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
        Parameters:
        userName - the user name
        sessionId - the http session identifier
        templateManager - the template manager used to retrieve the global templates
        Returns:
        map of logarithm of accesses
      • updateTemplateName

        protected void updateTemplateName​(java.lang.String oldTemplateName,
                                          java.lang.String newTemplateName,
                                          java.sql.Connection con)
        Update the template name value into the database
        Parameters:
        oldTemplateName - the old name
        newTemplateName - the new name
        con - the connection
      • getStatementCreatingTable

        public java.lang.String getStatementCreatingTable()
        Generate the sql statement to create the table used by the tracker
        Specified by:
        getStatementCreatingTable in class AbstractTracker
        Returns:
        String sql statement
      • getName

        public java.lang.String getName()
        Return the tracker's name
        Specified by:
        getName in interface Tracker
        Specified by:
        getName in class AbstractTracker
        Returns:
        String tracker's name