Class ReplicationCache
- 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 class
ReplicationCache.Factory
A factory class for ReplicationCache.
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_EXPIRATION_IN_MINUTES
Cache expiration in minutes.
-
Constructor Summary
Constructors Constructor Description ReplicationCache()
Default constructor.ReplicationCache(long expiration, TimeUnit unit)
Constructor use by default constructor and for unit tests.
-
Method Summary
All Methods Instance Methods Concrete Methods 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()
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.
-
-
-
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 expirationunit
- 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 gerritServergerritProject
- The gerritProjectref
- The refslaveHost
- The slaveHost- Returns:
- the RefReplicated if found, otherwise null
-
-