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 Summary
Fields Modifier and Type Field Description static String
GERRIT_LS_PROJECTS
The command for fetching projects.
-
Constructor Summary
Constructors Constructor Description GerritProjectListUpdater(String serverName)
Default constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addGerritProject(String gerritProject)
Adds a Gerrit project to this.gerritProjects.void
cancelProjectListUpdater()
Cancel project list update timer.void
connectionDown()
void
connectionEstablished()
void
gerritEvent(com.sonymobile.tools.gerrit.gerritevents.dto.events.ProjectCreated gerritEvent)
OverLoaded gerritEvent(GerritEvent gerritEvent).void
gerritEvent(com.sonymobile.tools.gerrit.gerritevents.dto.GerritEvent gerritEvent)
String
getDisplayName()
A possible more descriptive display name than the class name.List<String>
getGerritProjects()
Returns a string list of Gerrit projects.String
getServerName()
The name of theGerritServer
this listener is working for.int
getTimerUpdatePeriod()
The update period currently being used by the timer.void
initProjectListUpdater()
Initialize project list updater.boolean
isConnected()
static List<String>
readProjects(Reader commandReader)
Reads a list of Gerrit projects from a Reader, one project per line.void
scheduleProjectListUpdate(int initDelay, int updatePeriod)
This method creates a timer that schedule the update of the gerrit project list.void
setConnected(boolean connected)
void
setGerritProjects(List<String> projects)
Sets the internal Gerrit project list.void
setTimerUpdatePeriod(int timerUpdatePeriod)
Sets a new value for the timer update period, in minutes.
-
-
-
Field Detail
-
GERRIT_LS_PROJECTS
public static final String GERRIT_LS_PROJECTS
The command for fetching projects.- See Also:
- Constant Field Values
-
-
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.
-
getServerName
public String getServerName()
The name of theGerritServer
this listener is working for.- Returns:
- the
GerritServer.getName()
.
-
connectionEstablished
public void connectionEstablished()
- Specified by:
connectionEstablished
in interfacecom.sonymobile.tools.gerrit.gerritevents.ConnectionListener
-
connectionDown
public void connectionDown()
- Specified by:
connectionDown
in interfacecom.sonymobile.tools.gerrit.gerritevents.ConnectionListener
-
gerritEvent
public void gerritEvent(com.sonymobile.tools.gerrit.gerritevents.dto.GerritEvent gerritEvent)
- Specified by:
gerritEvent
in interfacecom.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 interfaceNamedGerritEventListener
- Returns:
- the name
-
-