use of com.zimbra.common.util.LruMap in project zm-mailbox by Zimbra.
the class ZimbraLmtpBackend method checkDedupeCacheSize.
/**
* If the configured Message-ID cache size has changed, create a new cache and copy
* values from the old one.
*/
private void checkDedupeCacheSize() {
try {
Config config = Provisioning.getInstance().getConfig();
int cacheSize = config.getMessageIdDedupeCacheSize();
long entryTimeout = config.getMessageIdDedupeCacheTimeout();
synchronized (ZimbraLmtpBackend.class) {
Map<String, Set<Integer>> newMap = null;
if (receivedMessageIDs == null) {
// if non-zero entry timeout is specified then use a timeout map, else use an lru map
receivedMessageIDs = entryTimeout == 0 ? new LruMap<String, Set<Integer>>(cacheSize) : new TimeoutMap<String, Set<Integer>>(entryTimeout);
} else if (receivedMessageIDs instanceof LruMap) {
if (entryTimeout != 0) {
// change to a timeout map
newMap = MapUtil.newTimeoutMap(entryTimeout);
} else if (((LruMap) receivedMessageIDs).getMaxSize() != cacheSize) {
// adjust lru map size
newMap = MapUtil.newLruMap(cacheSize);
}
} else if (receivedMessageIDs instanceof TimeoutMap) {
if (entryTimeout == 0) {
// change to a lru map
newMap = MapUtil.newLruMap(cacheSize);
} else {
((TimeoutMap) receivedMessageIDs).setTimeout(entryTimeout);
}
}
if (newMap != null) {
// Copy entries from the old map to the new one. The old map
// is iterated in order from least-recently accessed to last accessed.
// If the new map size is smaller, we'll get the latest entries.
newMap.putAll(receivedMessageIDs);
receivedMessageIDs = newMap;
}
}
} catch (ServiceException e) {
ZimbraLog.lmtp.warn("Unable to update dedupe cache size.", e);
// create an empty lru map if it doesn't exist already.
synchronized (ZimbraLmtpBackend.class) {
if (receivedMessageIDs == null) {
receivedMessageIDs = new LruMap<String, Set<Integer>>(0);
}
}
}
}
Aggregations