Added expiring time to TypesKnowledge
This commit is contained in:
parent
118e058c90
commit
ef74dd31ea
|
@ -1,6 +1,8 @@
|
||||||
package org.gcube.informationsystem.types.knowledge;
|
package org.gcube.informationsystem.types.knowledge;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.gcube.informationsystem.base.reference.AccessType;
|
import org.gcube.informationsystem.base.reference.AccessType;
|
||||||
import org.gcube.informationsystem.model.knowledge.ModelKnowledge;
|
import org.gcube.informationsystem.model.knowledge.ModelKnowledge;
|
||||||
|
@ -21,15 +23,35 @@ public class TypesKnowledge {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// in millisec
|
||||||
|
public static final long DEFAULT_EXPIRING_TIMEOUT;
|
||||||
|
|
||||||
|
static {
|
||||||
|
DEFAULT_EXPIRING_TIMEOUT = TimeUnit.HOURS.toMillis(6);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
protected boolean initialized;
|
protected boolean initialized;
|
||||||
|
public int expiringTimeout;
|
||||||
|
|
||||||
|
// in millisec used only for logging and debugging
|
||||||
|
protected Calendar creationTime;
|
||||||
|
// in millisec
|
||||||
|
protected Calendar expiringTime;
|
||||||
|
|
||||||
protected ModelKnowledge<Type, TypeInformation> modelKnowledge;
|
protected ModelKnowledge<Type, TypeInformation> modelKnowledge;
|
||||||
protected TypesDiscoverer<Type> typesDiscoverer;
|
protected TypesDiscoverer<Type> typesDiscoverer;
|
||||||
|
|
||||||
public TypesKnowledge() {
|
public TypesKnowledge() {
|
||||||
initialized = false;
|
initialized = false;
|
||||||
|
expiringTimeout = (int) DEFAULT_EXPIRING_TIMEOUT;
|
||||||
modelKnowledge = new ModelKnowledge<>(new TypeInformation());
|
modelKnowledge = new ModelKnowledge<>(new TypeInformation());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setExpiringTimeout(int expiringTimeout) {
|
||||||
|
this.expiringTimeout = expiringTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
public TypesDiscoverer<Type> getTypesDiscoverer() {
|
public TypesDiscoverer<Type> getTypesDiscoverer() {
|
||||||
return typesDiscoverer;
|
return typesDiscoverer;
|
||||||
}
|
}
|
||||||
|
@ -41,6 +63,11 @@ public class TypesKnowledge {
|
||||||
public ModelKnowledge<Type, TypeInformation> getModelKnowledge() {
|
public ModelKnowledge<Type, TypeInformation> getModelKnowledge() {
|
||||||
if(!initialized) {
|
if(!initialized) {
|
||||||
discover();
|
discover();
|
||||||
|
}else {
|
||||||
|
Calendar now = Calendar.getInstance();
|
||||||
|
if(now.after(expiringTime)) {
|
||||||
|
renew();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return modelKnowledge;
|
return modelKnowledge;
|
||||||
}
|
}
|
||||||
|
@ -55,6 +82,11 @@ public class TypesKnowledge {
|
||||||
modelKnowledge.addAllType(types);
|
modelKnowledge.addAllType(types);
|
||||||
}
|
}
|
||||||
initialized = true;
|
initialized = true;
|
||||||
|
this.creationTime = Calendar.getInstance();
|
||||||
|
this.expiringTime = Calendar.getInstance();
|
||||||
|
this.expiringTime.setTimeInMillis(creationTime.getTimeInMillis());
|
||||||
|
this.expiringTime.add(Calendar.MILLISECOND, -1);
|
||||||
|
this.expiringTime.add(Calendar.MILLISECOND, expiringTimeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue