Class GerritMissedEventsPlaybackManager
- java.lang.Object
-
- com.sonyericsson.hudson.plugins.gerrit.trigger.playback.GerritMissedEventsPlaybackManager
-
- All Implemented Interfaces:
NamedGerritEventListener
,com.sonymobile.tools.gerrit.gerritevents.ConnectionListener
,com.sonymobile.tools.gerrit.gerritevents.GerritEventListener
public class GerritMissedEventsPlaybackManager extends Object implements com.sonymobile.tools.gerrit.gerritevents.ConnectionListener, NamedGerritEventListener
The GerritMissedEventsPlaybackManager is responsible for recording a last-alive timestamp for each server connection. The motivation is that we want to be able to know when we last received an event. This will help us determine upon connection startup, if we have missed some events while the connection was down. Once the server is re-connected, the missed event will be played back as if they had been received originally.- Author:
- scott.hebert@ericsson.com
-
-
Field Summary
Fields Modifier and Type Field Description protected List<com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent>
receivedEventCache
List that contains received Gerrit Events.protected EventTimeSlice
serverTimestamp
Server Timestamp.
-
Constructor Summary
Constructors Constructor Description GerritMissedEventsPlaybackManager(String name)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected String
buildEventsLogURL(IGerritHudsonTriggerConfig config, Date date1)
void
checkIfEventsLogPluginSupported()
method to verify if plugin is supported.void
connectionDown()
Log when the connection goes down.void
connectionEstablished()
When the connection is established, we load in the last-alive timestamp for this server and try to determine if a time range exist whereby we missed some events.void
gerritEvent(com.sonymobile.tools.gerrit.gerritevents.dto.GerritEvent event)
This allows us to persist a last known alive time for the server.static XmlFile
getConfigXml(String serverName)
protected Date
getDateFromTimestamp()
get DateRange from current and last known time.String
getDisplayName()
A possible more descriptive display name than the class name.protected List<com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent>
getEventsFromDateRange(Date lowerDate)
Get events for a given lower bound date.protected String
getEventsFromEventsLogPlugin(IGerritHudsonTriggerConfig config, String url)
String
getServerName()
The name of theGerritServer
this is managing.EventTimeSlice
getServerTimestamp()
Return server timestamp.boolean
isSupported()
protected void
load()
Load in the last-alive Timestamp file.void
performCheck()
Method to perform check to see if Events Plugin is enabled.void
shutdown()
Shutdown the listener.
-
-
-
Field Detail
-
serverTimestamp
protected EventTimeSlice serverTimestamp
Server Timestamp.
-
receivedEventCache
protected List<com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent> receivedEventCache
List that contains received Gerrit Events.
-
-
Constructor Detail
-
GerritMissedEventsPlaybackManager
public GerritMissedEventsPlaybackManager(String name)
- Parameters:
name
- Gerrit Server Name.
-
-
Method Detail
-
performCheck
public void performCheck() throws IOException
Method to perform check to see if Events Plugin is enabled.- Throws:
IOException
- if occurs.
-
getServerName
public String getServerName()
The name of theGerritServer
this is managing.- Returns:
- the
GerritServer.getName()
.
-
checkIfEventsLogPluginSupported
public void checkIfEventsLogPluginSupported()
method to verify if plugin is supported.
-
load
protected void load() throws IOException
Load in the last-alive Timestamp file.- Throws:
IOException
- is we cannot unmarshal.
-
getDateFromTimestamp
protected Date getDateFromTimestamp()
get DateRange from current and last known time.- Returns:
- last known timestamp or current date if not found.
-
connectionEstablished
public void connectionEstablished()
When the connection is established, we load in the last-alive timestamp for this server and try to determine if a time range exist whereby we missed some events. If so, request the events from the Gerrit events-log plugin and pump them in to play them back.- Specified by:
connectionEstablished
in interfacecom.sonymobile.tools.gerrit.gerritevents.ConnectionListener
-
connectionDown
public void connectionDown()
Log when the connection goes down.- Specified by:
connectionDown
in interfacecom.sonymobile.tools.gerrit.gerritevents.ConnectionListener
-
gerritEvent
public void gerritEvent(com.sonymobile.tools.gerrit.gerritevents.dto.GerritEvent event)
This allows us to persist a last known alive time for the server.- Specified by:
gerritEvent
in interfacecom.sonymobile.tools.gerrit.gerritevents.GerritEventListener
- Parameters:
event
- Gerrit Event
-
getEventsFromDateRange
protected List<com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent> getEventsFromDateRange(Date lowerDate) throws IOException
Get events for a given lower bound date.- Parameters:
lowerDate
- lower bound for which to request missed events.- Returns:
- collection of gerrit events.
- Throws:
IOException
- if HTTP errors occur
-
getEventsFromEventsLogPlugin
protected String getEventsFromEventsLogPlugin(IGerritHudsonTriggerConfig config, String url)
- Parameters:
config
- Gerrit config for server.url
- URL to use.- Returns:
- String of gerrit events.
-
buildEventsLogURL
protected String buildEventsLogURL(IGerritHudsonTriggerConfig config, Date date1) throws UnsupportedEncodingException
- Parameters:
config
- Gerrit Config for server.date1
- lower bound for date range,- Returns:
- url to use to request missed events.
- Throws:
UnsupportedEncodingException
- if URL encoding not supported.
-
shutdown
public void shutdown()
Shutdown the listener.
-
isSupported
public boolean isSupported()
- Returns:
- whether playback is supported.
-
getServerTimestamp
public EventTimeSlice getServerTimestamp()
Return server timestamp.- Returns:
- timestamp.
-
getConfigXml
@CheckForNull public static XmlFile getConfigXml(String serverName) throws IOException
- Parameters:
serverName
- The Name of the Gerrit Server to load config for.- Returns:
- XmlFile corresponding to gerrit-trigger-server-timestamps.xml.
- Throws:
IOException
- if it occurs.
-
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
-
-