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 Details

    • 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 Details

    • GerritMissedEventsPlaybackManager

      public GerritMissedEventsPlaybackManager(String name)
      Parameters:
      name - Gerrit Server Name.
  • Method Details

    • 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 the GerritServer 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 interface com.sonymobile.tools.gerrit.gerritevents.ConnectionListener
    • connectionDown

      public void connectionDown()
      Log when the connection goes down.
      Specified by:
      connectionDown in interface com.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 interface com.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 interface NamedGerritEventListener
      Returns:
      the name