TTL Object retrieving fix
This commit is contained in:
parent
ad56a91310
commit
3c129484d4
|
@ -28,16 +28,21 @@ public abstract class AbstractScopedMap<T> implements Engine<T>{
|
|||
public T getObject() throws ConfigurationException {
|
||||
String currentScope=ContextUtils.getCurrentScope();
|
||||
log.debug(name+" : obtaining object for context "+currentScope);
|
||||
scopeMap.putIfAbsent(currentScope, new TTLObject<T>(LocalDateTime.now(),retrieveObject()));
|
||||
|
||||
TTLObject<T> found=scopeMap.get(currentScope);
|
||||
|
||||
|
||||
if(found== null){
|
||||
log.debug(name+" : init object for context "+currentScope);
|
||||
return scopeMap.put(currentScope, new TTLObject<T>(LocalDateTime.now(),retrieveObject())).getTheObject();
|
||||
}
|
||||
|
||||
if(TTL!=null) {
|
||||
if(!found.getCreationTime().plus(TTL).isBefore(LocalDateTime.now())) {
|
||||
log.debug(name+" : elapsed TTL, disposing..");
|
||||
dispose(found.getTheObject());
|
||||
found=scopeMap.put(currentScope, new TTLObject<T>(LocalDateTime.now(),retrieveObject()));
|
||||
}
|
||||
}
|
||||
}else {log.debug(name+" : TTL is null, never disposing..");}
|
||||
return found.getTheObject();
|
||||
}
|
||||
|
||||
|
|
|
@ -8,13 +8,14 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.gcube.application.geoportal.service.engine.ImplementationProvider;
|
||||
import org.gcube.application.geoportal.service.model.internal.db.MongoConnection;
|
||||
import org.gcube.application.geoportal.service.model.internal.faults.ConfigurationException;
|
||||
|
||||
@Slf4j
|
||||
public class MongoClientProvider extends AbstractScopedMap<MongoClient>{
|
||||
|
||||
public MongoClientProvider() {
|
||||
super("MongoClient cache");
|
||||
|
||||
// setTTL(Duration.of(10,ChronoUnit.MINUTES));
|
||||
// setTTL(Duration.of(10, ChronoUnit.MINUTES));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Reference in New Issue