protected abstract Set<Source> getSourceSetNew();
@Override
public Set<Source> getSourceSet() {
SourceSetState stateNow = state;
// check both boundaries of the interval to exclude problems with leap seconds etc.
long diff = System.currentTimeMillis() - stateNow.getLastChecked();
if (diff >= 0 && diff < latencyMs) {
return stateNow.getSourceSet();
}
synchronized(this) {
// prevent multiple updates
stateNow = state;
diff = System.currentTimeMillis() - stateNow.getLastChecked();
if (diff >= 0 && diff < latencyMs) {
return stateNow.getSourceSet();
}
state = stateNow.update(getSourceSetNew());
return state.getSourceSet();
}
}