Class GerritProjectListUpdater

java.lang.Object
com.sonyericsson.hudson.plugins.gerrit.trigger.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 Details

    • GERRIT_LS_PROJECTS

      public static final String GERRIT_LS_PROJECTS
      The command for fetching projects.
      See Also:
  • Constructor Details

    • GerritProjectListUpdater

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

    • 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.
    • getServerName

      public String getServerName()
      The name of the GerritServer this listener is working for.
      Returns:
      the GerritServer.getName().
    • 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
    • getDisplayName

      public String getDisplayName()
      Description copied from interface: NamedGerritEventListener
      A possible more descriptive display name than the class name.
      Specified by:
      getDisplayName in interface NamedGerritEventListener
      Returns:
      the name