java.lang.Object
com.sonyericsson.hudson.plugins.gerrit.trigger.replication.ReplicationCache

public class ReplicationCache extends Object
Replication cache for RefReplicated events.
Author:
Hugo Arès <hugo.ares@ericsson.com>
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    A factory class for ReplicationCache.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Cache expiration in minutes.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor.
    ReplicationCache(long expiration, TimeUnit unit)
    Constructor use by default constructor and for unit tests.
  • Method Summary

    Modifier and Type
    Method
    Description
    com.sonymobile.tools.gerrit.gerritevents.dto.events.RefReplicated
    getIfPresent(String gerritServer, String gerritProject, String ref, String slaveHost)
    Return the cached RefReplicated associated with the specified parameters, if found.
    boolean
    Initialize cache.
    boolean
    isExpired(long timestamp)
    Returns if the specified time stamp is expired.
    void
    put(com.sonymobile.tools.gerrit.gerritevents.dto.events.RefReplicated refReplicated)
    Cache the specified RefReplicated.
    void
    setCreationTime(long time)
    Set creation time for Replication Cache.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_EXPIRATION_IN_MINUTES

      public static final int DEFAULT_EXPIRATION_IN_MINUTES
      Cache expiration in minutes.
  • Constructor Details

    • ReplicationCache

      public ReplicationCache()
      Default constructor.
    • ReplicationCache

      public ReplicationCache(long expiration, TimeUnit unit)
      Constructor use by default constructor and for unit tests.
      Parameters:
      expiration - Cache expiration
      unit - the unit that expiration is expressed in
  • Method Details

    • setCreationTime

      public void setCreationTime(long time)
      Set creation time for Replication Cache.
      Parameters:
      time - when cache was created
    • initialize

      public boolean initialize()
      Initialize cache.
      Returns:
      true if success
    • put

      public void put(com.sonymobile.tools.gerrit.gerritevents.dto.events.RefReplicated refReplicated)
      Cache the specified RefReplicated.
      Parameters:
      refReplicated - the event to cache
    • isExpired

      public boolean isExpired(long timestamp)
      Returns if the specified time stamp is expired. Note that we also need to check if the event would have been received before the cache was even created as would be the case of a Jenkins restart.
      Parameters:
      timestamp - the time stamp to check.
      Returns:
      true if expired, otherwise false
    • getIfPresent

      public com.sonymobile.tools.gerrit.gerritevents.dto.events.RefReplicated getIfPresent(String gerritServer, String gerritProject, String ref, String slaveHost)
      Return the cached RefReplicated associated with the specified parameters, if found.
      Parameters:
      gerritServer - The gerritServer
      gerritProject - The gerritProject
      ref - The ref
      slaveHost - The slaveHost
      Returns:
      the RefReplicated if found, otherwise null