Class GerritProjectListUpdater

  • All Implemented Interfaces:
    NamedGerritEventListener, com.sonymobile.tools.gerrit.gerritevents.ConnectionListener, com.sonymobile.tools.gerrit.gerritevents.GerritEventListener

    public class GerritProjectListUpdater
    extends Object
    implements com.sonymobile.tools.gerrit.gerritevents.ConnectionListener, NamedGerritEventListener
    Class responsible for providing the Config object with a list of all available Gerrit projects. Executed periodically on a timely basis and every time the connection to the Gerrit server has been restored.
    Author:
    Gustaf Lundh <Gustaf.Lundh@sonyericsson.com>
    • Field Detail

    • Constructor Detail

      • GerritProjectListUpdater

        public GerritProjectListUpdater​(String serverName)
        Default constructor.
        Parameters:
        serverName - the name of the Gerrit server.
    • Method Detail

      • getTimerUpdatePeriod

        public int getTimerUpdatePeriod()
        The update period currently being used by the timer.
        Returns:
        the update period, in minutes.
      • setTimerUpdatePeriod

        public void setTimerUpdatePeriod​(int timerUpdatePeriod)
        Sets a new value for the timer update period, in minutes.
        Parameters:
        timerUpdatePeriod - the new update period, in minutes.
      • connectionEstablished

        public void connectionEstablished()
        Specified by:
        connectionEstablished in interface com.sonymobile.tools.gerrit.gerritevents.ConnectionListener
      • connectionDown

        public void connectionDown()
        Specified by:
        connectionDown in interface com.sonymobile.tools.gerrit.gerritevents.ConnectionListener
      • gerritEvent

        public void gerritEvent​(com.sonymobile.tools.gerrit.gerritevents.dto.GerritEvent gerritEvent)
        Specified by:
        gerritEvent in interface com.sonymobile.tools.gerrit.gerritevents.GerritEventListener
      • gerritEvent

        public void gerritEvent​(com.sonymobile.tools.gerrit.gerritevents.dto.events.ProjectCreated gerritEvent)
        OverLoaded gerritEvent(GerritEvent gerritEvent).
        Parameters:
        gerritEvent - the event.
      • initProjectListUpdater

        public void initProjectListUpdater()
        Initialize project list updater.
      • cancelProjectListUpdater

        public void cancelProjectListUpdater()
        Cancel project list update timer.
      • scheduleProjectListUpdate

        public void scheduleProjectListUpdate​(int initDelay,
                                              int updatePeriod)
        This method creates a timer that schedule the update of the gerrit project list.
        Parameters:
        initDelay - the initial delay, in seconds.
        updatePeriod - the update period, in seconds.
      • readProjects

        public static List<String> readProjects​(Reader commandReader)
                                         throws IOException
        Reads a list of Gerrit projects from a Reader, one project per line. As from command: gerrit ls-projects.
        Parameters:
        commandReader - the Reader.
        Returns:
        a list of projects
        Throws:
        IOException - if something unfortunate happens.
      • isConnected

        public boolean isConnected()
        Returns:
        if connected to Gerrit.
      • setConnected

        public void setConnected​(boolean connected)
        Parameters:
        connected - the connected to set.
      • addGerritProject

        public void addGerritProject​(String gerritProject)
        Adds a Gerrit project to this.gerritProjects.
        Parameters:
        gerritProject - the Gerrit project to add.
      • setGerritProjects

        public void setGerritProjects​(List<String> projects)
        Sets the internal Gerrit project list.
        Parameters:
        projects - The list of projects
      • getGerritProjects

        public List<String> getGerritProjects()
        Returns a string list of Gerrit projects.
        Returns:
        list of gerrit projects