Skip to content

Commit

Permalink
Merge pull request #57 from oniatus/snapshotOverride
Browse files Browse the repository at this point in the history
Avoid snapshots being overridden by other instances discovered later. Log discovered of repeated modules.
  • Loading branch information
immortius authored Aug 28, 2016
2 parents 9c28501 + a929896 commit f797436
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.common.collect.Table;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terasology.naming.Name;
import org.terasology.naming.Version;

Expand All @@ -37,19 +39,27 @@
*/
public class TableModuleRegistry implements ModuleRegistry {

private static final Logger logger = LoggerFactory.getLogger(TableModuleRegistry.class);

private final Table<Name, Version, Module> modules = HashBasedTable.create();
private final Map<Name, Module> latestModules = Maps.newHashMap();

@Override
public boolean add(Module module) {
Preconditions.checkNotNull(module);
if (!modules.contains(module.getId(), module.getVersion()) || modules.get(module.getId(), module.getVersion()).getVersion().isSnapshot()) {
if (!modules.contains(module.getId(), module.getVersion())) {
modules.put(module.getId(), module.getVersion(), module);
Module previousLatest = latestModules.get(module.getId());
if (previousLatest == null || previousLatest.getVersion().compareTo(module.getVersion()) <= 0) {
latestModules.put(module.getId(), module);
}
return true;
} else {
logger.error("Module {}-{} already registered from {}, cannot register same module from {}",
module.getId(),
module.getVersion(),
modules.get(module.getId(), module.getVersion()).getLocations(),
module.getLocations());
}
return false;
}
Expand Down

0 comments on commit f797436

Please sign in to comment.