Class ReplicationCache


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

      • DEFAULT_EXPIRATION_IN_MINUTES

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

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

      • 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