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
FieldsModifier and TypeFieldDescriptionprotected List<com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent>List that contains received Gerrit Events.protected EventTimeSliceServer Timestamp. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringbuildEventsLogURL(IGerritHudsonTriggerConfig config, Date date1) voidmethod to verify if plugin is supported.voidLog when the connection goes down.voidWhen 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.voidgerritEvent(com.sonymobile.tools.gerrit.gerritevents.dto.GerritEvent event) This allows us to persist a last known alive time for the server.static XmlFilegetConfigXml(String serverName) protected Dateget DateRange from current and last known time.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 StringgetEventsFromEventsLogPlugin(IGerritHudsonTriggerConfig config, String url) The name of theGerritServerthis is managing.Return server timestamp.booleanprotected voidload()Load in the last-alive Timestamp file.voidMethod to perform check to see if Events Plugin is enabled.voidshutdown()Shutdown the listener.
-
Field Details
-
serverTimestamp
Server Timestamp. -
receivedEventCache
protected List<com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent> receivedEventCacheList that contains received Gerrit Events.
-
-
Constructor Details
-
GerritMissedEventsPlaybackManager
- Parameters:
name- Gerrit Server Name.
-
-
Method Details
-
performCheck
Method to perform check to see if Events Plugin is enabled.- Throws:
IOException- if occurs.
-
getServerName
The name of theGerritServerthis is managing.- Returns:
- the
GerritServer.getName().
-
checkIfEventsLogPluginSupported
public void checkIfEventsLogPluginSupported()method to verify if plugin is supported. -
load
Load in the last-alive Timestamp file.- Throws:
IOException- is we cannot unmarshal.
-
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:
connectionEstablishedin interfacecom.sonymobile.tools.gerrit.gerritevents.ConnectionListener
-
connectionDown
public void connectionDown()Log when the connection goes down.- Specified by:
connectionDownin 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:
gerritEventin 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
- 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
Return server timestamp.- Returns:
- timestamp.
-
getConfigXml
- 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
Description copied from interface:NamedGerritEventListenerA possible more descriptive display name than the class name.- Specified by:
getDisplayNamein interfaceNamedGerritEventListener- Returns:
- the name
-